Upload
shyam-rana
View
1.065
Download
1
Embed Size (px)
Citation preview
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 1 of 1
INDEX(Advanced Technology+CODE)
Sr. Number
Name of Experiment Document No.
1Learn basics of java language and its development tools/libraries.
HEC/CE/CSE
2Write a program in java using command line arguments.
HEC/CE/CSE
3Create an editor screen containing menus, dialogue boxes using java .
HEC/CE/CSE
4Write a program in java showing exception handling.
HEC/CE/CSE
5
Create an applet with a text field and three buttons when you press each button make some different text appear in the text field.
Add a check box to the applet created,capture the event and insert different text into the text field
HEC/CE/CSE
6 Write a program to find the volume of a box HEC/CE/CSE
7Write a multithreaded program to print “Hello Thread” ten times.
HEC/CE/CSE
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 2 of 1
AIM : Learn basics of java language and its development tools/libraries
SCOPEPROCEDURE:
JAVA is first and foremost an object oriented programming language.Many programmers were surprised when they discovered how easy it is to follow sound object oriented design practices with java.The following sections give you a better understanding of what java offers .
Characteristics of javaCharacteristics of java are very easy to understand. Java has advanced object oriented capabilities are they are very powerful.Some of the characteristics are:Architecture-neutral Distributed Interpreted and compiledMultithreaded Network-ready and compatibleObject-oriented PortableRobust SecureViewing
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 3 of 1
AIM:Program to calculate the volume of the box.
class box{ double width; double height; 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;}
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 4 of 1
box(double len){ width=height=depth=len;}
double volume(){ return width*height*depth;}}
class boxweight extends box{ double weight;
boxweight(double w,double h,double d,doublew m){ width=w; height=h; depth=d; weight=m;}
}
class demoboxweight{ public static void main(String args[]){ boxweight mybox1=new boxweight(10,20,15,34.3); boxweight mybox2=new boxweight(2,3,4,0.076);
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 5 of 1
double vol1; vol1=mybox1.volume(); System.out.println("volume of mybox1 is"+vol1); System.out.println("volume of mybox1 is"+mybox.weight); System.out.println();
vol1=mybox2.volume();System.out.println("volume of mybox2 is"+vol1);System.out.println("volume of mybox2 is"+mybox2.weight);}}
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 6 of 1
AIM: Program to create an applet with a textfield and three buttons.When you press each button, make some text appear in the textfield . Add a check box to applet created ,capture the event and insert different text in textfield.
CODING:
import java.awt.*;import java.awt.event.*;import java.applet.*;
public class MyApplet extends Applet implements ActionListener,ItemListener { TextField t; Button b1,b2; checkbox c;
public void init() { t=new TextField(20); b1=new Button("one"); b2=new Button("two"); c=new Checkbox("Check");
add(t); add(b1); add(b2);
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 7 of 1
add(c);
b1.addActionListener(this); b2.addActionListener(this); c.addItemListener(this); }
public void actionPerformed(ActionEvent ae) { if(ae.getActionCommand()=="one")
t.setText("pressed button one");
else if(ae.getActionCommand()=="two")t.setText("pressed button two");
}
public void itemStateChanged(ItemEvent ie) { if(c.getState()==true) t.setText("u pressed chechbox"); }}
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 8 of 1
AIM: Write a program in Java using COMMAND LINE ARGUMENTS
SCOPE
CODING:
class text{ public static void main(String args[ ]) { int count,I=0; String str; count=args.length; System.out.println(“No. of arguments= “+count); while(I<count) { str=args[i]; i=i+1; System.out.println(I+ “argument is “+str); } }}
INPUT
java test One Two Three
OUTPUT
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 9 of 1
No. of arguments=31 argument is One2 argument is Two3 argument is Three
AIM: Write a program in Java using COMMAND LINE ARGUMENTS
SCOPE
CODING:
public class Example2 { public static void main(String args[ ]) { int i=1,j=0,k; try { k=i/j; } catch (ArithmeticException ae) { System.out.println(“Division by zero,illegal operator); } System.out.println(“Hello World”); }}
INPUT
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 10 of 1
OUTPUT
Division by Zero,illegal operationHello World
AIM: Write a multithreaded program in Java to print “Hello Thread2” ten times.
SCOPE
CODING:
class ExampleThread1 extends Thread { public void run() { for (int i=0;i<10;i++) { System.out.println(“Hello Thread1”); } }
class ExampleThread2 extends Thread { public void run() { for(int i=0;i<10;i++) { System.out.println(“Hello Thread2”); } } }
public class Example1
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 11 of 1
{ public Static void main(String args[ ]) { ExampleThread1 t1=new ExampleThread1(); ExampleThread2 t2=new ExampleThread2(); T1.start(); T2.start(); } }
INPUT
OUTPUT
HelloThread1HelloThread2HelloThread2HelloThread2HelloThread2HelloThread1HelloThread1HelloThread1HelloThread1HelloThread2HelloThread2HelloThread2HelloThread1
Originated /Reviewed By:
Approved by: Revision No Revision Date: Effective Date
Ashna SharmaPriya AggarwalShefali Garg