Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Packages-Java Network Programming-Lecture Slides, Slides of Java Programming

This lecture is delivered by Prem Vikas at Jaypee Institute of Information Technology University for discussing following points of Java Network Programming: Classes, Objects, Public, Private, Protected, Inner, Classes, Overloading, Constructors, Methods

Typology: Slides

2011/2012

Uploaded on 07/03/2012

aapti
aapti 🇮🇳

4.6

(28)

82 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Java-Programming
Day-02
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Packages-Java Network Programming-Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Java-Programming

Day-

Outlines

  • Classes and Objects

 Public, Private, Protected,default  Packages  Importing classes  Inner Classes  Creating instances of classes  Constructors  Overloading Constructors  Methods  Abstract ,final,native,synchronize  Parameters (by value or by reference)  Scope of variables  Casting and conversion  Method overloading

  • Borland Jubilder-

 Introduction  examples

package cont…

  • Example

package my2Dgraphics;

public class Circle{

        • code - - - - - -

}

  • Example

package bscis.semester0.xyz

public class Circle{

      • -- - code - - - - - -

}

package cont…

  • Fully qualified name

 Package name becomes part of class identity  A class name when written with its package name is termed as its fully qualified name  Example  my2Dgraphics.Circle  bscis.semester0.xyz.Circle  Directory structure reflected by two class files will be  outputpath/my2Dgraphics/Circle.class  Outputpath/bscis/semester0/xyz/Circls.class

  • A package can be imported to any other program using import

statement

 Import statement should placed before start of a class  Example  import javax.swings.JOptionPane;  Import javax.swings.*;

Controlling Access to Class Member

  • Class Members

 Primitive or reference variable in the class that is not part of any method in the class

  • Member Access Specifier

 public  private  protected  Default access (Package access)

  • Public Members

 The keyword public is written before the member to make it public  Methods or variables declared are directly accessible to other classes and objects through the object-no access restriction

  • Private Members

 The keyword private is written before the member to make it private  Methods or variables declared private are not directly accessible to any other class or object

controlling access….

  • Protected Members

 The keyword protected is written to make a member protected  A protected member is accessible to other classes with in the package  Outside the package only child classes can access a protected member  Not accessible to non-inherited classes outside the package

  • Default or Package access

 When no access specifieris used before a class member the access of that member function or variable is default or package  Such members are accessible to other classes within the package  Such members are not accessible to other classes outside the package

controlling access….examples

Private Access

  • Example:2-part

package temp;

public class Test{

private int x; public static void main (String s[]){ Test t=new Test(); t.x=90; //Error } }

  • Example:2-part package temp; public class Test2{ Test t=new Test(); public void methodx ( ){ t.x=120; //Error } }
  • Example:2-part package secure; import temp.*; public class Test3{ Test t=new Test(); public void methody( ){ t.x=30; //Error } }

controlling access….examples

Protected Access

  • Example:3-part package temp;

public class Test{ protected int x; public static void main (String s[]){ Test t=new Test(); t.x=90; //Accessd } }

  • Example:3-part

package temp; public class Test2{ Test t=new Test(); public void methodx ( ){ t.x=120; //Accessed } }

  • Example:3-part package secure; import temp.*; public class Test3{ Test t=new Test(); public void methody( ){ t.x=30; //Error non-child class } }
  • Example:3-part package secure; import temp.*; public class Test3 extends Test4{ Test t=new Test(); public void methody( ){ t.x=30; //Error } }

Constructors

  • Same name as that of the class
  • No return type
  • Primary objective is to initialize the class variables
  • A constructor allocates memory to the object of a class
  • Example

public class Circle{ int x,y; int radius; Circle(){ x=y=radius=0; } }

Constructor Overloading

  • Same name with different parameters
  • Primary objective is to provide many ways to initialize the object
  • Example:

public class Circle{ int x,y; int radius; Circle(){ X=y=radius=0; } Circile(int x1,int y1){ x=x1; y=y1; } }

Inheritance

  • Single Inheritance

 A class cannot have more than one immediate parents

  • Parent class is also termed as super
  • Inherited class is termed as child or extended class
  • The keyword extends is used for inheritance
  • Syntax

public class Sphere extends Cirlce{

        • -Code - - - - - }

Example-Inheritance

public class Point{

int x,int y; Point(){ x=y=0; } Point(int x1,int y1){ x=x1; y=y } public void showPoint(){ System.out.println(“X=“+x); System.out.println(“X=“+y); }

public class Point3D extends Point{ int z; Point(){ x=y=0; }

}

  • Inherited members
    • x y show point and the two constructors

this and super

  • this usually refers to the class itself
  • Used to refer to variable of the class in conditions where a

parameter and class variable have same names

  • super refers to the parent class
  • Used to refer to variable of the parent class in conditions where a

child class and parent class have same variable or method names

  • Super is also used to call the constructor of the parent class

An Introduction to JBuilder

Power on your systems and start JBuilder