You are on page 1of 11

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 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 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=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 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=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 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 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);
add(c);

b1.addActionListener(this);
b2.addActionListener(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

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 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=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

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)
{
System.out.println(“Division by zero,illegal operator);
}
System.out.println(“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++)
{
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


{
public Static void main(String args[ ])
{
ExampleThread1 t1=new ExampleThread1();
ExampleThread2 t2=new ExampleThread2();
T1.start();
T2.start();
}
}
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

You might also like