Beruflich Dokumente
Kultur Dokumente
VARIOUS TAGS USED IN HTML 1. <MARQUEE>. </MARQUEE>: This tag is used to scroll text horizontally across the screen. For example: <HTML> <HEAD> <TITLE> Marquee Tag </TITLE> </HEAD> <BODY> <h1><MARQUEE>MARQUEE TAG </MARQUEE></h1> </BODY> </HTML>
OUTPUT:
/*PROGRAM TO DISPLAY ATTRIBUTES OF BODY TAG*/ <html> <head> <title> body tags </title> </head> <body bgcolor = "black"> <i><b><center><fontcolor="red">Satnam Foundry</center></b></i> WELCOME in our Profile <font color="red"><h2> <br> <p><h1>Satnam Foundry </h1><h3>is a special manufacturer of iron and ironic products.This industry was setup under<h2> Jassal Enterprices</h2>This enterprice is located at Punjab,INDIA</center><br/> </body> </html> OUTPUT:
/*PROGRAM TO SHOW USE OF FONT & CENTER TAGS*/ <html> <head> <title> Delta Engineering Pvt.Ltd.</title> </head> <body background = "abc.jpg"> <font color="darkblue" size="5"><i><b><center>Delta Engineering Pvt.Ltd</center></b></i> <hr align="center" color="black"> <br> <center><fontcolor="PINK"><h1><MARQUEEDIRECTI ON="LEFT"> WELCOME</MARQUEE> <MARQUEE DIRECTION="RIGHT">IN OUR </MARQUEE><MARQUEEDIRECTION="LEFT">Profil e</MARQUEE></BLINK></h1></center> <font color="darkblue"><h2> <br> <p><h1><center>Delta Engineering Pvt.Ltd</center> </h1><h3>is a special manufacturer of wire and wire products..DEPL established in Mumbai,India is ideally located for shipments to any part of the world.Thhe main items of manufacture, in collaboration with Gulf Fencing Industry include protector gabions and protector fencing systems. </body> </html> OUTPUT:
4
/*PROGRAM TO SHOW USE OF MARQUEE, SUB & SUP TAG*/ <html> <head> <title>mathematical expression</title> </head> <body bgcolor=black> <font color=red> <center><h2><i><u> mathematical expression</u></i> <p> x<sup>2</sup>+y<sup>3</sup>=z <p> log<sub>10</sub> <p> a<sup>2</sup>+b log<sub>10</sub> </center> </body></html>
OUTPUT:
<li>Dot Matrix <li>Daisy Wheel </ol> <li>line Printer <ol type="a"> <li>Drum Printer <li>Chain Printer </ol> </ol> </ol> </ol></ol> <br> <li>Non Impact Printer <ol type="A"> <li>Inkjet Printer <li>Laser Printer <li>Plotter </ol> <br> <br> <li>Memory <br> <ol type="1"> <u><li>Primary Memory</u> <ol type="a"> <li>Cache <li>RAM <ol type="i"> <li>Static RAM <li>Dynamic RAM </ol> <li>ROM <ol type="i"> <li>PROM <li>EPROM
9
<li>EEPROM </ol> </ol> <br> <u><li>Secondary Memory</u> </ol> <ol type="a"> <li>Magnetic Storage <ol type="i"> <li>Magnetic Tape <li>Magnetic Disk </ol> <ol type="a"> <li>Floppy Disk <li>Hard Disk Drive </ol> <li>Optical storage </ol> <ol type="i"> <li>Optical Disk <li>Digital Versatic Disk <li>Blue Ray Disk </ol></body> </html>
10
OUTPUT:
11
<html> <head><title> working with images</title> </head> <body bgcolor="black"> <b> <font color="red">controlling image borders!<b> <center> <i>image without a border</i><br/> <r/> <img src="blue.jpg"><br/><br/> <i>image with border</i><br/> <br/> <img src="blue.jpg" height="50" width="50"> <br/> </center> </body> </html>
12
OUTPUT:
13
/*PROGRAM TO SHOW THE USE OF TABLE TAG*/ <html> <head><title>student.com</title></head> <body><b><center><h1>TABLE</h1></center></b> <center><table border="2"></center> <tr><th colspan="7"><center>student</center></th></tr> <tr><th rowspan="2">rollno</th> <th rowspan="2">name</th> <th colspan="3">marks</th> <th rowspan="2">total marks</th> <th rowspan="2">groups</th> </tr> <tr><th>c++</th> <th>graphics</th> <th>java</th> </tr> <tr><td>101</td> <td>gagan</td> <td>70</td> <td>80</td> <td>50</td> <td>200</td> <td rowspan="2">1</td> </tr> <tr><td>102</td> <td>gurpreet</td> <td>60</td> <td>80</td> <td>50</td> <td>190</td> </tr> <tr><td>103</td>
14
<td>suman</td> <td>60</td> <td>80</td> <td>40</td> <td>180</td> <td rowspan="2">2</td></tr> <tr><td>104</td> <td>harpreet</td> <td>60</td> <td>50</td> <td>50</td> <td>160</td> </tr> </table> </body> </html>
OUTPUT:
15
16
/*PROGRAM TO DISPLAY FRAME IN HTML*/ <html> <head><title>frame.com</title></head> <frameset rows="30%,50%,20%"> <frame src="gg7.HTML"> <frameset cols="50%,50%"> <frame name="f1" src="gg14.html"> <frame name="f2" src="f1"> </frameset> <frame src="gg22.html"> </frameset> </html>
//gg7
<html> <head><title>notesite.in</title></head> <body bgcolor="green"><marquee behaviour="alternate"><h1>welcome to all</h1></marquee></body> </html>
//gg14
<html> <head><title>linking.com</title></head> <body bgcolor="`pink" text="brown"><b><i><h1>SUBJECTS OF BCA FINAL</h1></i></b> <h2><a href="gg15.html" target="f2">computer graphics</h2></a> <h2><a href="gg16.html" target="f2">computer networks</h2></a> <h2><a href="gg17.html" target="f2">html</h2></a> <h2><a href="gg18.html" target="f2">edp</h2></a> <h2><a href="gg19.html" target="f2">maths</h2></a> </body>
17
</html>
//gg15
<html> <head><title>linking</title></head> <body bgcolor="pink"><b><i><h1>syllabus of graphics</h1></i></b> <h2>chapter 1=introduction of computer graphics</h2></br> <h2>chapter 2=video display unit</h2></br> <h2>chapter 3=input devices</h2></br> </body></html>
//gg16
<html> <head><title>network.com</title></head> <body bgcolor="pink"><b><i><h1>syllabus of computer networks</h1></i></b> <h1>chapter 1 =uses of computer network</h1></br> <h1>chapter 2= network hardware</h1></br> <h1>chapter 3=physical layer</h1></br> </body> </html>
//gg17
<html> <head><title>network.com</title></head> <body bgcolor="pink"><b><i><h1>syllabus of computer networks</h1></i></b> <h1>chapter 1 =uses of computer network</h1></br> <h1>chapter 2= network hardware</h1></br> <h1>chapter 3=physical layer</h1></br> </body> </html>
//gg18
<html>
18
<head><title>edp.com</title></head> <body bgcolor="pink"<b><i><h1>syllabus of edp</h1></i></b> <h2>chapter 1=project formulation</h2></br> <h2>chapter 2=reports</h2></br> <h2>chapter 3=ratios </h2></br> </body> </html>
//gg19
<html> <head><title>maths.com</title></head> <body bgcolor="pink"><b><i><h1>syllabus of maths</h1></i></b> <h2>chapter 1=sets</h2></br> <h2>chapter 2=relation</h2></br> <h2>chapter 3=functions</h2></br> </body> </html>
//gg22
<html> <head><title>notesite.in</title></head> <body bgcolor="red"> <b><i><h1>THANKYOU FOR VISITING</b></i></h1></body> </html>
19
OUTPUT:
20
</body> </html>
OUTPUT:
22
</tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table><br> Strength:</a> </fieldset> </body> </html> OUTPUT;-
24
25
/*IMAGE MAP*/
Image maps are image links in which a single image can have multiple links. For example: <HTML> <BODY <A> <IMG SRC="DOLL.JPG" HEIGHT=200 WIDTH=200 USEMAP="#M1"> </A> <MAP NAME="M1"> <AREA SHAPE="RECTANGLE" COORDS=10, 20, 50, 60 HREF="DOLL.JPG"> <AREA SHAPE="CIRCLE" COORDS=100, 100, 40 HREF="DOLL1.JPG"> <AREA SHAPE="POLYGON" COORDS=50, 50, 90, 60, 70, 80, 50, 70, 30, 50 HREF="DOLL.JPG"> <AREA SHAPE=DEFAULT HREF="DOLL1.JPG" ALT="DEFAULT CASE"> </MAP> </BODY> </HTML>
26
OUTPUT:
27
<html> <head> <body> <s> HELLO </s> <br><br> <strong> HELLO </strong> <br><br> <pre> HELLO & WELCOME </pre> </head> </body> </html> OUTPUT:
DHTML
28
<html> <body> p1{color:pink} h1{color:red} </body> </html> <html> <head> <link rel=stylesheet href="C:\Users\DELL\Desktop\hgrewal\html\dht ml1.css"> </head> <body> <p1>Welcome <h1>Hello </body> </html> OUTPUT:
<html> <body> p{color:pink} .abc{Text-decoration:Underline} </body> </html> <html> <head> <link rel=stylesheet href="C:\Users\DELL\Desktop\hgrewal\html\dht ml2.css"> </head> <body> <p>Welcome <p class="abc">Hello </body> </html> OUTPUT:
<head> <style type=text/css> p{color:red} h1{color:pink;font-style:italic} </style> </head> <body> hello <p> Welcome <h1> First page </h1> End </body> </html> OUTPUT:
31
p{color:red} .abc{color:pink;font-style:italic} .xyz{color:blue} </style> </head> <body> <p> hello <p class=abc> Welcome <p class=xyz> HTML </h1> </body> </html> OUTPUT:
<h1 style=color:red;font-style:italic> Welcome </h1> <h1> Hello </h1> </body> </html> OUTPUT:
.abc{color:pink;font-style:italic} .xyz{color:blue} </style> </head> <body> <p> hello <p class=abc> Welcome to <SPAN class=xyz> HTML </SPAN> programming <p class=xyz> HTML <SPAN class=abc> Program </SPAN> </h1> </body> </html> OUTPUT:
34
public static void main(String args[]) { System.out.println("Welcome in the Java World"); } } OUTPUT:
} OUTPUT:
36
37
38
class Div { public static void main(String args[]) { int a=20,b=10; int c; c=a/b; System.out.println("Div of a & b = " + c); } } OUTPUT:
39
import java .io.DataInputStream; class Reading { public static void main(String args[]) { DataInputStream in=new DataInputStream(System.in); int intnumber=0; float floatnumber=0.0f; try { System.out.println("enter an integer "); intnumber=Integer.parseInt(in.readLine()); System.out.println("enter a float number : "); floatnumber=Float.valueOf(in.readLine()).floa tValue(); } catch (Exception e) { } System.out.println("intnumber=" + intnumber); System.out.println("floatnumber=" + floatnumber); } } OUTPUT:
40
41
class Sumcmd { public static void main(String args[]) { int x,y,s; x=Integer.parseInt(args[0]); y=Integer.parseInt(args[1]); s=x+y; System.out.println("sum of x and y is" + s); s=x-y; System.out.println("sub of x and y is" + s); s=x*y; System.out.println("mul of x and y is" + s); s=x/y; System.out.println("div of x and y is" + s); } } OUTPUT:
42
class Avg { public static void main(String args[]) { int a=10,b=20; int sum,avg; sum=a+b; System.out.println("Sum = " + sum); avg=sum/2; System.out.println("Average = " + avg); } } OUTPUT:
43
class Reloperator { public static void main(String args[]) { int a=10,b=20,c=10; System.out.println("a<b = " + (a<b)); System.out.println("a>b = " + (a>b)); System.out.println("a==b = " + (a==b)); System.out.println("a<=b = " + (a<=b)); System.out.println("a>=b = " + (a>=b)); System.out.println("a!=b = " + (a!=b)); } } OUTPUT:
44
45
46
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)); System.out.println("Largest of 10,20,30 is " +largest); } } OUTPUT:
47
System.out.println("(short)b= " + s1); System.out.println("(short)i= " + s2); System.out.println("(float)l= " + n1); System.out.println("(int)f1= " + m1); } } OUTPUT:
49
class Math1 { public static void main(String args[]) { double a; a=Math.max(22,33); System.out.println("The maximum among 22 and 33 is" + a); a=Math.sqrt(16); System.out.println("The square root of 16 is" + a); a=Math.abs(-20); System.out.println("The absolute value of 20 is" + a); a=Math.pow(16,4); System.out.println("The power of 16 and 4 is" + a); a=Math.min(22,33); System.out.println("The minimum among 22 and 33 is" + a); a=Math.log(2); System.out.println("The lod value of 2 is" + a); } }
50
OUTPUT:
51
class Sqcube { public static void main(String args[]) { int num=2 , square , cube ; System.out.println("\nThe squares and cubes of a number is :\n"); System.out.println("================ ======================\n\n"); System.out.println("Number\tSquare\tCube\n"); square = num * num ; cube = num * square ; System.out.println(num+"\t"+square+"\t"+cub e); } } OUTPUT:
52
class Even1 { public static void main(String args[]) { int i,c=0; System.out.println("First 10 even numbers are:"); for(i=1;i<=20;i++) { if(i%2==0) { c=c+1; System.out.print("\t" + i); } if(c==10) break; } } } OUTPUT:
53
class Odd1 { public static void main(String args[]) { int i,c=0; System.out.println("First 10 odd numbers are:"); for(i=1;i<=20;i++) { if(i%2!=0) { c=c+1; System.out.print("\t" + i); } if(c==10) break; } } } OUTPUT:
54
class Nestedifelse { public static void main(String args[]) { int a=10,b=20,c=10; if(a>b) { if(a>c){ System.out.println("a is the greatest "+a); } else { System.out.println("c is the greatest " + c); } } else{ if(c>b) { System.out.println("c is the greatest" + c); } else { System.out.println("b is the greatest " + b); }
55
} } }
56
OUTPUT:
57
class Fact { public static void main(String args[]) { int num = 5; int fact=1; for(int i=num;i>=1;i--) { fact=fact*i; } System.out.println("Factorial of Given no. is : "+ fact); } } OUTPUT:
59
public static void main(String args[]) { int i=11; do { i--; System.out.println(i); }while(i>=2); } } OUTPUT:
int n=10,k,i=1,j=1; System.out.println("table upto 10 is"); do { do { k=i*j; System.out.print(" " + k); j++; }while(j<=n); j=1; i++; System.out.print("\n"); }while(i<=n); } } OUTPUT:
class ArmstrongNum { public static void main(String args[]) { int n=151,sum = 0, temp, r;
63
temp = n; while( temp != 0 ) { r = temp%10; sum = sum + r*r*r; temp = temp/10; } if ( n == sum ) System.out.println("Entered number is an armstrong number."); else System.out.println("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; } System.out.println("reverse of a number is" + rev); if(z==rev) { System.out.println("number is palindrome"); } else { System.out.println("number is not palindrome"); } } }
65
OUTPUT:
66
67
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; } System.out.println("reverse of a number is" + rev); } } OUTPUT:
68
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++) System.out.print(" "); for(k=1;k<=2*i-1;k++) { System.out.print(b); b++; } System.out.print("\n"); } } } OUTPUT:
69
class Grade { public static void main(String args[]) { int marks=85; if(marks>79) System.out.println("grade= Honours"); else if(marks>59) System.out.println("grade= I division"); else if(marks>49) System.out.println("grae= II division"); else if(marks>39) System.out.println("grade= III division"); else System.out.println("Fail"); } } OUTPUT:
70
return Integer.parseInt(reader.readLine()); } catch (Exception e) { e.printStackTrace(); return 0; } } public static void main(String[] args) { int a, b, opcode, result; System.out.println("Program for Addition, Subtraction, Multiplication and Division\n"); while (true) { System.out.print("Enter Your Choice: 1 - Add, 2 - Sub, 3 - Mul, 4 - Div: "); opcode = ReadInteger(); if (opcode < 1 || opcode > 4) return; System.out.print("Enter First Number:"); a = ReadInteger(); System.out.print("Enter Second Number:"); b = ReadInteger(); switch (opcode) { case 1: result = a + b; System.out.println(result); break;
72
case 2: result = a - b; System.out.println(result); break; case 3: result = a * b; System.out.println(result); break; case 4: result = a / b; System.out.println(result); break; default: break; } } } }
73
OUTPUT:
74
class Fibbo { public static void main(String args[]) { int x,y,z=0; System.out.println("The Fibonacci Series :\n"); System.out.println("=============== =====\n"); System.out.println("0\n1"); for (x=0,y=1 ; y<1000 ; x=z) { z=y; y=x+y; System.out.println(y); } } }
75
OUTPUT:
76
class box { double width; double height; double length; } class mybox1 { public static void main( String args[ ] ) { box b1=new box(); b1.width=12; b1.height=10; b1.length=10; double vol1=b1.width*b1.height*b1.length; System.out.println("volume=" + vol1); b1.width=10; b1.height=10; b1.length=10; vol1=b1.width*b1.height*b1.length; System.out.println("volume=" + vol1); } }
77
OUTPUT:
78
import java.io.*; import java.util.*; 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(); this.id = id; this.name = name; this.address=address; count++; } public int getId() { return id; } public String getName() { return name; }
79
} public class Employee1 { public static void main(String[] args) throws Exception { ListEmployee list = new ArrayListEmployee(); list.add(new Employee(1, "A","Delhi")); list.add(new Employee(2, "B","Mumbai")); list.add(new Employee(3, "C","Chennai")); list.add(new Employee(4, "D","Kolkata")); System.out.println(" "); System.out.print("Enter Employee Id: "); Scanner input=new Scanner(System.in); int id = input.nextInt(); for (Employee s : list){ if(id == s.getId()) { System.out.println("Name and Address of employee is: "); System.out.print(s.getName()+" " +s.getAddress()); } } }
80
} OUTPUT: Name and Address of employee is: 1 , A , Delhi 2 , B , Mumbai 3 , C , Chennai 4 , D , Kolkata
81
float sportwt=6.0F; void putwt(); } class result extends test implements sports { float total; public void putwt() { System.out.println("sports wt=" + sportwt); } void display() { total=part1+part2+sportwt; putnumber(); putmarks(); putwt(); System.out.println("Total score=" + total); } } class Multiple1 { public static void main(String args[]) { result r1=new result(); r1.getnumber(10); r1.getmarks(20.5F,30.5F); r1.display(); } }
83
OUTPUT:
84
private double height; private double depth; Box(Box ob) { width=ob.width; height=ob.height; depth=ob.depth; } 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=ob.weight; } 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=ob.color;
86
} 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=c1.volume(); System.out.println("the volume of c1 = " + vol);
87
System.out.println("the c1.weight); System.out.println("the c1.color); vol=c2.volume(); System.out.println("the vol); System.out.println("the c2.weight); System.out.println("the c2.color); } }
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() { System.out.println("Area of figure is undefined"); return 0; } } class Rect extends Figure { Rect(double a,double b) { super(a,b); } double area() { System.out.println("Inside area of rectangle is"); return dim1*dim2; } } class Tri extends Figure { Tri(double a,double b)
89
{ super(a,b); } double area() { System.out.println("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; System.out.println("Area is " + figref.area()); figref=t; System.out.println("Area is " + figref.area()); figref=f; System.out.println("Area is " + figref.area()); } } OUTPUT:
90
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); System.out.println("ob1==ob2" + ob1.equals(ob2)); System.out.println("ob1==ob2" + ob1.equals(ob3)); }
91
} OUTPUT:
92
int l=0; int w=0; try { BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter length of rectangle : "); l = Integer.parseInt(br1.readLine()); System.out.println("Enter width of rectangle : "); w = Integer.parseInt(br1.readLine()); int area = l*w; System.out.println("Area of Rectangle : "+area); } catch(Exception e) { System.out.println("Error : "+e); }
93
} } OUTPUT:
94
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; System.out.println("a & b="+ a + " "+ b); test obj=new test(); obj.method(a,b); System.out.println("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); System.out.println("ob1.a=" + ob1.a); System.out.println("ob1.b=" + ob1.b); } }
96
OUTPUT:
97
import java.io.*; class Complex { int real1,imag1,real2,imag2; void get() throws IOException { BufferedReader Br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("\n Enter the real part of first complex number: "); real1=Integer.parseInt(Br.readLine()); System.out.print(" Enter the imaginary part of first complex number: "); imag1=Integer.parseInt(Br.readLine()); System.out.print("\n Enter the real part of second complex number: "); real2=Integer.parseInt(Br.readLine()); System.out.print(" Enter the imaginary part of second complex number : "); imag2=Integer.parseInt(Br.readLine()); } void display() { System.out.println(" \n Sum of complex numbers " + real1 + "+" + imag1 + "i and " + real2 + "+" + imag2 + "i is " + (real1+real2) + "+" + (imag1+imag2) + "i");
98
} public static void main(String p[]) throws IOException { Complex cmp = new Complex(); cmp.get(); cmp.display(); } } OUTPUT:
private double width; private double height; private double depth; Box(Box ob) { width=ob.width; height=ob.height; depth=ob.depth; } 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; } }
100
class Boxweight extends Box { double weight; Boxweight(Boxweight ob) { super(ob); weight=ob.weight; } 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[]) {
101
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=b1.volume(); System.out.println("volume of b1=" + vol); System.out.println("weight of b1=" + b1.weight); System.out.println(); } } OUTPUT:
static int b; static void method(int x) { System.out.println("x=" + x); System.out.println("a=" + a); System.out.println("b=" + b); } static { System.out.println("static block"); b=a*4; } public static void main(String args[]) { method(40); } } OUTPUT:
int number[]={55,40,80,65,71}; int n; n=number.length; System.out.println("Given list :"); for(int i=0;i<n;i++) { System.out.println(" " + number[i]); } System.out.println("/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; } } } System.out.println("Sorted list"); for(int i=0;i<n;i++) { System.out.println(" " +number[i]); } System.out.println(" "); } }
104
OUTPUT:
{ int size=name.length; 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++) { System.out.println(name[i]); } } } OUTPUT:
106
107
{ public static void main(String args[]) { Vector list=new Vector(); int length=args.length; for(int i=0;i<length;i++) { list.addElement(args[i]); } list.insertElementAt("COBOL",1); int size=list.size(); String listArray[]=new String[size]; list.copyInto(listArray); System.out.println("List of languages"); for(int i=0;i<size;i++) { System.out.println(listArray[i]); } } }
108
OUTPUT:
109
Program to show use of Wrapper class import java.io.*; 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(System.in); System.out.print("Enter principal amount"); System.out.flush(); String principalString=in.readLine(); principalAmount=Float.valueOf(principalStri ng); System.out.print("Enter interest rate"); System.out.flush(); String interestString=in.readLine(); interestRate=Float.valueOf(interestString); System.out.print("Enter number of years"); System.out.flush(); String yearsString=in.readLine(); numYears=Integer.parseInt(yearsString); } catch(IOException e) { System.out.println("I/O Error"); System.exit(1); }
110
float value=loan(principalAmount.floatValue(),intere stRate.floatValue(),numYears); printline(); System.out.println("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++) { System.out.print("="); } System.out.println(" "); } } OUTPUT:
111
112
System.out.println("area of rectangle is " + a1.compute(10,20)); a1=cir; System.out.println("area of circle =" + a1.compute(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}}; System.out.println("Values in array1 by row are"); OutputArray(array1); } public static void OutputArray(int[][] array1) { int sum=0; for(int row=0;row<array1.length;row++) { for( column=0;column<array1[row].length;c olumn++) System.out.print("\t"+"\t" + array1[row] [column]); System.out.println(); } System.out.println(); sum=sum+array1.length; System.out.print("sum=\t"+sum+"\t"); System.out.println(); } }
115
OUTPUT:
116
117
118
OUTPUT:
119
120
package package4; public class Arithmetic { public void arith(){ int a=30,b=20,c; c=a+b; System.out.println("Addition of a & b is " + c); c=a-b; System.out.println("Sub of a & b is " +c); c=a*b; System.out.println("Mul of a & b is " + c); c=a/b; System.out.println("Division of a & b is " + c); } } import package4.Arithmetic; class Packagetest5{ public static void main(String args[]) { Arithmetic a1=new Arithmetic(); a1.arith(); } }
122
OUTPUT:
123
import static java.lang.Math.*; public class Mathop { public void circle(double r) { double area=PI*r*r; System.out.println("The area of circle is " + area); } public static void main(String args[]) { Mathop obj=new Mathop(); obj.circle(2.3); } } OUTPUT: The area of circle is 16.619025137490002
class A extends Thread { public void run() { for(int i=0;i<=5;i++) { System.out.println(" From Thread A :" + i); } System.out.println("exit from A"); } } class B extends Thread { public void run() { for(int i=0;i<=5;i++) { System.out.println(" From Thread B :" + i); } System.out.println("exit from B"); } } class C extends Thread { public void run() { for(int i=0;i<=5;i++) { System.out.println(" From Thread C :" + i); }
126
System.out.println("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
127
{ public void run() { for(int i=1;i<=5;i++) { if(i==1) yield(); System.out.println(" From Thread A :" + i); } System.out.println("exit from A"); } } class B extends Thread { public void run() { for(int j=1;j<=5;j++) { System.out.println(" From Thread B :" + j); if(j==3) stop(); } System.out.println("exit from B"); } } class C extends Thread { public void run() { for(int k=1;k<=5;k++) { System.out.println(" From Thread C :" + k);
128
if(k==1) try { sleep(1000); } catch(Exception e) { } } System.out.println("exit from C"); } } class Threadmethod { public static void main(String args[]) { A threadA=new A(); B threadB=new B(); C threadC=new C(); System.out.println("start thread A"); threadA.start(); System.out.println("start thread B"); threadB.start(); System.out.println("start thread C"); threadC.start(); System.out.println("End of main thread"); } } OUTPUT:
129
130
System.out.println(" From Thread A :" + i); } System.out.println("exit from A"); } } class B extends Thread { public void run() { for(int j=1;j<=4;j++) { System.out.println(" From Thread B :" + j); } System.out.println("exit from B"); } } class C extends Thread { public void run() { for(int k=0;k<=4;k++) { System.out.println(" From Thread C :" + k); } System.out.println("exit from C"); } } class Threadpriority { public static void main(String args[])
131
{ A threadA=new A(); B threadB=new B(); C threadC=new C(); threadC.setPriority(Thread.MAX_PRIORITY); threadC.setPriority(threadA.getPriority()+1); threadC.setPriority(Thread.MIN_PRIORITY); System.out.println("Start thread A"); threadA.start(); System.out.println("Start thread B"); threadB.start(); System.out.println("Start thread C"); threadC.start(); System.out.println("End of main thread"); } }
132
OUTPUT:
133
class A implements Runnable { public void run() { for(int i=1;i<=10;i++) { System.out.println("/tThreadA : " +i); } System.out.println("End of ThreadA"); } } class Runnabletest { public static void main(String args[]) { A runnable=new A(); Thread threadA=new Thread(runnable); threadA.start(); System.out.println("End of main thread" ); } }
134
OUTPUT:
135
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; Th.start(); } public void run() { try { int j=1; while(++j<20) { synchronized(this) { while(suspend_flag) { wait(); } if(stop_flag) { break;
136
} } } } catch(InterruptedException IE) { System.out.println("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
137
{ sus_res_stop S_R_S_T=new sus_res_stop("SRS"); System.out.println("Thread S_R_S_T is created and started"); Thread.sleep(2000); S_R_S_T.my_suspend(); System.out.println("Thread S_R_S_T is suspended"); Thread.sleep(2000); S_R_S_T.my_resume(); System.out.println("Thread S_R_S_T is resumed"); Thread.sleep(2000); S_R_S_T.my_suspend(); System.out.println("Thread S_R_S_T is suspended"); Thread.sleep(2000); S_R_S_T.my_resume(); System.out.println("Thread S_R_S_T is resumed"); Thread.sleep(2000); S_R_S_T.my_stop(); System.out.println("Thread S_R_S_T is stopped"); } catch(InterruptedException IE) { System.out.println("Generated interrupted exception");
138
} OUTPUT:
} }
139
Program to display compile time error class Error1 { public static void main(String args[]){ System.out.println("Hello Java") } }
OUTPUT:
140
141
142
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<args.length;i++) { try { number=Integer.parseInt(args[i]); } catch(NumberFormatException e) { invalid =invalid +1; System.out.println("invalid number :" + args[i]); continue; } count=count+1; } System.out.println("valid number=" + count); System.out.println("invalid number=" + invalid); } }
143
OUTPUT:
144
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)); System.out.println("the value of z is=" + z); } catch(ArithmeticException e) { System.out.println("division by zero in arithmetic"); } } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Array index is out of bound"); } } }
145
OUTPUT:
146
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) { System.out.println("Division by zero"); } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Array index error"); } catch(ArrayStoreException e) { System.out.println("Wrong data type"); } int y=a[1]/a[0]; System.out.println("y=" + y); } }
147
OUTPUT:
148
import java.lang.Exception; 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) { System.out.println("caught my exception"); System.out.println(e.getMessage()); } finally
149
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) { System.out.println("Caught the exception" + e); } } } OUTPUT:
Applet file <html> <applet code=Hellojava.class width=300 height=300 > </applet> </html> Java file import java.awt.*; import java.applet.*; public class Hellojava extends Applet { public void paint(Graphics g) { String str; str="HELLO JAVA"; System.out.println(str); g.drawString(str,10,100); } }
152
OUTPUT:
153
} OUTPUT:
<applet code=Numvalues.class width=300 height=300> </applet> </html> import java.awt.*; import java.applet.*; public class Numvalues extends Applet { public void paint(Graphics g) { int values1=10; int values2=20; int sum=values1+values2; String s="sum:" +String.valueOf(sum); g.drawString(s,100,100); } } `
156
OUTPUT:
157
s1=text1.getText(); x=Integer.parseInt(s1); s2=text2.getText(); y=Integer.parseInt(s2); } catch(Exception ex) { } z=x+y; s=String.valueOf(z); g.drawString("The Sum is:" ,10,75); } public boolean action (Event event,Object object) { repaint(); return true; } } OUTPUT:
159
import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; public class Setbkgcolor extends Applet { public void paint(Graphics g) { setBackground(Color.red); } } <html> <body> <applet code=Setbkgcolor.class width=200 height=200> </applet> </body> </html
160
OUTPUT:
161
<html> <body> <applet code=Event1.class width=200 height=200> </applet> </body> </html> import java.applet.*; import java.awt.*; import java.awt.event.*; 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) {
162
showStatus("A key on the keyboard is pressed"); } Font f1=new Font("courier new",Font.BOLD,20); public void paint(Graphics GA) { GA.setFont(f1); GA.setColor(Color.blue); GA.drawString("This applet sense the up/down motion of keys",20,120); } } OUTPUT:
163
Program to demonstrate Labels <html> <body> <applet code=Labeldemo.class width=200 height=300> </applet> </body> </html> import java.awt.*; import java.applet.*; 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); } }
164
OUTPUT:
165
Program to demonstrate buttons in an applet <html> <body> <applet code=Buttondemo.class width=200 height=300> </applet> </body> </html> import java.awt.*; import java.awt.event.*; import java.applet.*; 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); yes.addActionListener(this); no.addActionListener(this); maybe.addActionListener(this); }
166
public void actionPerformed(ActionEvent ae) { String str=ae.getActionCommand(); if(str.equals("Yes")) { msg="u pressed Yes"; } else if(str.equals("No")) { msg="U pressed No"; } else { msg="u pressed Undecided"; } repaint(); } public void paint(Graphics g) { g.drawString(msg,6,100); } }
167
OUTPUT:
168
Program to perform arithmetic operations in buttons <html> <body> <applet code=Buttonarith.class width=200 height=200> </applet> </body> </html import java.awt.*; import java.awt.event.*; import java.applet.*; 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); add.addActionListener(this); sub.addActionListener(this); divide.addActionListener(this); }
169
public void actionPerformed(ActionEvent ae) { String str=ae.getActionCommand(); int a=10,b=10,c; if(str.equals("add")) { c=a+b; System.out.println("the additio is" + c); } else if(str.equals("sub")) { c=a*b; msg="the sub is"; } else { c=a/b; msg="the divide is "; } repaint(); } public void paint(Graphics g) { g.drawString(msg,6,100); } }
170
OUTPUT:
171
winNT.addItemListener(this); solaris.addItemListener(this); mac.addItemListener(this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) { msg="Current state:"; g.drawString(msg,6,80); msg="Windows 98: " + Win98.getState(); g.drawString(msg,6,100); msg="Windows NT: " + winNT.getState(); g.drawString(msg,6,120); msg="Solaris: " + solaris.getState(); g.drawString(msg,6,140); msg="MacOS: " + mac.getState(); g.drawString(msg,6,160); } }
173
OUTPUT:
174
<html> <body> <applet code =Checkboxgroup.class width=200 height=300> </applet> </body> </html> import java.awt.*; import java.awt.event.*; import java.applet.*; 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);
175
add(solaris); add(mac); Win98.addItemListener(this); winNT.addItemListener(this); solaris.addItemListener(this); mac.addItemListener(this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) { msg="Current selection:"; msg += cbg.getSelectedCheckbox().getLabel(); g.drawString(msg,6,100); } }
176
OUTPUT:
177
browser.add("Internet Explorer 3.0"); browser.add("Internet Explorer 4.0"); browser.add("Lynx 2.4"); browser.select("Netscape 4.x"); add(os); add(browser); os.addItemListener(this); browser.addItemListener(this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint (Graphics g) { msg = "Current OS: "; msg += os.getSelectedItem(); g.drawString(msg, 6, 120); msg = "Current Browser: "; msg += browser.getSelectedItem(); g.drawString(msg, 6, 140); } }
179
OUTPUT:
180
<html> <body> <applet code=ListDemo.class width=200 height=300> </applet> </body> </html> import java.awt.*; import java.awt.event.*; import java.applet.*; 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); os.add("Windows 98"); os.add("Windows NT"); os.add("Solaris"); os.add("MacOS"); browser.add("Netscape 1.1"); browser.add("Netscape 2.x"); browser.add("Netscape 3.x"); browser.add("Netscape 4.x"); browser.add("Internet Explorer 2.0");
181
browser.add("Internet Explorer 3.0"); browser.add("Internet Explorer 4.0"); browser.add("Lynx 2.4"); browser.select(1); add(os); add(browser); os.addActionListener(this); browser.addActionListener(this); } public void actionPerformed(ActionEvent ae) { repaint(); } public void paint (Graphics g) { msg = "Current OS: "; msg += os.getSelectedIndexes(); g.drawString(msg, 6, 120); msg = "Current Browser: "; msg += browser.getSelectedItem(); g.drawString(msg, 6, 140); } }
182
OUTPUT:
183
<html> <body> <applet code=SBdemo.class width=200 height=300> </applet </body> </html> import java.awt.*; import java.awt.event.*; import java.applet.*; public class SBdemo extends Applet implements AdjustmentListener,MouseMotionListener { String msg=""; Scrollbar vertSB,horzSB; public void init() { int width=Integer.parseInt(getParameter("width")) ; int height=Integer.parseInt(getParameter("height" )); vertSB = new Scrollbar(Scrollbar.VERTICAL,0,1,0,height); horzSB = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,width); add(vertSB);
184
add(horzSB); vertSB.addAdjustmentListener(this); horzSB.addAdjustmentListener(this); addMouseMotionListener(this); } public void adjustmentValueChanged(AdjustmentEvent ae) { repaint(); } public void mouseDragged(MouseEvent me) { int x=me.getX(); int y=me.getY(); vertSB.setValue(y); horzSB.setValue(x); repaint(); } public void mouseMoved(MouseEvent me) { } public void paint(Graphics g){ msg="Vertical:"+ vertSB.getValue(); msg+="Horizontal:" + horzSB.getValue(); g.drawString(msg,6,160); g.drawString("*",horzSB.getValue(),vertSB.g etValue()); } }
185
OUTPUT:
186
<html> <body> <applet code=Flowlayoutdemo.class width=200 height=300> </applet> </body> </html> import java.awt.*; import java.awt.event.*; import java.applet.*; public class Flowlayoutdemo extends Applet implements ItemListener { String msg=""; Checkbox Win98,winNT,solaris,mac; public void init() { setLayout(new FlowLayout(FlowLayout.LEFT)); 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);
187
Win98.addItemListener(this); winNT.addItemListener(this); solaris.addItemListener(this); mac.addItemListener(this); } public void itemStateChanged(ItemEvent ie) { repaint(); } public void paint(Graphics g) { msg="Current state:"; g.drawString(msg,6,80); msg="Windows 98: " + Win98.getState(); g.drawString(msg,6,100); msg="Windows NT: " + winNT.getState(); g.drawString(msg,6,120); msg="Solaris: " + solaris.getState(); g.drawString(msg,6,140); msg="MacOS: " + mac.getState(); g.drawString(msg,6,160); } }
188
OUTPUT:
189
<html> <body> <applet code=Graphicmethods.class width=300 height=300> </applet> </body> </html> import java.awt.*; import java.applet.*; public class Graphicmethods extends Applet { String s=new String(); String s1=new String(); String s2=new String(); Font f1=new Font("Courier New ", Font.BOLD,20); public void paint(Graphics GA) { GA.setFont(f1); GA.setColor(Color.blue); GA.drawString("Illustration of methods of graphics class",200,250); Font f2=GA.getFont(); s=f2.toString(); GA.drawString(s,5,540); GA.setColor(Color.green); Color col=GA.getColor(); s2=col.toString();
190
GA.drawString(s2,5,560); GA.fillRect(500,15,70,90); GA.drawRect(160,5,60,60); GA.drawOval(10,120,155,95); GA.setColor(Color.yellow); GA.fillOval(700,140,50,150); GA.setColor(Color.black); GA.drawLine(380,100,200,180); GA.drawArc(400,150,180,280,90,70); int x2[]={200,120,280,240}; int z2=4; int y2[]={260,370,370,270}; GA.setColor(Color.blue); GA.fillPolygon(x2,y2,z2); GA.setColor(Color.red); GA.drawRect(15,15,30,50); FontMetrics f3=GA.getFontMetrics(); s1=f3.toString(); GA.drawString(s1,5,580); GA.setColor(Color.magenta); GA.fillRoundRect(510,400,90,80,20,20); } }
191
OUTPUT:
192
193
OUTPUT:
<body> <applet code=Triangle2.class width=300 height=300> </applet> </body> </html> import java.awt.*; import java.applet.*; public class Triangle2 extends Applet { public void paint(Graphics g) { g.drawLine(200,150,160,300); g.drawLine(200,150,260,300); g.drawLine(160,300,260,300); } }OUTPUT:
<body> <applet code=Star2.class width=300 height=300> </applet> </body> </html> import java.awt.*; import java.applet.*; 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<points.length; i++) g.drawLine(points[i-1].x, points[i-1].y, points[i].x, points[i].y); } } OUTPUT:
196
</applet> </body> </html> import java.awt.*; import java . applet.*; public class ControlLoop extends Applet { public void paint (Graphics g) { for (int i=0; i<=4; i++) { if((i%2)==0) g.drawOval (120, i*60+10, 50, 50); else g.fillOval (120, 1*60+10, 50, 50) ; } } }
198
OUTPUT:
199
import java.io.*; 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 ("city.txt") ; outfile. write (cities) ; outfile.close(); } catch (IOException ioe) { System.out.println (ioe) ; System.exit (-1) ; } } } OUTPUT:
import java.io.*; class ReadBytes { public static void main(String args[]) { FileInputStream infile=null; int b; try { infile=new FileInputStream(args[0]); while((b=infile.read()) != -1) { System.out.println((char) b); } infile.close(); } catch(IOException ioe) { System.out.println(ioe); } } }
201
OUTPUT:
202