Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 1 of 1
INDEX(Advanced Technology+CODE)
Sr. Name of Experiment Document No.
Numbe
r
Learn basics of java language and its HEC/CE/CSE
1 development tools/libraries.
Write a program in java using command line HEC/CE/CSE
2 arguments.
Create an editor screen containing menus, HEC/CE/CSE
3 dialogue boxes using java .
Write a program in java showing exception HEC/CE/CSE
4 handling.
Create an applet with a text field and three HEC/CE/CSE
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
5 field
6 Write a program to find the volume of a box HEC/CE/CSE
Write a multithreaded program to print HEC/CE/CSE
7 “Hello Thread” ten times.
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 2 of 1
AIM : Learn basics of java language and its development tools/libraries
SCOPE
PROCEDURE:
JAVA is first and foremost an object oriented programming [Link]
programmers were surprised when they discovered how easy it is to follow sound
object oriented design practices with [Link] following sections give you a better
understanding of what java offers .
Characteristics of java
Characteristics 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 compiled
Multithreaded
Network-ready and compatible
Object-oriented
Portable
Robust
Secure
Viewing
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali 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=[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;
}
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali 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);
double vol1;
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 5 of 1
vol1=[Link]();
[Link]("volume of mybox1 is"+vol1);
[Link]("volume of mybox1 is"+[Link]);
[Link]();
vol1=[Link]();
[Link]("volume of mybox2 is"+vol1);
[Link]("volume of mybox2 is"+[Link]);
}
}
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 6 of 1
AIM: Program to create an applet with a textfield and three [Link]
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 [Link].*;
import [Link].*;
import [Link].*;
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);
add(c);
[Link](this);
[Link](this);
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 7 of 1
[Link](this);
}
public void actionPerformed(ActionEvent ae)
{
if([Link]()=="one")
[Link]("pressed button one");
else if([Link]()=="two")
[Link]("pressed button two");
}
public void itemStateChanged(ItemEvent ie)
{
if([Link]()==true)
[Link]("u pressed chechbox");
}
}
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali 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=[Link];
[Link](“No. of arguments= “+count);
while(I<count)
{
str=args[i];
i=i+1;
[Link](I+ “argument is “+str);
}
}
}
INPUT
java test One Two Three
OUTPUT
No. of arguments=3
1 argument is One
2 argument is Two
3 argument is Three
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 9 of 1
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)
{
[Link](“Division by zero,illegal operator);
}
[Link](“Hello World”);
}
}
INPUT
OUTPUT
Division by Zero,illegal operation
Hello World
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 10 of 1
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++)
{
[Link](“Hello Thread1”);
}
}
class ExampleThread2 extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
{
[Link](“Hello Thread2”);
}
}
}
public class Example1
{
public Static void main(String args[ ])
{
ExampleThread1 t1=new ExampleThread1();
ExampleThread2 t2=new ExampleThread2();
[Link]();
[Link]();
}
}
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali Garg
Haryana Engineering College
JAGADHRI
Experiment Instructions Issue : 01
Page 11 of 1
INPUT
OUTPUT
HelloThread1
HelloThread2
HelloThread2
HelloThread2
HelloThread2
HelloThread1
HelloThread1
HelloThread1
HelloThread1
HelloThread2
HelloThread2
HelloThread2
HelloThread1
Originated /Reviewed Approved by: Revision Date: Effective
Revision No
By: Date
Ashna Sharma
Priya Aggarwal
Shefali Garg