(1) public class hello { public static void main (String args[]) { [Link].
println(" Hello, Welcome to JAVA world"); } }
(2) public class commandp { public static void main (String args[]) { [Link](" This is from command prompt"); [Link] (args[0]); [Link] (args[2]); } }
(3) class light { public static void main(String args[]) { int lightspeed; long days; long seconds; long distance; lightspeed=186000; days=1000; seconds=days*24*60*60; distance=lightspeed*seconds; [Link] ("In"+days); [Link]("days light will travel about"); [Link](distance+"miles"); } }
(4) class chtest { public static void main(String args[]) { char ch1, ch2; ch1=88; ch2='y'; [Link]("ch1 and ch2"); [Link](ch1+" "+ch2); } }
(5) class optest { public static void main(String args[]) { int a=2; int b=5; int c=7; a +=3; b *=2; c++; [Link]("a:"+a); [Link]("b:"+b); [Link]("c:"+c); } }
(6) class Conversion { public static void main(String args[]) { byte b; int i=126; double d=323.123; // double d=655381.123; [Link]("Conversion of int to byte"); b=(byte)i; [Link]("i and b\t"+i+" "+b); [Link]("Conversion of double to int"); i=(int)d;
[Link]("d and i\t"+d+" "+i); [Link]("Conversion of byte to double"); d=b; [Link](" d :"+d); } }
(7) class average { public static void main(String args[]) { double nums[]={10.1, 11.2, 12.3, 13.4, 14.4}; double result=0; int i; for(i=0; i<5; i++) result=result+nums[i]; [Link]("Average is "+result/5); } }
(8) class twoDarray { public static void main(String args[]) { int twoD[][]=new int [4][5]; int i,j,k=0; for(i=0; i<4; i++) for(j=0; j<5; j++) { twoD[i][j]=k; k++; } for(i=0; i<4; i++) { for(j=0; j<5; j++) [Link](twoD[i][j]+" "); [Link](); } } }
(9) class fortest1 { public static void main(String args[]) { int n; for(n=10; n>1; n--) [Link]("number "+n); } }
(10) class nestedfor { public static void main(String args[]) { int i,j; for(i=0; i<6; i++) { for(j=i; j<6; j++) [Link]("*"); [Link](); } } } (11) class dowhile { public static void main(String args[]) { int n=10; do { [Link]("number "+n); n--; } while(n>3); } }
(12) class switchcase { public static void main(String args[]) { for(int i=0; i<6; i++) switch(i) { case 0: [Link]("i is zero"); break; case 1: [Link]("i is one"); break; default: [Link]("i is more than one"); } } }
(13) class box1 { double width; double height; double depth; } class demo1 { public static void main(String args[]) { box1 mybox1=new box1(); box1 mybox2=new box1(); double volume; [Link]=10; [Link]=20; [Link]=30; [Link]=3; [Link]=6; [Link]=9; volume=[Link]*[Link]*[Link]; [Link]("Volume is "+volume); volume=[Link]*[Link]*[Link]; [Link]("Volume is "+volume); } }
(14) class box2 { double width; double height; double depth; void volume() { [Link]("volume is" + width*height*depth); } } class demo2 { public static void main(String args[]) { box2 mybox1=new box2(); box2 mybox2=new box2(); [Link]=10; [Link]=20; [Link]=30; [Link]=3; [Link]=6; [Link]=9; [Link](); [Link](); } }
(15) class box3 { double width; double height; double depth; double volume() { return width*height*depth; } } class demo3 { public static void main(String args[]) { box3 mybox1=new box3(); box3 mybox2=new box3(); double value; [Link]=10; [Link]=20;
[Link]=30; [Link]=3; [Link]=6; [Link]=9; value=[Link](); [Link] ("Volume is "+value); //value=[Link](); [Link] ("Volume is "); [Link]([Link]()); } }
(16) class box4 { double width; double height; double depth; double volume() { return width*height*depth; } void setDim(double w, double h, double d) { width=w; height=h; depth=d; } }
(17) class demo4 { public static void main(String args[]) { box4 mybox1=new box4(); box4 mybox2=new box4(); [Link](10,20,30); [Link]([Link]()); [Link](3,6,9); [Link]([Link]()); } }
(18) class Box { double width; double height; double depth; Box() { [Link]("Constructing Box"); width=10; height=20; depth=30; } double volume() { return width*height*depth; } }
(19) class demo5 { public static void main(String args[]) { Box mybox1=new Box(); double vol; vol=[Link](); [Link]("Volume is:"+vol); } }
(20) class box6 { double width; double height; double depth; box6(double w, double h, double d) { width=w; height=h; depth=d; } double volume() {
} }
return width*height*depth;
class demo6 { public static void main(String args[]) { box6 mybox1=new box6(10,20,30); box6 mybox2=new box6(3,6,9); double result; result=[Link](); [Link]("Volume is:"+result); result=[Link](); [Link]("Volume is:"+result); } }
(21) class con { double width; double height; double depth; con(double w, double h, double d) { width=w; height=h; depth=d; } con () { width=10; height=10; depth=10; } con(double len) { width=height=depth=len; } double volume() { return width*depth*height; } }
(22) class overloadcons { public static void main(String args[]) { con mybox1=new con(10,20,30); con mybox2=new con(); con mybox3=new con(12); double result; result=[Link](); [Link]("mybox1 is "+result); result=[Link](); [Link]("mybox2 is "+result); result=[Link](); [Link]("mybox3 is "+result); }}
(23) class overloaddemo { void test() { [Link]("No parameters"); } void test(int a) { [Link]("a is:"+a); } void test(int a, int b) { [Link]("a and b:"+a+" "+b); } double test(double a) { [Link]("double a:"+a); return a*a; } }
(24) class overload { public static void main(String args[]) { overloaddemo ob=new overloaddemo(); double result; [Link](); [Link](10); [Link](10,20); result=[Link](123.2); [Link]("result of [Link](123.2) is:"+([Link](123.2))); } }
(25) class Factorial { int fact(int n) { int result; if (n==1) return 1; result = fact(n-1)*n; return result; } } class Recursion { public static void main(String args[]) { Factorial f=new Factorial(); [Link]("Factorial of 3 is "+[Link](3)); [Link]("Factorial of 4 is "+[Link](4)); [Link]("Factorial of 5 is "+[Link](5)); } }
(26) class Test { int a; public int b; private int c; void setc(int i) { c=i; } int getc() { return c; } }
(27) class AccessTest { public static void main(String args[]) { Test ob=new Test(); ob.a=10; ob.b=20; [Link](100); [Link]("a, b, and c: "+ob.a+" "+ob.b+" "+[Link]()); } }
(28) class test { void meth(int i, int j) { i *=2; j /=2; [Link]("the values of i & J:"+i+" } }
"+j);
(29) class callbyvalue { public static void main(String args[]) { test ob=new test(); int a=[Link](args[0]); int b=20; [Link]("a and b before calling:"+a+" "+b); [Link](a,b); [Link]("a and b after calling:"+a+" " +b); } }
(30) class set { int a,b; set(int i, int j) { a=i; b=j; } void meth(set d) { d.a *=2; d.b /=2; } } (31) class callbyref { public static void main(String args[]) { set ob=new set(15,20); [Link]("ob.a and ob.b before calling:"+ob.a+" "+ob.b); [Link](ob); [Link]("ob.a and ob.b after calling:"+ob.a+" "+ob.b); } }