Академический Документы
Профессиональный Документы
Культура Документы
E 6th SEM
D952408
PRACTICAL FILE
OF
JAVA
SUBMITTED BY:-
Mr. Rajnish
(LECT. OF JAVA)
GGPC
Page 1
D952408
INDEX
S.NO.
PRACTICALS
NAME
DATE
TEACHERS
SIGN.
01
02
03(A)
(B)
04
05
06
07
GGPC
Page 2
D952408
08
09
10
GGPC
Page 3
D952408
PRACTICAL NO 01
Objective: - How to install & config. the Java.
To install java we need perform the following steps:
1. Double click the .exe file to initiate the installation procedure. The welcome
screen appears, shown in fig.
2. The welcome screen shows the licensing terms and conditions. Click the accept
button to being Java installation. The progress screen appears, as shown in fig.
GGPC
Page 4
D952408
3. The progress screen depicts the percentage of installation that has been
completed. The complete screen appears as shown below:
GGPC
Page 5
D952408
4. The complete screen depicts the successful installation of Java on the computer
system. Click the Finish button to end the installation process.
Configuring Java:Once Java is installed, we need to configure it. To configure Java we need to
perform the following steps:1. Right click on the My Computer icon and select the properties option. The system
properties dialog box appears as shown below:2. Select the Advanced tab to display the Advanced tab page, as shown below:3. Click the environment variables button to display the environment variables
dialog box as shown below:4. The Environment Variables dialog box is divides into two sectors- User variables
and system variables. Under system variables sector select the path option below
the variable column and click the Edit button. The Edit System Variable dialog
box appears as shown below:5. By default, the Path Variableis already set to multiple locations. To set the Java
directory path to the Path Variable, append the directory path in the Variable
value text box, separated by a semi-colon, as shown below:6. Click OK to close the Edit System Variable dialog box.
7. Click OKto close the Environment Variable dialog box.
8. Click OK to close System Properties dialog box and complete the process of
configuring Java.
GGPC
Page 6
D952408
PRACTICAL NO 02
Objective: - To print HELLO word?
Coding:class hello
{
public static void main (String args[])
{
System.out.println("HELLO");
}
}
Output:-
GGPC
Page 7
D952408
PRACTICAL NO 03 (A)
Objective: - WAP to print 20 numbers on the screen using FOR loop.
Coding:class numbers
{
public static void main(String args[])
{
for(int i=0;i<=20;i++)
{
System.out.println("numbers is " +i);
}
}
}
Output:-
GGPC
Page 8
D952408
PRACTICAL NO 03 (B)
Objective: - WAP to print 20 numbers on the screen using WHILE
loop.
Coding:class number
{
public static void main(String args[])
{
int i=0;
while(i<=20)
{
System.out.println("numbers is " +i);
si++;
}
}
}
Output:-
GGPC
Page 9
D952408
PRACTICAL NO 04
Objective: - WAP to reverse a number in JAVA.
Coding:class rev
{
public static void main(String args[])
{
int a=32;
int b=a/10;
int c=a%10;
System.out.print(c);
System.out.print(b);
}
}
Output:-
GGPC
Page 10
D952408
PRACTICAL NO 05
Objective: - WAP how to declare a object in java.
Coding:class box
{
double width,height,depth;
}
class boxdemo
{
public static void main(String args[])
{
box mybox=new box();
double volume;
mybox.width=10;
mybox.height=20;
mybox.depth=30;
volume=mybox.width*mybox.height*mybox.depth;
System.out.println("vol of the box is " +volume);
}
}
Output:-
GGPC
Page 11
D952408
PRACTICAL NO 06
Objective: - WAP to implement single inheritance in java.
Coding:class room
{
int length, breadth;
room(int x, int y)
{
length=x;
breadth=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*breadth*height);
}
}
class inheritance
{
public static void main(String args[])
{
bedroom room1=new bedroom(30,40,50);
int area1=room1.area();
int vol1=room1.volume();
System.out.println("area1= " +area1);
System.out.println("vol1= " +vol1);
}
}
GGPC
Page 12
D952408
Output:-
GGPC
Page 13
D952408
PRACTICAL NO 07
Objective: - WAP to make a constructor function in java.
Coding:class abc
{
int a,b;
abc(int x, int y)
{
a=x;
b=y;
}
int mul()
{
return(a*b);
}
}
class constructor
{
public static void main(String args[])
{
abc d=new abc(10,20);
int mul=d.mul();
System.out.println("mul= " +mul);
}
}
Output:-
GGPC
Page 14
D952408
PRACTICAL NO 08
Objective: - WAP to show the use 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:-
GGPC
Page 15
GGPC
D952408
Page 16
D952408
PRACTICAL NO 09
Objective: - WAP to find the factorial of any number.
Coding:class f
{
public static void main(String args[])
{
int i, fact=1;
for(i=4; i>=1; i--)
{
fact=fact*i;
}
System.out.println("Factorial is " +fact);
}
}
Output:-
GGPC
Page 17
D952408
PRACTICAL NO 10
Objective: - WAP to show the use of applet.
Coding:import java.awt.*;
import java.applet.*;
public class numvalues extends Applet
{
public void paint(Graphics g)
{
int value1 = 10;
int value2 = 20;
int sum = value1 + value2;
String s = "sum:" + String.valueOf(sum);
g.drawString(s,10,100);
}
}
<HTML>
<CENTER>
<H4>
<APPLET code = numvalues.class
width= 800
height = 800>
</H4>
</CENTER>
</APPLET>
</HTML>
GGPC
Page 18
D952408
Output:-
GGPC
Page 19