HTML & Java Basics for Beginners
HTML & Java Basics for Beginners
<HTML> <HEAD> <TITLE> First Program in HTML </TITLE> <BODY> WELCOME TO HTML </BODY> </HEAD> </HTML> OUTPUT:
<html> <head> <body bgcolor=yellow text=red> <center> LINE </center> <HR ALIGN="center" WIDTH="20" SIZE="100" color=black> </HR> </head> </body> </html> OUTPUT:
<html> <head> <body> <img src="C:\Users\Public\Pictures\Sample Pictures\[Link]" border=5> <img src="C:\Users\Public\Pictures\Sample Pictures\[Link]"> </head> </body> </html> OUTPUT:
<html> <body> <FRAMESET Rows="30%,*"> <FRAMESET Cols="50%,50%"> <FRAME Src="C:\flowers\[Link]"> <FRAME Src="C:\flowers\[Link]"> </FRAMESET> <FRAMESET Cols="50%,50%"> <FRAME Src="C:\flowers\[Link]"> <FRAME Src="C:\flowers\[Link]"> </FRAMESET> </FRAMESET> </body> </html>
10
11
12
<html> <head> <body> <form name="f1"> <b> Resume </b> <br><br> <b> Name </b> <input type="text" name="t1" size=5> <br><br> <b> Class </b> <input type="text" name="t2" size=5> <br><br> <b> Rollno </b> <input type="text" name="t3" size=5> <br><br> <b> Percentage in 10th </b> <input type="text" name="t4" size=5> <br><br> <b> Percentage in 10+2th </b> <input type="text" name="t5" size=5> <br><br> <b> Percentage in BCA I </b> <input type="text" name="t6" size=5> <br><br> <b> Percentage in BCA II</b> <input type="text" name="t7" size=5> <br><br> <b> Father's Name </b< <input type="text" name="t8" size=5> <br><br>
13
<b> Address</b> <input type="text" name="t9" size=5> <br><br> <b> Contact No. </b> <input type="text" name="t10" size=5> <br><br> <b> Hobbies</b> <input type="text" name="t11" size=5> <br><br> <input type="button" name="b1" value=SUBMIT> <br><br> <input type="button" name="b2" value=RESET> <br><br> </form> </head> </body> </html> OUTPUT:
14
17
<html> <head> <link rel=stylesheet href="C:\Users\DELL\Desktop\hgrewal\html\dht [Link]"> </head> <body> <p1>Welcome <h1>Hello </body> </html> OUTPUT:
<head> <link rel=stylesheet href="C:\Users\DELL\Desktop\hgrewal\html\dht [Link]"> </head> <body> <p>Welcome <p class="abc">Hello </body> </html> OUTPUT:
<p> Welcome <h1> First page </h1> End </body> </html> OUTPUT:
21
<p class=abc> Welcome to <SPAN class=xyz> HTML </SPAN> programming <p class=xyz> HTML <SPAN class=abc> Program </SPAN> </h1> </body> </html> OUTPUT:
OUTPUT:
25
26
27
class Div { public static void main(String args[]) { int a=20,b=10; int c; c=a/b; [Link]("Div of a & b = " + c); } } OUTPUT:
28
import java .[Link]; class Reading { public static void main(String args[]) { DataInputStream in=new DataInputStream([Link]); int intnumber=0; float floatnumber=0.0f; try { [Link]("enter an integer "); intnumber=[Link]([Link]()); [Link]("enter a float number : "); floatnumber=[Link]([Link]()).floa tValue(); } catch (Exception e) { } [Link]("intnumber=" + intnumber); [Link]("floatnumber=" + floatnumber); } } OUTPUT:
29
30
class Sumcmd { public static void main(String args[]) { int x,y,s; x=[Link](args[0]); y=[Link](args[1]); s=x+y; [Link]("sum of x and y is" + s); s=x-y; [Link]("sub of x and y is" + s); s=x*y; [Link]("mul of x and y is" + s); s=x/y; [Link]("div of x and y is" + s); } } OUTPUT:
31
class Avg { public static void main(String args[]) { int a=10,b=20; int sum,avg; sum=a+b; [Link]("Sum = " + sum); avg=sum/2; [Link]("Average = " + avg); } } OUTPUT:
32
class Reloperator { public static void main(String args[]) { int a=10,b=20,c=10; [Link]("a<b = " + (a<b)); [Link]("a>b = " + (a>b)); [Link]("a==b = " + (a==b)); [Link]("a<=b = " + (a<=b)); [Link]("a>=b = " + (a>=b)); [Link]("a!=b = " + (a!=b)); } } OUTPUT:
33
34
35
class Largest3 { public static void main(String args[]) { int largest , a, b, c ; a=10; b=20; c=30; largest = a > b ? (a > c ? a : (b > c ? b : c)) : (b > c ? b : (a > c ? a : c)); [Link]("Largest of 10,20,30 is " +largest); } } OUTPUT:
36
[Link]("(short)b= " + s1); [Link]("(short)i= " + s2); [Link]("(float)l= " + n1); [Link]("(int)f1= " + m1); } } OUTPUT:
38
class Math1 { public static void main(String args[]) { double a; a=[Link](22,33); [Link]("The maximum among 22 and 33 is" + a); a=[Link](16); [Link]("The square root of 16 is" + a); a=[Link](-20); [Link]("The absolute value of 20 is" + a); a=[Link](16,4); [Link]("The power of 16 and 4 is" + a); a=[Link](22,33); [Link]("The minimum among 22 and 33 is" + a); a=[Link](2); [Link]("The lod value of 2 is" + a); } }
39
OUTPUT:
40
class Sqcube { public static void main(String args[]) { int num=2 , square , cube ; [Link]("\nThe squares and cubes of a number is :\n"); [Link]("================ ======================\n\n"); [Link]("Number\tSquare\tCube\n"); square = num * num ; cube = num * square ; [Link](num+"\t"+square+"\t"+cub e); } } OUTPUT:
41
class Even1 { public static void main(String args[]) { int i,c=0; [Link]("First 10 even numbers are:"); for(i=1;i<=20;i++) { if(i%2==0) { c=c+1; [Link]("\t" + i); } if(c==10) break; } } } OUTPUT:
42
class Odd1 { public static void main(String args[]) { int i,c=0; [Link]("First 10 odd numbers are:"); for(i=1;i<=20;i++) { if(i%2!=0) { c=c+1; [Link]("\t" + i); } if(c==10) break; } } } OUTPUT:
43
class Nestedifelse { public static void main(String args[]) { int a=10,b=20,c=10; if(a>b) { if(a>c){ [Link]("a is the greatest "+a); } else { [Link]("c is the greatest " + c); } } else{ if(c>b) { [Link]("c is the greatest" + c); } else { [Link]("b is the greatest " + b); }
44
} } }
45
OUTPUT:
46
class Fact { public static void main(String args[]) { int num = 5; int fact=1; for(int i=num;i>=1;i--) { fact=fact*i; } [Link]("Factorial of Given no. is : "+ fact); } } OUTPUT:
48
public static void main(String args[]) { int i=11; do { i--; [Link](i); }while(i>=2); } } OUTPUT:
int n=10,k,i=1,j=1; [Link]("table upto 10 is"); do { do { k=i*j; [Link](" " + k); j++; }while(j<=n); j=1; i++; [Link]("\n"); }while(i<=n); } } OUTPUT:
class ArmstrongNum { public static void main(String args[]) { int n=151,sum = 0, temp, r;
52
temp = n; while( temp != 0 ) { r = temp%10; sum = sum + r*r*r; temp = temp/10; } if ( n == sum ) [Link]("Entered number is an armstrong number."); else [Link]("Entered number is not an armstrong number."); } } OUTPUT:
int num,z=123; num=z; while(num>0) { rem=num%10; num=num/10; rev=(rev*10)+rem; } [Link]("reverse of a number is" + rev); if(z==rev) { [Link]("number is palindrome"); } else { [Link]("number is not palindrome"); } } }
54
OUTPUT:
55
56
class Reverse1 { public static void main(String args[]) { int rem=0,rev=0,c=0; int num,z=12345; num=z; while(num>0) { rem=num%10; num=num/10; rev=(rev*10)+rem; } [Link]("reverse of a number is" + rev); } } OUTPUT:
57
class Print1to10 { public static void main(String args[]) { int i,n=3,j,k,b=1; for(i=1;i<=n;i++) { for(j=1;j<=(n-i);j++) [Link](" "); for(k=1;k<=2*i-1;k++) { [Link](b); b++; } [Link]("\n"); } } } OUTPUT:
58
class Grade { public static void main(String args[]) { int marks=85; if(marks>79) [Link]("grade= Honours"); else if(marks>59) [Link]("grade= I division"); else if(marks>49) [Link]("grae= II division"); else if(marks>39) [Link]("grade= III division"); else [Link]("Fail"); } } OUTPUT:
59
return [Link]([Link]()); } catch (Exception e) { [Link](); return 0; } } public static void main(String[] args) { int a, b, opcode, result; [Link]("Program for Addition, Subtraction, Multiplication and Division\n"); while (true) { [Link]("Enter Your Choice: 1 - Add, 2 - Sub, 3 - Mul, 4 - Div: "); opcode = ReadInteger(); if (opcode < 1 || opcode > 4) return; [Link]("Enter First Number:"); a = ReadInteger(); [Link]("Enter Second Number:"); b = ReadInteger(); switch (opcode) { case 1: result = a + b; [Link](result); break;
61
case 2: result = a - b; [Link](result); break; case 3: result = a * b; [Link](result); break; case 4: result = a / b; [Link](result); break; default: break; } } } }
62
OUTPUT:
63
class Fibbo { public static void main(String args[]) { int x,y,z=0; [Link]("The Fibonacci Series :\n"); [Link]("=============== =====\n"); [Link]("0\n1"); for (x=0,y=1 ; y<1000 ; x=z) { z=y; y=x+y; [Link](y); } } }
64
OUTPUT:
65
class box { double width; double height; double length; } class mybox1 { public static void main( String args[ ] ) { box b1=new box(); [Link]=12; [Link]=10; [Link]=10; double vol1=[Link]*[Link]*[Link]; [Link]("volume=" + vol1); [Link]=10; [Link]=10; [Link]=10; vol1=[Link]*[Link]*[Link]; [Link]("volume=" + vol1); } }
66
OUTPUT:
67
import [Link].*; import [Link].*; class Employee { public int id; public String name; public String address; public static int count = 0; public Employee() { } public Employee(int id, String name,String address) { super(); [Link] = id; [Link] = name; [Link]=address; count++; } public int getId() { return id; } public String getName() { return name; }
68
} public class Employee1 { public static void main(String[] args) throws Exception { ListEmployee list = new ArrayListEmployee(); [Link](new Employee(1, "A","Delhi")); [Link](new Employee(2, "B","Mumbai")); [Link](new Employee(3, "C","Chennai")); [Link](new Employee(4, "D","Kolkata")); [Link](" "); [Link]("Enter Employee Id: "); Scanner input=new Scanner([Link]); int id = [Link](); for (Employee s : list){ if(id == [Link]()) { [Link]("Name and Address of employee is: "); [Link]([Link]()+" " +[Link]()); } } }
69
} OUTPUT: Name and Address of employee is: 1 , A , Delhi 2 , B , Mumbai 3 , C , Chennai 4 , D , Kolkata
70
float sportwt=6.0F; void putwt(); } class result extends test implements sports { float total; public void putwt() { [Link]("sports wt=" + sportwt); } void display() { total=part1+part2+sportwt; putnumber(); putmarks(); putwt(); [Link]("Total score=" + total); } } class Multiple1 { public static void main(String args[]) { result r1=new result(); [Link](10); [Link](20.5F,30.5F); [Link](); } }
72
OUTPUT:
73
private double height; private double depth; Box(Box ob) { width=[Link]; height=[Link]; depth=[Link]; } Box(double w,double h,double d) { width=w; height=h; depth=d; } Box() { width=-1; height=-1; depth=-1; } Box(double l) { width=height=depth=l; } double volume() { return width*height*depth; }
{ double weight; Boxweight(Boxweight ob) { super(ob); weight=[Link]; } Boxweight(double w,double h,double d,double m) { super(w,h,d); weight=m; } Boxweight() { super(); weight=-1; } Boxweight(double l,double m) { super(l); weight=l; } class Boxcolor extends Boxweight { double color; Boxcolor(Boxcolor ob) { super(ob); color=[Link];
75
} Boxcolor(double w,double h,double d,double m,double c) { super(w,h,d,m); color=c; } Boxcolor() { super(); color=-1; } Boxcolor(double l,double m,double c) { super(l,m); color=l; } } } class Multilevel1 { public static void main(String args[]) { Boxcolor c1=new Boxcolor(20,30,40,50,60); Boxcolor c2=new Boxcolor(30,60,70,40,90); double vol; vol=[Link](); [Link]("the volume of c1 = " + vol);
76
[Link]("the [Link]); [Link]("the [Link]); vol=[Link](); [Link]("the vol); [Link]("the [Link]); [Link]("the [Link]); } }
weight of c1 = " + color of c1 = " + volume of c2 = " + weight of c2 = " + color of c2 = " +
double dim1; double dim2; Figure(double a,double b) { dim1=a; dim2=b; } double area() { [Link]("Area of figure is undefined"); return 0; } } class Rect extends Figure { Rect(double a,double b) { super(a,b); } double area() { [Link]("Inside area of rectangle is"); return dim1*dim2; } } class Tri extends Figure { Tri(double a,double b)
78
{ super(a,b); } double area() { [Link]("Inside area of Tri is "); return (dim1*dim2)/2; } } class Runtimepoly { public static void main(String args[]) { Figure f=new Figure(10,10); Rect r=new Rect(9,5); Tri t=new Tri(10,12); Figure figref; figref=r; [Link]("Area is " + [Link]()); figref=t; [Link]("Area is " + [Link]()); figref=f; [Link]("Area is " + [Link]()); } } OUTPUT:
79
class Test { int a,b; Test(int i,int j) { a=i; b=j; } boolean equals(Test o) { if(o.a==a && o.b==b) return true; else return false; } } class Testob { public static void main (String args[]) { Test ob1=new Test(100,200); Test ob2=new Test(100,200); Test ob3=new Test(-1,-1); [Link]("ob1==ob2" + [Link](ob2)); [Link]("ob1==ob2" + [Link](ob3)); }
80
} OUTPUT:
81
int l=0; int w=0; try { BufferedReader br1 = new BufferedReader(new InputStreamReader([Link])); [Link]("Enter length of rectangle : "); l = [Link]([Link]()); [Link]("Enter width of rectangle : "); w = [Link]([Link]()); int area = l*w; [Link]("Area of Rectangle : "+area); } catch(Exception e) { [Link]("Error : "+e); }
82
} } OUTPUT:
83
class test { void method(int i,int j) { i *= 2; j /= 2; } } class Callvalue { public static void main(String args[]) { int a=15,b=20; [Link]("a & b="+ a + " "+ b); test obj=new test(); [Link](a,b); [Link]("a & b="+ a +" "+ b); } } OUTPUT:
{ int a,b; test (int i,int j) { a=i; b=j; } void method1(test ob) { ob.a*=2; ob.b/=2; } } class Callrefrence { public static void main(String args[]) { test ob1 = new test(15,20); ob1.method1(ob1); [Link]("ob1.a=" + ob1.a); [Link]("ob1.b=" + ob1.b); } }
85
OUTPUT:
86
import [Link].*; class Complex { int real1,imag1,real2,imag2; void get() throws IOException { BufferedReader Br = new BufferedReader(new InputStreamReader([Link])); [Link]("\n Enter the real part of first complex number: "); real1=[Link]([Link]()); [Link](" Enter the imaginary part of first complex number: "); imag1=[Link]([Link]()); [Link]("\n Enter the real part of second complex number: "); real2=[Link]([Link]()); [Link](" Enter the imaginary part of second complex number : "); imag2=[Link]([Link]()); } void display() { [Link](" \n Sum of complex numbers " + real1 + "+" + imag1 + "i and " + real2 + "+" + imag2 + "i is " + (real1+real2) + "+" + (imag1+imag2) + "i");
87
} public static void main(String p[]) throws IOException { Complex cmp = new Complex(); [Link](); [Link](); } } OUTPUT:
private double width; private double height; private double depth; Box(Box ob) { width=[Link]; height=[Link]; depth=[Link]; } Box(double w,double h,double d) { width=w; height=h; depth=d; } Box() { width=-1; height=-1; depth=-1; } Box(double l) { width=height=depth=l; } double volume() { return width*height*depth; } }
89
class Boxweight extends Box { double weight; Boxweight(Boxweight ob) { super(ob); weight=[Link]; } Boxweight(double w,double h,double d,double m) { super(w,h,d); weight=m; } Boxweight() { super(); weight=-1; } Boxweight(double l,double m) { super(l); weight=m; } } class Privatemember { public static void main(String args[]) {
90
Boxweight b1=new Boxweight(10,20,30,40.5); Boxweight b2=new Boxweight(2,3,4,5.5); Boxweight b3=new Boxweight(); Boxweight b4=new Boxweight(3,2); Boxweight b=new Boxweight(b1); double vol; vol=[Link](); [Link]("volume of b1=" + vol); [Link]("weight of b1=" + [Link]); [Link](); } } OUTPUT:
static int b; static void method(int x) { [Link]("x=" + x); [Link]("a=" + a); [Link]("b=" + b); } static { [Link]("static block"); b=a*4; } public static void main(String args[]) { method(40); } } OUTPUT:
int number[]={55,40,80,65,71}; int n; n=[Link]; [Link]("Given list :"); for(int i=0;i<n;i++) { [Link](" " + number[i]); } [Link]("/n"); 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]("Sorted list"); for(int i=0;i<n;i++) { [Link](" " +number[i]); } [Link](" "); } }
93
OUTPUT:
{ int size=[Link]; String temp=null; for(int i=0;i<size;i++) { for(int j=i+1;j<size;j++) { if(name[j].compareTo(name[i])<0) { temp=name[i]; name[i]=name[j]; name[j]=temp; } } } for(int i=0;i<size;i++) { [Link](name[i]); } } } OUTPUT:
95
96
{ public static void main(String args[]) { Vector list=new Vector(); int length=[Link]; for(int i=0;i<length;i++) { [Link](args[i]); } [Link]("COBOL",1); int size=[Link](); String listArray[]=new String[size]; [Link](listArray); [Link]("List of languages"); for(int i=0;i<size;i++) { [Link](listArray[i]); } } }
97
OUTPUT:
98
Program to show use of Wrapper class import [Link].*; class Wrapper1 { public static void main(String args[]){ Float principalAmount=new Float(0); Float interestRate=new Float(0); int numYears=0; try{ DataInputStream in=new DataInputStream([Link]); [Link]("Enter principal amount"); [Link](); String principalString=[Link](); principalAmount=[Link](principalStri ng); [Link]("Enter interest rate"); [Link](); String interestString=[Link](); interestRate=[Link](interestString); [Link]("Enter number of years"); [Link](); String yearsString=[Link](); numYears=[Link](yearsString); } catch(IOException e) { [Link]("I/O Error"); [Link](1); }
99
float value=loan([Link](),intere [Link](),numYears); printline(); [Link]("Final values =" + value); printline(); } static float loan(float p,float r,int n) { int year=1; float sum=p; while(year<=n) { sum=sum*(1+r); year=year+1; } return sum; } static void printline() { for(int i=1;i<=30;i++) { [Link]("="); } [Link](" "); } } OUTPUT:
100
101
[Link]("area of rectangle is " + [Link](10,20)); a1=cir; [Link]("area of circle =" + [Link](10,0)); } } OUTPUT:
public class Matrix1 { private static int column; public static void main(String[] args) { int [][]array1={{1,2,3,4},{5,6,7},{8,9}, {10}}; [Link]("Values in array1 by row are"); OutputArray(array1); } public static void OutputArray(int[][] array1) { int sum=0; for(int row=0;row<[Link];row++) { for( column=0;column<array1[row].length;c olumn++) [Link]("\t"+"\t" + array1[row] [column]); [Link](); } [Link](); sum=sum+[Link]; [Link]("sum=\t"+sum+"\t"); [Link](); } }
104
OUTPUT:
105
106
107
OUTPUT:
108
109
package package4; public class Arithmetic { public void arith(){ int a=30,b=20,c; c=a+b; [Link]("Addition of a & b is " + c); c=a-b; [Link]("Sub of a & b is " +c); c=a*b; [Link]("Mul of a & b is " + c); c=a/b; [Link]("Division of a & b is " + c); } } import [Link]; class Packagetest5{ public static void main(String args[]) { Arithmetic a1=new Arithmetic(); [Link](); } }
111
OUTPUT:
112
import static [Link].*; public class Mathop { public void circle(double r) { double area=PI*r*r; [Link]("The area of circle is " + area); } public static void main(String args[]) { Mathop obj=new Mathop(); [Link](2.3); } } OUTPUT: The area of circle is 16.619025137490002
class A extends Thread { public void run() { for(int i=0;i<=5;i++) { [Link](" From Thread A :" + i); } [Link]("exit from A"); } } class B extends Thread { public void run() { for(int i=0;i<=5;i++) { [Link](" From Thread B :" + i); } [Link]("exit from B"); } } class C extends Thread { public void run() { for(int i=0;i<=5;i++) { [Link](" From Thread C :" + i); }
115
[Link]("exit from C"); } } class Threadtest { public static void main(String args[]) { new A().start(); new B().start(); new C().start(); } } OUTPUT:
Program to display use of yield(),stop() and sleep() methods class A extends Thread
116
{ public void run() { for(int i=1;i<=5;i++) { if(i==1) yield(); [Link](" From Thread A :" + i); } [Link]("exit from A"); } } class B extends Thread { public void run() { for(int j=1;j<=5;j++) { [Link](" From Thread B :" + j); if(j==3) stop(); } [Link]("exit from B"); } } class C extends Thread { public void run() { for(int k=1;k<=5;k++) { [Link](" From Thread C :" + k);
117
if(k==1) try { sleep(1000); } catch(Exception e) { } } [Link]("exit from C"); } } class Threadmethod { public static void main(String args[]) { A threadA=new A(); B threadB=new B(); C threadC=new C(); [Link]("start thread A"); [Link](); [Link]("start thread B"); [Link](); [Link]("start thread C"); [Link](); [Link]("End of main thread"); } } OUTPUT:
118
119
[Link](" From Thread A :" + i); } [Link]("exit from A"); } } class B extends Thread { public void run() { for(int j=1;j<=4;j++) { [Link](" From Thread B :" + j); } [Link]("exit from B"); } } class C extends Thread { public void run() { for(int k=0;k<=4;k++) { [Link](" From Thread C :" + k); } [Link]("exit from C"); } } class Threadpriority { public static void main(String args[])
120
{ A threadA=new A(); B threadB=new B(); C threadC=new C(); [Link](Thread.MAX_PRIORITY); [Link]([Link]()+1); [Link](Thread.MIN_PRIORITY); [Link]("Start thread A"); [Link](); [Link]("Start thread B"); [Link](); [Link]("Start thread C"); [Link](); [Link]("End of main thread"); } }
121
OUTPUT:
122
class A implements Runnable { public void run() { for(int i=1;i<=10;i++) { [Link]("/tThreadA : " +i); } [Link]("End of ThreadA"); } } class Runnabletest { public static void main(String args[]) { A runnable=new A(); Thread threadA=new Thread(runnable); [Link](); [Link]("End of main thread" ); } }
123
OUTPUT:
124
class sus_res_stop implements Runnable { Thread Th; boolean suspend_flag,stop_flag; sus_res_stop(String tN) { Th=new Thread(this,tN); suspend_flag=false; stop_flag=false; [Link](); } public void run() { try { int j=1; while(++j<20) { synchronized(this) { while(suspend_flag) { wait(); } if(stop_flag) { break;
125
} } } } catch(InterruptedException IE) { [Link]("thread interrupted"); } } synchronized void my_suspend() { suspend_flag=true; } synchronized void my_resume() { suspend_flag=false; notify(); } synchronized void my_stop() { suspend_flag=false; stop_flag=true; notify(); } } public class eg_SRS { public static void main(String[] args) { try
126
{ sus_res_stop S_R_S_T=new sus_res_stop("SRS"); [Link]("Thread S_R_S_T is created and started"); [Link](2000); S_R_S_T.my_suspend(); [Link]("Thread S_R_S_T is suspended"); [Link](2000); S_R_S_T.my_resume(); [Link]("Thread S_R_S_T is resumed"); [Link](2000); S_R_S_T.my_suspend(); [Link]("Thread S_R_S_T is suspended"); [Link](2000); S_R_S_T.my_resume(); [Link]("Thread S_R_S_T is resumed"); [Link](2000); S_R_S_T.my_stop(); [Link]("Thread S_R_S_T is stopped"); } catch(InterruptedException IE) { [Link]("Generated interrupted exception");
127
} OUTPUT:
} }
128
Program to display compile time error class Error1 { public static void main(String args[]){ [Link]("Hello Java") } }
OUTPUT:
129
130
131
Program of catching invalid command line arguments class Clineinput { public static void main(String args[]) { int invalid = 0; int number ,count=0; for(int i=0;i<[Link];i++) { try { number=[Link](args[i]); } catch(NumberFormatException e) { invalid =invalid +1; [Link]("invalid number :" + args[i]); continue; } count=count+1; } [Link]("valid number=" + count); [Link]("invalid number=" + invalid); } }
132
OUTPUT:
133
class Nestedtry1 { public static void main(String args[]) { try { int a=2,b=4,c=2,x=7,z; int p[]={2}; p[3]=33; try { z=x/((b*b)-(4*a*c)); [Link]("the value of z is=" + z); } catch(ArithmeticException e) { [Link]("division by zero in arithmetic"); } } catch(ArrayIndexOutOfBoundsException e) { [Link]("Array index is out of bound"); } } }
134
OUTPUT:
135
class Error4 { public static void main(String args[]) { int a[]={5,10}; int b=5; try { int x=a[2]/b-a[1]; } catch(ArithmeticException e) { [Link]("Division by zero"); } catch(ArrayIndexOutOfBoundsException e) { [Link]("Array index error"); } catch(ArrayStoreException e) { [Link]("Wrong data type"); } int y=a[1]/a[0]; [Link]("y=" + y); } }
136
OUTPUT:
137
import [Link]; class MyException extends Exception { MyException(String message) { super(message); } } class Testmyexception { public static void main(String args[]) { int x=5,y=1000; try { float z=(float)x/(float)y; if(z < 0.01) { throw new MyException("number is too small"); } } catch(MyException e) { [Link]("caught my exception"); [Link]([Link]()); } finally
138
class Throws1 { static void divide_m() throws ArithmeticException { int x=22,y=0,z; z=x/y; } public static void main9String args[]) { try { divide_m(); } catch(ArithmeticException e) { [Link]("Caught the exception" + e); } } } OUTPUT:
Applet file <html> <applet code=[Link] width=300 height=300 > </applet> </html> Java file import [Link].*; import [Link].*; public class Hellojava extends Applet { public void paint(Graphics g) { String str; str="HELLO JAVA"; [Link](str); [Link](str,10,100); } }
141
OUTPUT:
142
} OUTPUT:
<applet code=[Link] width=300 height=300> </applet> </html> import [Link].*; import [Link].*; public class Numvalues extends Applet { public void paint(Graphics g) { int values1=10; int values2=20; int sum=values1+values2; String s="sum:" +[Link](sum); [Link](s,100,100); } }
145
OUTPUT:
146
s1=[Link](); x=[Link](s1); s2=[Link](); y=[Link](s2); } catch(Exception ex) { } z=x+y; s=[Link](z); [Link]("The Sum is:" ,10,75); } public boolean action (Event event,Object object) { repaint(); return true; } } OUTPUT:
148
import [Link]; import [Link]; import [Link]; public class Setbkgcolor extends Applet { public void paint(Graphics g) { setBackground([Link]); } } <html> <body> <applet code=[Link] width=200 height=200> </applet> </body> </html
149
OUTPUT:
150
<html> <body> <applet code=[Link] width=200 height=200> </applet> </body> </html> import [Link].*; import [Link].*; import [Link].*; public class Event1 extends Applet implements KeyListener { public void init() { addKeyListener(this); } public void keyTyped(KeyEvent KB) { } public void keyReleased(KeyEvent KB) { showStatus("Key on the keyboard is released"); } public void keyPressed(KeyEvent KB) {
151
showStatus("A key on the keyboard is pressed"); } Font f1=new Font("courier new",[Link],20); public void paint(Graphics GA) { [Link](f1); [Link]([Link]); [Link]("This applet sense the up/down motion of keys",20,120); } } OUTPUT:
152
Program to demonstrate Labels <html> <body> <applet code=[Link] width=200 height=300> </applet> </body> </html> import [Link].*; import [Link].*; public class Labeldemo extends Applet{ public void init() { Label one=new Label("One"); Label two=new Label("Two"); Label three=new Label("Three"); add(one); add(two); add(three); } }
153
OUTPUT:
154
Program to demonstrate buttons in an applet <html> <body> <applet code=[Link] width=200 height=300> </applet> </body> </html> import [Link].*; import [Link].*; import [Link].*; public class Buttondemo extends Applet implements ActionListener { String msg=""; Button yes,no,maybe; public void init() { yes=new Button("Yes"); no=new Button("No"); maybe=new Button("Undecided"); add(yes); add(no); add(maybe); [Link](this); [Link](this); [Link](this); }
155
public void actionPerformed(ActionEvent ae) { String str=[Link](); if([Link]("Yes")) { msg="u pressed Yes"; } else if([Link]("No")) { msg="U pressed No"; } else { msg="u pressed Undecided"; } repaint(); } public void paint(Graphics g) { [Link](msg,6,100); } }
156
OUTPUT:
157
Program to perform arithmetic operations in buttons <html> <body> <applet code=[Link] width=200 height=200> </applet> </body> </html import [Link].*; import [Link].*; import [Link].*; public class Buttonarith extends Applet implements ActionListener { String msg=""; Button add,sub,divide; public void init() { add=new Button("Addition"); sub=new Button("Subtract"); divide=new Button("Division"); add(add); add(sub); add(divide); [Link](this); [Link](this); [Link](this); }
158
public void actionPerformed(ActionEvent ae) { String str=[Link](); int a=10,b=10,c; if([Link]("add")) { c=a+b; [Link]("the additio is" + c); } else if([Link]("sub")) { c=a*b; msg="the sub is"; } else { c=a/b; msg="the divide is "; } repaint(); } public void paint(Graphics g) { [Link](msg,6,100); } }
159
OUTPUT:
160
[Link](this); [Link](this); [Link](this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) { msg="Current state:"; [Link](msg,6,80); msg="Windows 98: " + [Link](); [Link](msg,6,100); msg="Windows NT: " + [Link](); [Link](msg,6,120); msg="Solaris: " + [Link](); [Link](msg,6,140); msg="MacOS: " + [Link](); [Link](msg,6,160); } }
162
OUTPUT:
163
<html> <body> <applet code =[Link] width=200 height=300> </applet> </body> </html> import [Link].*; import [Link].*; import [Link].*; public class Checkboxgroup extends Applet implements ItemListener { String msg=""; Checkbox Win98,winNT,solaris,mac; CheckboxGroup cbg; public void init() { cbg=new CheckboxGroup(); Win98=new Checkbox("Windows 98",cbg,true); winNT=new Checkbox("Windows NT",cbg,false); solaris=new Checkbox("Solaris",cbg,false); mac=new Checkbox("MacOS",cbg,false); add(Win98); add(winNT);
164
add(solaris); add(mac); [Link](this); [Link](this); [Link](this); [Link](this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) { msg="Current selection:"; msg += [Link]().getLabel(); [Link](msg,6,100); } }
165
OUTPUT:
166
[Link]("Internet Explorer 3.0"); [Link]("Internet Explorer 4.0"); [Link]("Lynx 2.4"); [Link]("Netscape 4.x"); add(os); add(browser); [Link](this); [Link](this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint (Graphics g) { msg = "Current OS: "; msg += [Link](); [Link](msg, 6, 120); msg = "Current Browser: "; msg += [Link](); [Link](msg, 6, 140); } }
168
OUTPUT:
169
<html> <body> <applet code=[Link] width=200 height=300> </applet> </body> </html> import [Link].*; import [Link].*; import [Link].*; public class ListDemo extends Applet implements ActionListener { List os,browser; String msg = " "; public void init() { os = new List(4,true); browser = new List(4,false); [Link]("Windows 98"); [Link]("Windows NT"); [Link]("Solaris"); [Link]("MacOS"); [Link]("Netscape 1.1"); [Link]("Netscape 2.x"); [Link]("Netscape 3.x"); [Link]("Netscape 4.x"); [Link]("Internet Explorer 2.0");
170
[Link]("Internet Explorer 3.0"); [Link]("Internet Explorer 4.0"); [Link]("Lynx 2.4"); [Link](1); add(os); add(browser); [Link](this); [Link](this); } public void actionPerformed(ActionEvent ae) { repaint(); } public void paint (Graphics g) { msg = "Current OS: "; msg += [Link](); [Link](msg, 6, 120); msg = "Current Browser: "; msg += [Link](); [Link](msg, 6, 140); } }
171
OUTPUT:
172
<html> <body> <applet code=[Link] width=200 height=300> </applet </body> </html> import [Link].*; import [Link].*; import [Link].*; public class SBdemo extends Applet implements AdjustmentListener,MouseMotionListener { String msg=""; Scrollbar vertSB,horzSB; public void init() { int width=[Link](getParameter("width")) ; int height=[Link](getParameter("height" )); vertSB = new Scrollbar([Link],0,1,0,height); horzSB = new Scrollbar([Link],0,1,0,width); add(vertSB);
173
add(horzSB); [Link](this); [Link](this); addMouseMotionListener(this); } public void adjustmentValueChanged(AdjustmentEvent ae) { repaint(); } public void mouseDragged(MouseEvent me) { int x=[Link](); int y=[Link](); [Link](y); [Link](x); repaint(); } public void mouseMoved(MouseEvent me) { } public void paint(Graphics g){ msg="Vertical:"+ [Link](); msg+="Horizontal:" + [Link](); [Link](msg,6,160); [Link]("*",[Link](),vertSB.g etValue()); } }
174
OUTPUT:
175
<html> <body> <applet code=[Link] width=200 height=300> </applet> </body> </html> import [Link].*; import [Link].*; import [Link].*; public class Flowlayoutdemo extends Applet implements ItemListener { String msg=""; Checkbox Win98,winNT,solaris,mac; public void init() { setLayout(new FlowLayout([Link])); Win98=new Checkbox("Windows 98",null,true); winNT=new Checkbox("Windows NT"); solaris=new Checkbox("Solaris"); mac=new Checkbox("MacOS"); add(Win98); add(winNT); add(solaris); add(mac);
176
[Link](this); [Link](this); [Link](this); [Link](this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) { msg="Current state:"; [Link](msg,6,80); msg="Windows 98: " + [Link](); [Link](msg,6,100); msg="Windows NT: " + [Link](); [Link](msg,6,120); msg="Solaris: " + [Link](); [Link](msg,6,140); msg="MacOS: " + [Link](); [Link](msg,6,160); } }
177
OUTPUT:
178
<html> <body> <applet code=[Link] width=300 height=300> </applet> </body> </html> import [Link].*; import [Link].*; public class Graphicmethods extends Applet { String s=new String(); String s1=new String(); String s2=new String(); Font f1=new Font("Courier New ", [Link],20); public void paint(Graphics GA) { [Link](f1); [Link]([Link]); [Link]("Illustration of methods of graphics class",200,250); Font f2=[Link](); s=[Link](); [Link](s,5,540); [Link]([Link]); Color col=[Link](); s2=[Link]();
179
[Link](s2,5,560); [Link](500,15,70,90); [Link](160,5,60,60); [Link](10,120,155,95); [Link]([Link]); [Link](700,140,50,150); [Link]([Link]); [Link](380,100,200,180); [Link](400,150,180,280,90,70); int x2[]={200,120,280,240}; int z2=4; int y2[]={260,370,370,270}; [Link]([Link]); [Link](x2,y2,z2); [Link]([Link]); [Link](15,15,30,50); FontMetrics f3=[Link](); s1=[Link](); [Link](s1,5,580); [Link]([Link]); [Link](510,400,90,80,20,20); } }
180
OUTPUT:
181
182
OUTPUT:
<body> <applet code=[Link] width=300 height=300> </applet> </body> </html> import [Link].*; import [Link].*; public class Triangle2 extends Applet { public void paint(Graphics g) { [Link](200,150,160,300); [Link](200,150,260,300); [Link](160,300,260,300); } }OUTPUT:
<body> <applet code=[Link] width=300 height=300> </applet> </body> </html> import [Link].*; import [Link].*; public class Star2 extends Applet { public void paint(Graphics g) { Point[] points = new Point[9]; points[0] = new Point(28, 5); points[1] = new Point(27, 21); points[2] = new Point(13, 24); points[3] = new Point(27, 27); points[4] = new Point(28, 41); points[5] = new Point(31, 27); points[6] = new Point(42, 24); points[7] = new Point(31, 21); points[8] = new Point(28, 5); int i; for (i=1; i<[Link]; i++) [Link](points[i-1].x, points[i-1].y, points[i].x, points[i].y); } } OUTPUT:
185
</applet> </body> </html> import [Link].*; import java . applet.*; public class ControlLoop extends Applet { public void paint (Graphics g) { for (int i=0; i<=4; i++) { if((i%2)==0) [Link] (120, i*60+10, 50, 50); else [Link] (120, 1*60+10, 50, 50) ; } } }
187
OUTPUT:
188
import [Link].*; class WriteBytes { public static void main (String args[ ] ) { byte cities [ ] = {'D', 'E','L', 'H', 'I', 'M', 'A', 'D','R', 'A', 'S' , 'L','O','N','D','O','N' }; FileOutputStream outfile = null; try { outfile= new FileOutputStream ("[Link]") ; outfile. write (cities) ; [Link](); } catch (IOException ioe) { [Link] (ioe) ; [Link] (-1) ; } } } OUTPUT:
import [Link].*; class ReadBytes { public static void main(String args[]) { FileInputStream infile=null; int b; try { infile=new FileInputStream(args[0]); while((b=[Link]()) != -1) { [Link]((char) b); } [Link](); } catch(IOException ioe) { [Link](ioe); } } }
190
OUTPUT:
191