You are on page 1of 79

PRACTICAL FILE FOR WEB DEVELOPMENT

Submitted in partial fulfilment of the requirements for the award of the degree of

Bachelor of Technology In Information Technology

HTML

PROGRAM S

Program no. 1. Aim :- WRITE A PROGRAM to create a time table of group in HTML.. CODING :<HTML> <HEAD>

<TITLE> TIME TABLE OF I.T. 6th SEMESTER </TITLE> </HEAD> <BODY BGCOLOR = "PINK"> <CENTER> <TABLE> <TH COLSPAN ="8"> <FONT COLOR= "BLUE"> <FONT SIZE = "14"> <MARQUEE><CENTER> <B>TIME TABLE OF I.T. 6th SEMESTER </B></CENTER> </MARQUEE> <BR> <BR> <TABLE BORDER = "5" CELLPADDING = "5" CELLSPACING ="5" WIDTH ="100%"> <TR> <TD> <B> <CENTER> DAY </CENTER> </B> <TD> <CENTER> <B> 1 <BR> 8:45-9:45 a.m. </BR> </B> <TD> <CENTER> <B> 2 <BR> 9:45-10:45 a.m. </BR> </B> <TD> <CENTER> <B> 3 <BR> 10:45-11:45 a.m. </BR> </B> <TD> <CENTER> <B> 4 <BR> 11:45-12:45 a.m. </BR> </B> <TD> <CENTER> <B> 5 <BR> 12:45-13:30 p.m. </BR> </B> <TD> <CENTER> <B> 6 <BR> 13:30-14:30 p.m. </BR> </B> <TD> <CENTER> <B> 7 <BR> 13:30-14:30 p.m. </BR> </B> </TR> <TR> <TH> <CENTER> MONDAY </CENTER></TH> <TH> <CENTER>WC-3(302) <BR>RV </CENTER></TH> <TH> <CENTER>---- </CENTER></TH> <TH> <CENTER>WBD-3(302)<BR>SM </CENTER></TH> <TH> <CENTER>NPI-L<BR> YK</CENTER> </TH> <TH> <CENTER><STRONG> <ITALIC> L </ITALIC> </STRONG></CENTER> </TH> <TH> <CENTER>WBD-L <BR>SM</CENTER> </TH>

<TH> <CENTER>SE-L<BR> NJ </CENTER></TH> </TR> <TR> <TH> <CENTER>TUESDAY</CENTER> </TH> <TD COLSPAN ="2"> <B><CENTER>WBD-3(LAB 8) <BR>SM</CENTER></B> <TH> <CENTER> ---- </CENTER></TH> <TH> <CENTER>OR-L <BR>GJ </CENTER></TH> <TH> <CENTER><STRONG> <ITALIC> U </ITALIC> </STRONG></CENTER> </TH>

<TH> <CENTER>WC-L <BR>RV</CENTER> </TH> <TH> <CENTER>SE-3 (304) <BR>NJ</CENTER> </TH> </TR> <TR> <TH> <CENTER>WEDNESDAY </CENTER></TH> <TH> <CENTER>OR-L <BR>GS </CENTER></TH> <TH> <CENTER>IS-L <BR>AB </CENTER></TH> <TH> <CENTER>WBD-L <BR>SM</CENTER> </TH> <TH> <CENTER>WC-L <BR>RV </CENTER></TH> <TH> <CENTER><STRONG> <ITALIC> N </ITALIC> </STRONG></CENTER> </TH> <TH> <CENTER>SE-L <BR>X </CENTER></TH> <TH> <CENTER>----</CENTER> </TH> </TR> <TR> <TH> <CENTER>THURSDAY</CENTER> </TH> <TH> <CENTER>IS-L <BR>AB</CENTER> </TH> <TH> <CENTER> WC-L <BR>RV </CENTER></TH> <TD COLSPAN ="2"> <B><CENTER>NPI-3 (LAB 3) <BR>NG </CENTER> </B> <TH> <CENTER><STRONG> <ITALIC> C </ITALIC> </STRONG></CENTER> </TH> <TH> <CENTER>NPI-L <BR>YK</CENTER> </TH> <TH> <CENTER>---- </CENTER></TH> </TR> <TR> <TH> <CENTER>FRIDAY </CENTER></TH> <TH> <CENTER>NPI-L <BR>YK </CENTER></TH> <TD COLSPAN ="3"> <B><CENTER>IS-3(LAB 4) <BR>AB</CENTER></B> <TH> <CENTER><STRONG> <ITALIC> H </ITALIC> </STRONG></CENTER> </TH> <TH> <CENTER> OR-L <BR>GS</CENTER> </TH> <TH> <CENTER> NPI-3(302) <BR>YK</CENTER> </TH>

</TR> <TR> <TH><CENTER> SATURDAY </CENTER></TH> <TH> <CENTER> SE-L <BR>X</CENTER> </TH> <TH> <CENTER>OR-L <BR>SBL</CENTER> </TH> <TH> <CENTER>WBD-L <BR>SM</CENTER> </TH> <TH> <CENTER>IS-L <BR>AB</CENTER> </TH>

<TH> <B>\\\\\ </B></TH> <TH> <CENTER>IS-3 <BR>AB</CENTER> </TH> <TH> <CENTER>----</CENTER> </TH> </TR> </TABLE> </CENTER> </BODY> </HTML>

OUTPUT: -

Program no. 2. Aim :- WRITE A PROGRAM to create style sheet (inline and internal).. CODING :<HTML>

<HEAD> <TITLE> STYLE SHEET </TITLE> <STYLE TYPE = "TEXT/CSS" MEDIA ="SCREEN"> <!-- BODY {COLOR: BLUE} P {TEXT-ALIGN: CENTER; MARGIN-LEFT: 20%; MARGIN-RIGHT: 20%} H1,H2,H3{COLOR: RED} UL{COLOR: GREEN; FONT-WEIGHT: BOLD} --> </STYLE> </HEAD> <BODY> <H1> WELCOME TO THIS PAGE </H1> <P> The above heading is red, since we specified that H1-H3 headings <br> are red. This paragraph is blue, which is the default color <br> for the entire body. <br> </P> <P STYLE = "COLOR:BLACK"> This paragraph has black text, <br> because it overrides the default color. </P> <UL> <LI> This is a bullet list. <LI> It's green and bold. <LI STYLE = "COLOR:RED"> This item is red, overriding the default. <LI> This time is back to normal. </UL> <P> This is another paragraph. <br> It is with the default paragraph style <br> </P> </BODY> </HTML>

Output :-

Program no. 3. Aim :- WRITE A PROGRAM to create an external style sheet... CODING :-

<HTML> <HEAD> <TITLE> EXTERNAL STYLE SHEET </TITLE> <LINK REL = "STYLESHEET" TYPE = "TEXT/CSS" HREF = "STYLE.CSS"> </HEAD> <BODY> <H1> WELCOME TO THIS PAGE </H1> <P> The above heading is red, since we specified that H1-H3 headings <br> are red. This paragraph is blue, which is the default color <br> for the entire body. <br> </P> <P > This paragraph has black text, <br> because it overrides the default color. </P> <UL> <LI> This is a bullet list. <LI> It's green and bold. <LI STYLE = "COLOR:RED"> This item is red, overriding the default. <LI> This time is back to normal. </UL> <P ID = "FIRST"> This is another paragraph. <br> It is with the default paragraph style <br> </P> </BODY> </HTML>

Style.css coding :BODY {COLOR: BLUE} P {TEXT-ALIGN: CENTER; MARGIN-LEFT: 20%;

MARGIN-RIGHT: 20%} H1,H2,H3{COLOR: RED} UL{COLOR: GREEN; FONT-WEIGHT: BOLD; TEXT-ALIGN: CENTER} #FIRST{BACKGROUND-COLOR: YELLOW; BORDER-STYLE: DOUBLE,MEDIUM; BORDER-WIDTH: THIN,MEDIUM,THICK,0.25CM; MARGIN: 10PX}

Output :-

JAVASCRIP T PROGRAMS

Program no. 1. Aim :- WRITE A PROGRAM to print a message...

CODING :<HTML> <HEAD> <TITLE> JAVASCRIPT </TITLE> </HEAD> <BODY> <script language = "javascript"> document.write("HELLO FRIENDS! HOW ARE YOU???????"); var a = "HELLO! HOW ARE YOU?????????"; alert(a); </SCRIPT> </BODY> </HTML>

Output :-

Program no. 2. Aim :- WRITE A PROGRAM to show the demo of dialog boxes... CODING :-

<HTML> <HEAD> <TITLE> DIALOG BOXES </TITLE> </HEAD> <BODY> <H1> ALERTS, CONFIRMATIONS, AND PROMPTS </H1> <HR> USE THE BUTTONS BELOW TO TEST DIALOGS IN JAVASCRIPT. <HR> <FORM NAME = "WINFORM"> <P> <INPUT TYPE = "BUTTON" VALUE = "DISPLAY AN ALERT" onClick = "window.alert('This is a test alert.');"> </P> <P> <INPUT TYPE = "BUTTON" VALUE = "DISPLAY A CONFIRMATION" onClick = "window.confirm('Would you like to confirm?');"> </P> <P> <INPUT TYPE = "BUTTON" VALUE = "DISPLAY A PROMPT" onClick = "window.prompt('Enter some text:','This is the default value');"> </P> </FORM> <BR> HAVE A FUN!!!!!!!!!! <HR> </BODY> </HTML>

Output :-

Program no. 3. Aim :- WRITE A PROGRAM to show the GREETING MESSAGE ACCORDING TO THE TIME. CODING :<HTML> <HEAD> <TITLE> DATE AND TIME </TITLE> </HEAD> <BODY> <script language="JavaScript"> var day = new Date(); var hr = day.getHours(); if (hr <= 11) { alert("Good Morning!!!!!!!!!!!!"); } else if (hr > 11 && hr < 17) { alert("Good Afternoon!!!!!!!!!!!!!!"); } else { alert("Good Evening!!!!!!!!!!!"); } </script> </BODY> </HTML>

Output :-

Program no. 4.

Aim :- WRITE A PROGRAM to show the image roll over... CODING :<HTML> <HEAD> <TITLE> IMAGE ROLLOVER </TITLE> <script language="javascript"> function bigImg(x) { x.style.height="400"; x.style.width="350"; } function normalImg(x) { x.style.height="250"; x.style.width="150"; } </script> </HEAD> <BODY> <CENTER> <img onmouseover="bigImg(this)" onmouseout="normalImg(this)" border="0" src="C:\Users\Shiwani\Pictures\YouPaint\Save\sample01.png" alt="Smiley" width="150" height="250" /> </CENTER> <P>The function bigImg() is triggered when the user moves the mouse pointer over the image. This function enlarges the image.</P> <P>The function normalImg() is triggered when the mouse pointer is moved out of the image. That function changes the height and width of the image back to normal.</P> </BODY> </HTML>

Output :-

Program no. 5.

Aim :- WRITE A PROGRAM OF bubble sort. CODING :<HTML> <HEAD> <TITLE> BUUBLE SORT </TITLE> <BODY> <script language="javascript"> var array = new Array(); array[0] = 3; array[1] = 2; array[2] = 10; array[3] = 5; for(i=0;i<=3;i++) { if(array[i]>array[i+1]) { var temp = array[i]; array[i] = array[i+1]; array[i+1] = temp; } } for(i=0;i<=3;i++) { document.write(array[i]); document.write("\n"); } </script> </BODY> </HTML>

</HEAD>

Output :-

Program no. 6.(I) Aim :- WRITE A PROGRAM OF FORM PROCESSING. CODING :-

<HTML> <HEAD> <TITLE> FORM VERIFIVCATION </TITLE> <script language="javascript"> function ver (form1) { var v=form1.elements.length; if(form1.elements[3].name="button1") { alert("FIRST FORM NAME IS :-" + form1.name); alert("NO. OF ELEMENTS IN FORM1 IS :-" + document.form[0].name + "-" + v); } else if(form1.elements[4].name="button2") { alert("second FORM NAME IS :-" + form2.name); alert("NO. OF ELEMENTS IN FORM2 IS :-" + document.form[1].name + "-" + v); } for(i=0;i<v;i++) { alert(form1.elements[i].name + "is at position" + i); }} </script> </HEAD> <BODY> <FORM NAME="SURVEY FORM1"> FIRST NAME : <INPUT TYPE = "TEXTBOX" NAME = "TEXT1"> <BR/> <INPUT TYPE = "RADIO" NAME = "RADIO1" VALUE = "FRESHER"> FRESHER <BR/> <INPUT TYPE = "RADIO" NAME = "RADIO2" VALUE = "FRESHER"> EXPERIENCED <BR/> <INPUT TYPE = "BUTTON" NAME = "BUTTON1" VALUE = "CLICK1"> <BR/> <FORM NAME="SURVEY FORM2"> NAME : <INPUT TYPE = "TEXTBOX" NAME = "TEXT2"> <BR/> PASSWORD : <INPUT TYPE = "TEXTBOX" NAME = "TEXT3"> <BR/> <INPUT TYPE = "CHECKBOX" NAME = "CHECK1" VALUE = "EMPLOYED"> EMPLOYED<BR/> <INPUT TYPE = "CHECKBOX" NAME = "CHECK2" VALUE = "STUDYING"> STUDYING <BR/> <INPUT TYPE = "BUTTON" NAME = "BUTTON1" VALUE = "CLICK2"> <BR/> </BODY> </HTML>

OUTPUT :-

Program no. 6.(II) Aim :- WRITE A PROGRAM OF FORM PROCESSING. CODING :-

<HTML> <HEAD> <TITLE> FORM PROCESSING </TITLE> <script language = "javascript"> function compute(f) { if(confirm("ARE YOU SURE???")) f.result.value = eval(f.expr.value); else alert("PLEASE COME BACK AGAIN") } </script> </HEAD> <BODY> <FORM> ENTER AN EXPRESSION <INPUT TYPE = "TEXT" NAME = "EXPR" SIZE = "15"> <INPUT TYPE = "BUTTON" VALUE = "CALCULATE" onClick = "compute(this.form)"> <br> <result.inputtype = "text" name = "RESULT" SIZE = "15"> </FORM> </BODY> </HTML>

OUTPUT :-

Program no. 7. Aim :- WRITE A PROGRAM OF DATA OBJECT MODEL. CODING :<HTML>

<HEAD> <TITLE> DOCUMENT OBJECT MODEL </TITLE> </HEAD> <BODY> <script language="javascript"> document.write("Hello World!"); </script> <BR> Cookies associated with this document: <script language="javascript"> document.write(document.cookie); </SCRIPT> <BR> This document was last modified on: <script language="javascript"> document.write(document.lastModified); </script> <BR> The title of the document is: <script language="javascript"> document.write(document.title); </script> <BR> The full URL of this document is: <script language="javascript"> document.write(document.URL); </script> <BR> <form name="Form1"></form> <form name="Form2"></form> <form> </form> <p>Number of forms: <script language="javascript"> document.write(document.forms.length); </script> </p> <script language="javascript"> function getElements() { var x=document.getElementsByName("x"); alert(x.length); } </script> <br>

<body> Cats: <input name="x" type="radio" value="Cats" /> <br> Dogs: <input name="x" type="radio" value="Dogs" /> <br>

<input type="button" onclick="getElements()" value="How many elements named 'x'?" /> <br><br><br> <script language="javascript"> document.write("Number of URLs in history list: " + history.length); <br> </script> <script language="javascript"> function goBack() { window.history.back() } </script> <br> <body> <input type="button" value="Back" onclick="goBack()" /><br> <p>Notice that clicking on the Back button here will not result in any action, because there is no previous URL in the history list.</p><br> <script language="javascript"> function goForward() { window.history.forward() } </script><br> <body> <input type="button" value="Forward" onclick="goForward()" /><br> <p>Notice that clicking on the Forward button here will not result in any action, because there is no next URL in the history list.</p><br> <script language="javascript"> function goBack() { window.history.go(-2) } </script><br> <body> <input type="button" value="Go 2 pages back" onclick="goBack()" /><br> <p>Notice that clicking on the "Go 2 pages back" button here will not result in any action, because there is no previous URL in the history list.</p><br> HOST IS :-

<script language="javascript"> document.write(location.host); </script><br> HREF IS :-

<script language="javascript"> document.write(location.href); </script><br> PATH IS :<script language="javascript"> document.write(location.pathname); </script><br> PROTOCOL IS :<script language="javascript"> document.write(location.protocol); </script><br> <script language="javascript"> function reloadPage() { window.location.reload() } </script><br> <body> <input type="button" value="Reload page" onclick="reloadPage()" /> </BODY> </HTML>

OUTPUT :-

Program no. 8. Aim :- WRITE A PROGRAM for cookies. CODING :-

<HTML> <HEAD> <script language="javascript"> function getCookie(cookieName) { var data = document.cookie; var whole = data.split(";") var nams,dats,bool = false; var parts = new Array(); for(var i=0;i<whole.length;i++) { parts[i]=whole[i].split("="); } for(i=0;i<parts.length;i++) { if(parts[i][0].indexOf(cookieName)!=-1) { alert(parts[i][1]); bool = true; }; } if(!bool) alert("SORRY"); } </script> <TITLE>JAVASCRIPT COOKIES</TITLE> </HEAD> <BODY> <script language="javascript"> var somedate = new Date() somedate.setTime(somedate.getTime() +( 365*24*60*60*1000)) document.cookie = "userid = aakash;" document.cookie = "pass = lemmein; domain = www.ibm.com; expires =" +somedate.toGMTString() </script>

<H1> JAVASCRIPT COOKIES </H1> <HR> <FORM> <P>

<B> ENTER THE NAME OFTHE COOKIE </B> <INPUT TYPE = "TEXT" NAME = "cookname" SIZE = "20"> </P> <P> <INPUT TYPE= "BUTTON" VALUE = "CLICK HERE TO RETRIEVE THE VALUE OF COOKIE" onClick = "getCookie(document.forms[0].cookname.value)" name = "B1"> </P> </FORM> <P> &nbsp; </P> </BODY> </HTML>

OUTPUT:-

Program no. 9. Aim :- WRITE A PROGRAM OF EVENT HANDLING. CODING :<HTML> <HEAD> <TITLE> EVENT HANDLING </TITLE>

</HEAD> <BODY> <H3>Example of onAbort Event Handler</H3> <B>Stop the loading of this image and see what happens:</B><P> <IMG SRC="C:\Users\Public\Pictures\Sample Pictures\Desert.JPG" onAbort="alert('You stopped the loading the image!')"> <SCRIPT> function validate(value) { if (value < 0) alert("Please input a value that is greater or equal to 0"); } </SCRIPT> <H3> Example of onBlur Event Handler</H3> Try inputting a value less than zero:<BR> <FORM> <INPUT TYPE="text" onBlur="validate(this.value)"> </FORM> <SCRIPT> function valid(input) { alert("You have changed the value from 10 to " + input); } </SCRIPT> <H3>Example of onChange Event Handler</H3> Try changing the value from 10 to something else:<BR> <FORM> <INPUT TYPE="text" VALUE="10" onChange="valid(this.value)"> </FORM> <SCRIPT> function valid(form) { var input = form.data.value; alert("Hello " + input + " ! Welcome..."); } </SCRIPT> <H3> Example of onClick Event Handler </H3> Click on the button after inputting your name into the text box:<BR> <FORM> <INPUT TYPE="text" NAME="data"> <INPUT TYPE="button" VALUE="Click Here" onClick="valid(this.form)"> </FORM> <SCRIPT> function hello() { alert("Hello there...\n\nThis is an example of onLoad."); } </SCRIPT> <BODY onLoad="hello()"> <H3>Example of onLoad Event Handler</H3> <BODY>

<H3> Example of onMouseOut Event Handler </H3> Put your mouse over <A HREF="javascript:void('');" onMouseOut="window.status='You left the link!'; return true;"> here </A> and then take the mouse pointer away. <H3>Example of onMouseOver Event Handler</H3> Put your mouse over <A HREF="javascript:void('');" onMouseOver="window.status='Hello! How are you?'; return true;"> here </A> and look at the status bar (usually at the bottom of your browser window). <H3> Example of onReset Event Handler </H3> Please type something in the text box and press the reset button:<BR> <FORM onReset="alert('This will reset the form!')"> <INPUT TYPE="text"> <INPUT TYPE="reset" VALUE="Reset Form" > </FORM> <SCRIPT> function goodbye() { alert("Thanks for Visiting!"); } </SCRIPT> <BODY onUnLoad="goodbye();"> <H3>Example of onUnload Event Handler</H3> Look what happens when you try to leave this page... <script language="javascript"> function copyText() { document.getElementById("field2").value=document.getElementById("field1").value; } </script> Field1: <input type="text" id="field1" value="Hello World!" /><br /> Field2: <input type="text" id="field2" /> <br /><br /> <button ondblclick="copyText()">Copy Text</button> <p>A function is triggered when the button is double-clicked. The function copies the text in Field1 to Field2.</p> <script language="javascript"> function imgError() { alert('The image could not be loaded.'); }

</script> <img src="C:\Users\Public\Pictures\Sample Pictures\Desert.JPG" onerror="imgError()" /> <p>A function is triggered if an error occurs when loading the image. The function shows an alert box with a text. In this example we refer to an image that does not exist, therefore the onerror event occurs.</p> <script language="javascript"> function mouseDown() { document.getElementById("p1").style.color="red"; } function mouseUp() { document.getElementById("p1").style.color="green"; } </script> </head> <body> <p id="p1" onmousedown="mouseDown()" onmouseup="mouseUp()">Click the text! The mouseDown() function is triggered when the mouse button is pressed down over this paragraph. The function sets the color of the text to red. The mouseUp() function is triggered when the mouse button is released. That function sets the color of the text to green.</p> </BODY> </HTML>

OUTPUT :-

JAVA PROGRAM S

Program no. 1. Aim :- WRITE A PROGRAM to print a message... CODING :class Demo { public static void main(String a[]) { System.out.println("Hello, World of JAVA"); } }

OUTPUT: -

Program no. 2. Aim :- WRITE A PROGRAM to print a series...

CODING :class Displaying { public static void main(String args[]) { System.out.println("SCREEN DISPLAY"); for (int i = 1 ; i <= 9 ; i++ ) { for ( int j = 1 ; j <= i ; j++ ) { System.out.print(" "); System.out.print(i); } System.out.println("\n"); } System.out.println("SCREEN DISPLAY DONE"); } }

Output :-

Program no. 3. Aim :- WRITE A PROGRAM to print the floyds triangle series. CODING :-

class FloydTriangle { public static void main(String args[]) { System.out.println("SCREEN DISPLAY"); System.out.println("Floyd's triangle :-"); int counter = 1; for (int i = 1 ; i <= 10 ; i++ ) { for ( int j = 1 ; j <= i ; j++ ) { System.out.print(counter); counter = counter+1; System.out.print(" "); } System.out.println("\n"); } System.out.println("SCREEN DISPLAY DONE"); } }

Output :-

Program no. 4. Aim :- WRITE A PROGRAM to create a class... CODING :-

class Rectangle { int length, width; void getData(int x, int y) { length = x; width = y; } int rectArea() { int area = length*width; return(area); }} class RectArea { public static void main(String args[]) { int area1, area2; Rectangle rect1 = new Rectangle(); Rectangle rect2 = new Rectangle(); rect1.length = 15; rect1.width = 20; area1 = rect1.length*rect1.width; rect2.getData(20,12); area2 = rect2.rectArea(); System.out.println("AREA1 =" + area1); System.out.println("AREA2 =" + area2); }}

Output :-

Program no. 5. Aim :- WRITE A PROGRAM to create an array... CODING :-

class Array { public static void main(String args[]) { int month_days[]; month_days = new int[12]; month_days[0] = 31; month_days[1] = 28; month_days[2] = 31; month_days[3] = 30; month_days[4] = 31; month_days[5] = 30; month_days[6] = 31; month_days[7] = 31; month_days[8] = 30; month_days[9] = 31; month_days[10] = 30; month_days[11] = 31; System.out.println("AUGUST has" + month_days[7] + "days."); System.out.println("DECEMBER has" + month_days[11] + "days."); System.out.println("MARCH has" + month_days[2] + "days."); System.out.println("MAY has" + month_days[4] + "days."); System.out.println("JULY has" + month_days[6] + "days."); }}

Output :-

Program no. 6. Aim :- WRITE A PROGRAM to show the concept of inheritance... CODING :class Room { int length;

int breadth; Room(int x, int y) { length = x; width = y; } int area() { return(length*breadth); } } class BedRoom extends Room { int height; BedRoom(int x, int y, int z) { super(x,y); height = z; } int volume() { return(length*bredath*height); } } class InherTest { public static void main(String args[]) { BedRoom room1 = new BedRoom(14,12,10); int area1 = room1.area(); int volume1 = room.volume(); System.out.println("AREA1 = " + area1); System.out.println("VOLUME1 = " + volume1); } }

Output :-

Program no. 7. Aim :- WRITE A PROGRAM to show the concept of interface... CODING :interface Area { final static float pi = 3.14F;

float compute (float x, float y); } class Rectangle implements Area { public float compute(float x, float y) { return(x*y); } } class Circle implements Area { public float compute(float x, float y) { return(pi*x*x); } } class Interfacetest { public static void main(String args[]) { Rectangle rect = new Rectangle(); Circle cir = new Circle(); Area area; area = rect; System.out.println("Area of Rectangle" + area.compute(10,20)); area = cir; System.out.println("Area of Circle" + area.compute(10,0)); } }

Output :-

Program no. 8. Aim :- WRITE A PROGRAM to show the concept of multiplte inheritance... CODING :class Student

{ int rollNumber; void getNumber(int n) { rollNumber = n; } void putNumber() { System.out.println("ROLL NO.:" + rollNumber); }} class Test extends Student { float part1, part2; void getMarks(float m1, float m2) { part1 = m1; part2 = m2; } void putMarks() { System.out.println("MARKS OBTAINED"); System.out.println("PART1 = " + part1); System.out.println("PART2 = " + part2); }} interface Sports { float sportWt = 6.0F; void putWt(); } class Results extends Test implements Sports { float total; public void putWt() { total = part1 + part2 + sportWt;

putNumber(); putMarks(); putWt(); System.out.println("TOTAL SCORE = " + total); }} class Hybrid

{ public static void main(String args[]) { Results student1 = new Results(); student1.getNumber(1234); student1.getMarks(27.5F, 33.0F); student1.putMarks(); }}

Output :-

Program no. 9. Aim :- WRITE A PROGRAM to show the concept of package... Coding :package MyPack;

class Balance { String name; double bal; Balance(String n, double b) { name = n; bal = b; } void show() { if(bal<0) System.out.print("--> "); System.out.println(name + ": $" + bal); } } class AccountBalance { public static void main(String args[]) { Balance current[] = new Balance[3]; current[0] = new Balance("K. J. Fielding", 123.23); current[1] = new Balance("Will Tell", 157.02); current[2] = new Balance("Tom Jackson", -12.33); for(int i=0; i<3; i++) current[i].show(); } }

Output :-

Program no. 10. Aim :- WRITE A PROGRAM to show the concept of threads...

Coding :class A extends Thread { public void run() { for(int i=1;i<=5;i++) { System.out.println("\t From Thread A : i = "+i);

} System.out.println("Exit from A"); } } class B extends Thread { public void run() { for(int j=1;j<=5;j++) { System.out.println("\t From Thread B : j = "+j); } System.out.println("Exit from B"); } } class C extends Thread { public void run() { for(int k=1;k<=5;k++) { System.out.println("\t From Thread C : k = "+k); } System.out.println("Exit from C"); } } class ThreadTest { public static void main(String a[]) { new A().start(); new B().start(); new C().start(); } }

Output :-

Program no. 11. Aim :- WRITE A PROGRAM to show the concept of threads(ii)... CODING :class X implements Runnable { public void run()

{ for(int i=1; i<=10; i++ ) { System.out.println(" \t Thread X:" + i); } System.out.println("End of Thread X"); }} class RunnableTest { public static void main(String a[]) { X runnable = new X(); Thread t1 = new Thread(runnable); t1.start(); System.out.println("End of Main"); }}

Output :-

Program no. 12. Aim :- WRITE A PROGRAM to show the concept of exception handling. CODING :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 { System.out.println("I am always here"); } } }

Output :-

Program no. 13. Aim :- WRITE A PROGRAM to show the concept of applets... CODING :import java.awt.*; import java.applet.*; public class HelloJavaParam extends Applet {

String str; public void init() { str = getParameter("string"); if(str == null) str = "Java"; str = "Hello" + str; } public void paint(Graphics g) { g.drawString(str, 10, 100); } }

Html file coding :<HTML> <! Parameterized HTML file> <HEAD> <TITLE> welcome to java aopplets </TITLE> </HEAD> <BODY> <APPLET CODE = HelloJavaParam.class WIDTH = 400 HEIGHT = 200> <PARAM NAME = "string" VALUE = "Applet!"> </APPLET> </BODY> </HTML>

OUTPUT :-

Program no. 14. Aim :-write a program for reading the characters from the console. Coding :import java.io.*; class BRRead

{ public static void main(String args[]) throws IOException { char c; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter characters, 'q' to quit."); do { c = (char) br.read(); System.out.println(c); } while(c != 'q'); } }

Output :-

Program no. 15. Aim :-write a program for using a PrintWriter to handle the console output. Coding :import java.io.*; public class PrintWriterDemo { public static void main(String args[]) { PrintWriter pw = new PrintWriter(System.out, true);

pw.println("This is a string"); int i = -7; pw.println(i); double d = 4.5e-7; pw.println(d); } }

Output :-

Program no. 16. Aim :-write a program to show the concept of synchronisation. Coding :class Callme { void call(String msg)

{ System.out.print("[" + msg); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("Interrupted"); } System.out.println("]"); } } class Caller implements Runnable { String msg; Callme target; Thread t; public Caller(Callme targ, String s) { target = targ; msg = s; t = new Thread(this); t.start(); } public void run() { synchronized(target) { target.call(msg); }}}

class Synch1 { public static void main(String args[]) { Callme target = new Callme(); Caller ob1 = new Caller(target, "Hello"); Caller ob2 = new Caller(target, "Synchronized"); Caller ob3 = new Caller(target, "World");

try { ob1.t.join(); ob2.t.join(); ob3.t.join(); } catch(InterruptedException e) { System.out.println("Interrupted"); } } }

Output :-

Program no. 18. Aim :-write a program for xml. Coding :<?xml version="1.0"?> <hce> <b.tech.> <branch> IT,CSE,ECE,EE,ME,CE</branch> </b.tech.>

<m.tech.> <branch> CSE,ECE</branch> </m.tech.> </hce>

Output :-

Program no. 17. Aim :-write a program to show the concept of generic programs. Coding :class Gen<T> {

T ob; Gen(T o) { ob = o; } T getob() { return ob; } void showType() { System.out.println("Type of T is" + ob.getClass().getName()); } } class GenDemo { public static void main(String args[]) { Gen<Integer> iob; iob = new Gen<Integer>(88); iob.showType(); int v = iob.getob(); System.out.println("value: " + v); System.out.println(); Gen<String> strob = new Gen<String>("Generics Test"); strob.showType(); String str = strob.getob(); System.out.println("value: " + str); } }

Output :-