5, మార్చి 2012, సోమవారం

SOME OF My CLASSROOM DISCUSSIONS ON 5TH.MAR.2012 REGARDING JAVA SESSION

Note:- u dont have any licenced antivirsu on u r machne ,if u wants to check any of u r file weater it got virus or not  click on the below link and upload u r file in this site it will scan u r file more than 42 anti virus softwares
www.virustotal.com
//PROGRAM FOR IMPLEMENTATION 1D ARRAY IN JAVA BY USING SINGLE CLASS
//CLASSROOM EXPLANATION ON 5.MAR.2012
class a
{
int[] arr;
a()
{
arr=new int[5];
}

void display()
{
for(int i=0;i<arr.length;i++)
System.out.println(""+arr[i]);
}

public static void main(String args[])
{
a a1=new a();
for(int i=0;i<args.length; i++)
a1.arr[i]=Integer.parseInt(args[i]);
a1.display();
}}

execuation

E:\jit>dir a.java
 Directory of E:\jit
05-Mar-12  01:23 PM               297 a.java
               1 File(s)            297 bytes
               0 Dir(s)   1,286,799,360 bytes free
E:\jit>javac a.java
E:\jit>java a 10 20 30 40 50  //here supplying data for an array from the command prompt
10
20
30
40
50
//PROGRAM FOR IMPLEMENTATION 1D ARRAY IN JAVA BY USING 2 CLASSES
//CLASSROOM EXPLANATION ON 5.MAR.2012
class a
{
int[] arr;
a()
{
arr=new int[5];
}

void display()
{
for(int i=0;i<arr.length;i++)
System.out.println(""+arr[i]);
}
}

class a1
{
public static void main(String args[])
{
a a1=new a();
for(int i=0;i<args.length; i++)
a1.arr[i]=Integer.parseInt(args[i]);
a1.display();
}}

E:\jit>javac a1.java
E:\jit>java a1 100 200 300 400 500


//EXPLANATION ABOUT THE COPY CONSTRUCTOR
class copy
{
int x;
float y;
//constructor invoking firsttime by CALL BY VALUE technique
copy(int x1,float y1)
{
x=x1;
y=y1;
}

//this is COPY CONSTRUCTOR it will be invocked by CALL BY REFERENCE Mechanisim
copy(copy c)
{
x=c.x;
y=c.y;
}

void display()
{
System.out.println("the values of x ,y are "+x+"   "+y);
}
}// end of copy class


class copyimpl
{
public static void main(String args[])
{
//createon of object prototype which is being used in coping
copy c=new copy(3, 3.2f);
System.out.println("THIS IS THE DATA FROM THE MODEL OBJECT WHICH IS INTURN USED TO CREATE MORE OBJECTS ");
c.display();
//by using the above object  here we are crating more objects of the same type
copy c1=new copy(c);
System.out.println("THIS IS THE DATA FROM THE REPLICATED OBJECT BY COPY CONSTRUCTOR");
c1.display();
}
}

Execuation

E:\jit>javac copyimpl.java
E:\jit>java copyimpl
THIS IS THE DATA FROM THE MODEL OBJECT WHICH IS INTURN USED TO CREATE MORE OBJECTS
the values of x ,y are 3   3.2
THIS IS THE DATA FROM THE REPLICATED OBJECT BY COPY CONSTRUCTOR
the values of x ,y are 3   3.2


/*THIS KEYWORD EXPLANATION we will use this keyword at 3 places 1. is the below 2.is calling the mehtod of same class with out referning the objectname and 3.is calling the constructor of the same class */
class rect
{
int length;
int breadth;
//here i am dicriminating the instance variable and method variables
rect(int length, int breadth)
{
this.length=length;
this.breadth=breadth;
}

void display()
{
System.out.println("the values of rectangle are "+length+"   "+breadth);
}
void areacal()
{
int area;
area=length*breadth;
System.out.println("the are of the the rectangle is "+area);
}
void perimeter()
{
int peri=2*(length*breadth);
System.out.println("the perimeter is "+peri);
}}

class rectimpl
{
public static void main(String args[])
{
rect r=new rect(3,4);
r.display();
r.areacal();
r.perimeter();
}}
OUTPUT:-
E:\jit>javac rectimpl.java
E:\jit>java rectimpl
The values of rectangle are 3 4
The area of the rectangle is  12
The perimeter is   24

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి