class HelloJava { public static void main(String[] args) { [Link].
println("HelloJava"); } } -----------------------class charex { public static void main(String args[]) { char ch1, ch2; ch1 = 178; // code for X ch2 = 'Y'; [Link]("ch1 and ch2: "); [Link](ch1 + " " + ch2); } } -----------------------class charex2 { public static void main(String[] args) { int number[]={1,2,3,4,5,6,5,4,3,2,1}; int n=[Link]; [Link]("The entered number are:"); for(int i=0;i<n;i++) { [Link](" "+number[i]); } } } -----------------------class arraydis { public static void main(String[] args) { int number[]={1,2,3,4,5,8,7,9,5,4,6,55,99}; int n=[Link]; [Link]("The entered values are: "); for(int i=0;i<n;i++) { [Link](" "+number[i]); } } } -----------------------class Array { public static void main(String[] args) { int num[]=new int[5]; num[0]=5; num[1]=4; num[2]=6; num[3]=7; num[4]=9; //num[-6]=1; [Link]("Now we will print array");
for(int i=0; i<4; i++) { [Link](num[i]+""); } } } -----------------------class Trialngle { public static void main(String[] args) { for(int i=1; i<=5; i++) { for(int j=5; j>=i; j--) { [Link](" "+i); } [Link](""); } } } -----------------------class Triangleex { public static void main(String[] args) { for(int i=1; i<=5; i++) { for(int j=1; j<=i; j++) { [Link](j+" "); } [Link](""); } } } -----------------------class Tri { public static void main(String[] args) { for(int i=70; i>=65; i--) { for(int j=65; j<=i; j++) [Link](j+" "); [Link](""); } } } -----------------------class IfSimple { public static void main(String[] args) { int x,y; x=10; y=20; if(x<y) [Link]("\n x is less than y ");
x=x*2; if(x==y) [Link]("\n x is equal to y"); x=x*2; if(x>y) [Link]("\n x is greater than y"); if(x==y) [Link](" You wont see this"); } } -----------------------class CharDemo { public static void main(String args[]) { char ch1, ch2; ch1=88; ch2='y'; [Link]("Ch1 is "+ch1); [Link]("Ch2 is "+ch2); } } -----------------------class ForTest { public static void main(String[] args) { for(int x=0; x<10; x++) [Link]("The value of x:"+x); } } -----------------------class DynInit { public static void main(String args[]) { double a=3.0, b=4.0; double c=[Link](a*a+b*b); [Link]("c is "+c); } } -----------------------class TriEx { public static void main(String[] args) { for(int i=1; i<=9; i=i+2) { for(int j=1; j<=i; j=j+2) [Link](j+" "); [Link](""); } } } -----------------------class Search { public static void main(String[] args) { int a[]={5,6,8,4,9,2,7};
int n=4, c=1, i; for(i=0; i<n; i++) { if(a[i]==n) break; else c++; } [Link](a[i]+" is found at "+c); } } -----------------------class Sorting { public static void main(String args[]) { int number[]={8,6,9,7,1,2,4,3}; int n=[Link]; [Link]("Entered values are: "); for(int i=0; i<n; i++) { [Link](" "+number[i]); } for(int i=0; i<n; i++) { for(int j=i+1; j<n; j++) { if(number[i]>number[j]) { int temp=number[i]; number[i]=number[j]; number[j]=temp; } } } [Link]("\nAfter sorting the elements are: "); for(int i=0; i<n; i++) { [Link](" "+number[i]); } } } -----------------------class Searchex { public static void main(String[] args) { int a[]={2,6,4,5,8,9,77,66,88,44,15,33,94,56,28,46}; int n=[Link]; int s=94, c=1, i; for(i=0; i<n; i++) { if(a[i]==s) break; else c++; } [Link](a[i]+" is found at " [Link]("\n\ni/j= "+d+"\n\n"); }
} -----------------------class NestedDemo { public static void main(String[] args) { for(int i=1; i<=4; i++) { for(int j=1; j<=i; j++) [Link](j+" "); [Link](""); } } } -----------------------class Tria { public static void main(String[] args) { for(int i=5; i>0; i--) { for(int j=5; j>=i; j--) [Link](j+" "); [Link](""); } } } -----------------------class testingg { public static void main(String[] args) { int i,j; for(i=5; i>=1; i--) { for(j=5; j>=i; j--) [Link](j+" "); [Link](""); } } } -----------------------class SumAvg { public static void main(String[] args) { int sum=0; for(int i=0; i<[Link]; i++) { int value=5; sum=sum+value; } [Link]("Sum= "+sum); float avg=(float)(sum)/[Link]; [Link]("Avg= "+avg); } } -----------------------class Randam {
public static void main(String[] args) { int value=(int)([Link]()*100); [Link]("Randomly generated value: "+value); if(value%2==0) [Link]("Even"); else [Link]("Odd"); } } -----------------------class StrEx { public static void main(String[] args) { String str=new String("Hello"); //String str="Hellllllllo"; [Link]("The Entered string is: "+str); //[Link](str); } } -----------------------class Str1Ex { public static void main(String[] args) { // char ch[]={'I','N','D','I','A'}; // String st1=new String(ch); // String st2=new String(st1); // [Link](ch); // [Link]("First String is "+st1); // [Link]("Second String is "+st2); // // // // // // // // // // // // String str="java is a good language"; int len=[Link](); [Link]("Length is: "+len); int time=9; String str1="Hello World "; String str2="Good Morning "; String str3=str2+time+str1+"How are you..?"; [Link]("New String is "+str3); String str="Hot Java"; char ch; ch=[Link](4); [Link]("The char at 4th place is "+ch);
} } -----------------------class StrGetChar { public static void main(String[] args) { StringBuffer sb=new StringBuffer("Welcome to the readers"); char arr[]=new char[7]; [Link](0,7,arr,0); [Link](arr); }
} -----------------------class StrEqual { public static void main(String[] args) { // String st1="Java"; // String st2="Java"; // String st3="JAVA"; // [Link]("First equals to second "+[Link](st2)); // [Link]("Second equals to third "+[Link](st3) ); // String st="Hyderabad"; // [Link]("The String starts with 'Hyd' "+[Link]("hyde ")); // [Link]("The String ends with 'bad' "+[Link]("bad")); } } -----------------------class CompareDemo { public static void main(String[] args) { String st1="welcome"; String st2="welcome to MissWorld"; String st3="Welcome"; if([Link](st2)>0) [Link]("First string is Greater than Second"); else if([Link](st2)<0) [Link]("First string is Smaller than Second"); else [Link]("Both are Equal"); if([Link](st3)>0) [Link]("First string is Greater than Third"); else if([Link](st3)<0) [Link]("First string is Smaller than Third"); else [Link]("First and Third are same"); } } -----------------------class FindIndex { public static void main(String[] args) { // String st1="Four scores and seven years ago"; // int pos=[Link]("a"); // int stpos=[Link]("seven"); // [Link](pos); // [Link](stpos); String str=new String("Too much liberty is harmfultolove"); [Link](str); int pos=[Link]('l'); [Link]("First 'l' at "+pos); pos=[Link]('l',pos+2); [Link]("Second 'l' at "+pos); pos=[Link]("liberty"); [Link]("Liberty at "+pos); // pos=[Link]('l',pos+2);
// }
[Link]("Third 'l' at "+pos);
} -----------------------class Student { int Name; float Math; float Sci; float Eng; float Avg; //compute the avg and display the value void Average() { Avg=(Math+Sci+Eng)/3; [Link]("Average is "+Avg); } } class Mark { public static void main(String args[]) { Student st=new Student(); [Link]=60; [Link]=80; [Link]=70; [Link](); } } -----------------------class GetDetails { public static void main(String[] args) { int empno; float salary; char dept; void getdetails() { empno=10; salary=2000.50; dept='k'; } void showdetails() { [Link](empno); [Link](salary); [Link](dept); } } } -----------------------class Student { int rollno; float maths; float science;; float english; float calcavg(float maths, float science, float english) {
return(maths+science+english)/3; } } class ReturnValueDemo { public static void main(String[] args) { Student st=new Student(); float Average; [Link]=60; [Link]=75; [Link]=50; //Now calculate the average //Call the function calcavg Average=[Link]([Link], [Link], [Link]); [Link]("Average mark is "+Average); } } -----------------------class anand { int rollno; float maths; float science; float english; float anandavg(float maths, float science, float english) { return(maths+science+english)/3; } } class Student { public static void main(String[] args) { anand an=new anand(); float average; [Link]=65; [Link]=86; [Link]=75; //now calculate the average //call the function avg average=[Link]([Link],[Link],[Link]); [Link]("Average mark is "+average); } } -----------------------//class Students //{ // int stno; // float maths; // float science; // float english; // float avg; // //compare the average and display the value // void avg() // { // avg=(maths+science+english)/3; // [Link]("Average mark is "+avg); // } //}
//class Student //{ // public static void main(String[] args) // { // Students st=new Students(); // //now assign values to the object // [Link]=80; // [Link]=80; // [Link]=90; // [Link](); // } //} -----------------------class Student { int StuNO; float maths; float science; float english; float average; //compute the average and display the value void average() { average=(maths+science+english)/3; [Link]("Average mark is "+average); } } class Studentex { public static void main(String[] args) { Student st=new Student(); [Link]=60; [Link]=80; [Link]=70; [Link](); } } -----------------------class Staticex { int x; static int y; public void inc() { x=x+1; y=y+1; } public void show() { [Link]("The value of x is "+x); [Link]("The value of y is "+y); } } class StaticDemo { public static void main(String[] args) { Staticex st1=new Staticex(); Staticex st2=new Staticex();
[Link]("For the first object"); [Link](); [Link](); [Link]("For the second object"); [Link](); [Link](); } } -----------------------class Student { int stuno; String name; int mark; static int stucount; public void show() { [Link]("The student details are "); [Link]("Name is "+name); [Link]("No is "+stuno); [Link]("Marks are "+mark); [Link]("The studount is "+stucount); } } class StaMethEx { public static void main(String[] args) { Student st1=new Student(); Student st2=new Student(); Student st3=new Student(); [Link]++; [Link](); [Link]++; [Link](); [Link]++; [Link](); } } -----------------------class First { int length; int breadth; int FindArea(int x, int y) { return(x*y); } } class Second { int length; int breadth; int height; int FindArea(int x, int y) { return(x*y); } int FindVolume(int x, int y, int z) {
return(x*y*z); } } class Inher { public static void main(String[] args) { First fi=new First(); [Link]=2; [Link]=3; int Area=[Link]([Link], [Link]); [Link]("For First element"); [Link]("The Area is "+Area); Second se=new Second(); [Link]=2; [Link]=3; [Link]=4; Area=[Link]([Link], [Link]); [Link]("For Second element"); [Link]("The Area is "+Area); int Volume=[Link]([Link], [Link], [Link]); [Link]("The Volume is "+Volume); } } -----------------------class FirstClass { void firstMethod() { [Link]("Message from FirstClass"); } } class SecondClass extends FirstClass { void secondMethod() { [Link]("Message from SecondClass"); } } class ThirdClass extends SecondClass { void thirdMethod() { [Link]("Message from ThirdClass"); } } class FourthClass extends ThirdClass { void fourthMethod() { [Link]("Message from FourthClass"); } } class TestInheritance { public static void main(String args[]) { FourthClass fc=new FourthClass(); [Link](); [Link]();
[Link](); [Link](); [Link]("All the messages were displayed"); } } -----------------------class SuperClass { void superMethod() { [Link]("SuperClass called"); } } class FirstSubClass extends SuperClass { void firstsubMethod() { [Link]("Message from FirstSubClass"); } } class SecondSubClass extends SuperClass { void secondsubMethod() { [Link]("Message from SecondSubClass"); } } class MultiLevelTest { public static void main(String[] args) { SuperClass sc=new SuperClass(); FirstSubClass fsc=new FirstSubClass(); SecondSubClass ssc=new SecondSubClass(); [Link](); [Link](); [Link](); [Link](); [Link](); } } -----------------------class Rect { float length; float breadth; float height; float volume(float l, float b, float h) { return(l*b*h); } } class Volume extends Rect { public static void main(String[] args) { Rect r=new Rect(); float vol; [Link]=5; [Link]=6;
[Link]=7; vol=[Link]([Link], [Link], [Link]); [Link]("The Volume of the Rectangle is "+vol); } } -----------------------class First { void firstMethod() { [Link]("Message from First"); } } class Second extends First { void secondMethod() { [Link]("Message from Second"); } } class Third extends Second { void thirdMethod() { [Link]("Message from Third"); } } class Fourth extends Third { void fourthMethod() { [Link]("Message from Fourth"); } } class FourInher { public static void main(String[] args) { Second s=new Second(); Third t=new Third(); Fourth f=new Fourth(); [Link](); [Link](); [Link](); } } -----------------------class Student { int Rollno; float maths; float science; float english; float average(float m, float s, float e) { return(m+s+e)/3; } } class ReturnDemo {
public static void main(String[] args) { Student stu=new Student(); float avg; [Link]=1206; [Link]=88; [Link]=97; [Link]=86; avg=[Link]([Link], [Link], [Link]); [Link]("Average mark is "+avg); } } -----------------------class Construct { int length; int breadth; Construct(int x, int y) { length=x; breadth=y; [Link]("The values are "+length+","+breadth); } void display() { } } class TestConstruct { public static void main(String[] args) { Construct ct=new Construct(4,5); //Construct cr=new Construct(); [Link](); //[Link](); } } -----------------------class PolyTest { int r,l,b; public PolyTest(int x, int y, int z) { r=x; l=y; b=z; } void area(int rad) { double res; res=(double)rad*3.10*3.14; [Link]("Area of Circle is: "+res); } void area(int len, int bre) { int res; res=len*bre; [Link]("Area of Rectangle is: "+res);
} } class PolyAreaTest { public static void main(String[] args) { PolyTest pt=new PolyTest(4,5,6); PolyTest pp=pt; PolyTest p=pp; [Link](4); [Link](1,2); [Link](6); [Link](7,8); [Link](5); [Link](5,4); } } -----------------------class ObjectTest { int i,j; void setValues(int x, int y) { i=x; j=y; } void display() { [Link]("Values are "+i+","+j); } } class ObjectMain { public static void main(String[] args) { ObjectTest ob=new ObjectTest(); ObjectTest ot=ob; [Link](4,5); [Link]("The present "); [Link](); [Link](10,20); [Link]("The new "); [Link](); [Link](); } } -----------------------class MyObject { int a,b; void sendObject(MyObject m) { m.a=20; m.b=30; } void display() { [Link]("The values are"+a+","+b); } }
class MainClass { public static void main(String[] args) { MyObject my=new MyObject(); [Link](my); [Link](); } } -----------------------class RectArea { int length; int breadth; void Area(int l, int b) { length=l; breadth=b; [Link]("Area is: "+(l*b)); } } class ConsFindArea { public static void main(String args[]) { RectArea ra=new RectArea(); [Link](4,5); } } -----------------------class ObjectDemo { int x; int y; void sendObject(ObjectDemo ob) { ob.x=5; ob.y=6; } void display() { [Link]("The Values are:"+x+","+y); } } class ObjectTest { public static void main(String args[]) { ObjectDemo od=new ObjectDemo(); ObjectDemo ob=new ObjectDemo(); [Link](od); [Link](); [Link](od); [Link](); } } -----------------------class ThisDemo { int x,y;
void assignValues(int x, int y) { this.x=x; this.y=y; } void display() { [Link]("The values of theis object are: "+x+","+y); } } class ThisTest { public static void main(String[] args) { ThisDemo th=new ThisDemo(); ThisDemo td=new ThisDemo(); [Link](10,20); [Link](4,5); [Link](); [Link](); } } -----------------------class TestReturn { int i,j; public TestReturn() {} TestReturn assignValues() { TestReturn re=new TestReturn(); re.i=10; re.j=20; return re; } } class ObjReturn { public static void main(String[] args) { TestReturn rt=new TestReturn(); TestReturn rt1=new TestReturn(); [Link]("The Values are "+rt.i+","+rt.j); } } -----------------------//class TestReturn //{ // TestReturn assignValue() // { // TestReturn t=new TestReturn(); // return(t); // } //} //class ObjReturn //{ // public static void main(String[] args) // { // TestReturn tr=new TestReturn(); // [Link]();
// } //} -----------------------package newpack; class Demo { int k, num; public void show(int a, int b) { [Link]("The numbers are: "); [Link](a+" "+" "+b); [Link]("Their sum is "+(a+b)); } } class PackageDemo { public static void main(String args[]) { Demo d=new Demo(); [Link](20,30); } } -----------------------package newpack; public class Demo1 { int k, num; public void show(int a, int b) { [Link]("The numbers are: "); [Link](a+" "+" "+b); [Link]("Their sum is "+(a+b)); } } -----------------------import newpack.*; class UsePackdeme { public static void main(String[] args) { Demo1 d=new Demo1(); [Link](40,60); } } -----------------------package newpack; class addition { int a,b; public void show(int x, int y) { [Link]("The numbers are: "); [Link](a+" "+" "+b); [Link]("The addition is: "+(a+b)); } } ======================== package newpack; public class addition {
int k, num; public void show(int a, int b) { [Link]("The numbers are: "); [Link](a+" "+" "+b); [Link]("Their sum is "+(a+b)); } } -----------------------import newpack.*; class add { public static void main(String[] args) { addition ad=new addition(); [Link](1,2); } }interface MyDemo { public void show(int i, int j); public void result(int i, int j); } -----------------------class IntrDemo implements MyDemo { public void show(int i, int j) { [Link]("The numbers are "+i+","+j); } public void result(int i, int j) { [Link]("Sum is "+(i+j)); } } -----------------------class InterDemo { public static void main(String[] args) { MyDemo m=new IntrDemo(); [Link](10,20); [Link](20,30); } } -----------------------interface IDemo { public void show(int i, int j); } class first implements IDemo { public void show(int i, int j) { [Link]("Values from first are "+i+","+j); } } class second implements IDemo { public void show(int i, int j)
{ [Link]("The values from second are "+i+","+j); [Link]("Their sum is "+(i+j)); } } class InterfaceDemo { public static void main(String[] args) { IDemo id=new first(); IDemo sd=new second(); [Link](10,20); [Link](30,40); } } -----------------------interface interf { public void show(int i, int j); } interface First { public void one(int i, int j) { [Link]("Values from first are "+i+","+j); } } interface Second { public void two(int i, int j) { [Link]("Values from second are "+i+","+j); } } interface Third extends First extends Second { public void three(int i, int j) { [Link]("Values from third are "+i+","+j); } } class MultiInherInter { public static void main(String[] args) { Third t=new Third(); Second s=new Second(); First f=new First(); } } -----------------------interface Mydemo { public void show(int i, int j); public void result(int i, int j); } class InterDemo implements Mydemo { public void show(int i, int j)
{ [Link]("The values are: "+i+"'"+j); } public void result(int i, int j) { [Link]("The sum is: "+(i+j)); } } class DemoMain { public static void main(String[] args) { Mydemo m=new InterDemo(); [Link](10,20); [Link](1,2); } } -----------------------interface Idemo { public void show(int i, int j); } class first implements Idemo { public void show(int i, int j) { [Link]("Values from first are: "+i+","+j); } } class second implements Idemo { public void show(int i, int j) { [Link]("The values from second are "+i+","+j); [Link]("Their sum is "+(i+j)); } } class InterfaceDemo1 { public static void main(String[] args) { Idemo id=new first(); Idemo sd=new second(); [Link](10,20); [Link](2,3); } } -----------------------class ExceptionDemo { public static void main(String args[]) { int x,y; x=10; y=0; int z=x/y; [Link]("The result is "+z); } } ------------------------
class Array { public static void main(String[] args) { int num[]=new int[5]; try { num[0]=5; num[1]=4; num[2]=6; num[3]=7; num[4]=9; //num[-6]=1; [Link]("Now we will print array"); for(int i=0; i<4; i++) { [Link](num[i]+""); } } catch(Exception e) { [Link]("The Exception is: "+e); [Link]("Array values are out of limit"); } } } -----------------------class AccessDemo { private int no; private int dt; int x,y; AccessDemo() { no=10; dt=23; x=5; y=6; } void print() { [Link]("The values of variables are "+no+" "+dt+" "+x+" "+y) ; } } class AccessTest { public static void main(String[] args) { AccessDemo ad=new AccessDemo(); // [Link]([Link]); // [Link]([Link]); [Link](ad.x); [Link](ad.y); [Link](); } } -----------------------class ExceptionDemo1 {
public static void main(String args[]) { int i=2; int j=0; try { int z=i/j; [Link]("The result is "+z); } catch(Exception e) { [Link]("The Exception is: "+e); [Link]("'j' should not be '0'"); [Link]("Enter the correct value"); } } } -----------------------class FileText { public static void main(String[] args) { try { file f=new File("[Link]"); int i,j; i=0; int k=j/i; [Link](); } catch(ArithmeticException ae) { [Link]("Arithmetic Exception Occured"); } catch(FileNotFoundException fe) { [Link]("File not found exception"); } } } -----------------------class MultiCatch { public static void main(String args[]) { try { int x=[Link](); [Link](1000/x); } catch(ArrayIndexOutOfBoundsException aie) { [Link]("printStackTrace()"); [Link](); } catch(ArithmeticException ae) { [Link]("getMessage()"+[Link]()); } catch(Exception a)
{ [Link]("toString()"+[Link]()); } } } -----------------------import [Link].*; class FinallyDemo { public static void main(String[] args) { try { [Link]("Enter a char action: "); int i=[Link](); [Link]("Char action entered is: "+(char)i); } catch(IOException e) { [Link]("Catch block happens only if exception occurs"); [Link](); } finally { [Link]("Finally always occurs"); } } } -----------------------class Throwsexception { static void myownexception() throws ClassNotFoundException { throw new ClassNotFoundException("myownexception"); } public static void main(String[] args) { try { myownexception(); } catch(ClassNotFoundException e) { [Link]("myownexception exception caught"); } } } -----------------------class Exc { public static void main(String[] args) { int numerator=131; int denominator=0; int result; [Link]("The Entered Values are: "+numerator+","+denominator); try { result=numerator/denominator; [Link]("result is "+result);
} catch(Exception e) { [Link]("denominator should not be 0"); } } } -----------------------class ThreadDemo { public static void main(String[] args) { Thread th=[Link](); [Link]("The current thread is "+th); [Link]("Anand"); [Link]("The changed thread is "+th); } } -----------------------class SleepDemo { public static void main(String args[]) { Thread th=[Link](); try { for (int i = 1; i < 10; i++) { [Link](i); [Link](555); } } catch(InterruptedException e) { [Link]("Thread Interrupted"); } } }