Java Programming Laboratory Lab Manual
Java Programming Laboratory Lab Manual
LAB MANUAL
COURSE CODE:
KANATHUR, CHENNAI.
1. GUIDELINES TO STUDENTS
1. Equipment in the lab for the use of student community. Students need to maintain a proper
decorum in the computer lab. Students must use the equipment with care. Any damage is
Caused is punishable.
2. Students are instructed to come to lab in formal dresses only.
3. Students are supposed to occupy the systems allotted to them and are not supposed to talk
or make noise in the lab.
4. Students are required to carry their observation book and lab records with completed
exercises while entering the lab.
5. Lab records need to be submitted every week.
6. Students are not supposed to use pen drives in the lab.
REQUIREMENTS
HARDWARE:
Pentium IV with 2 GB RAM,
160 GB HARD Disk,
Monitor 1024 x 768 colour
60 Hz.
30 Nodes
SOFTWARE:
Windows Operating System
JDK 1.6(or above)
COURSE OBJECTIVE:
COURSE OUTCOME :
MARKS SCHEME
OUTPUT
Sum of 10 and 12 is :22
Average of 22 is :11.0
Ex.No. :2
Write a program to find the Largest number for given values
import java.io.*;
public class MyClass {
static String a;
static int b;
static void input()
{
a="Karan Raj";
b=12345;
}
static void display()
{
System.out.println("Name: "+a);
System.out.println("Number: "+b);
}
public static void main(String args[])
{
MyClass m=new MyClass();
m.input();
m.display();
}
}
OUTPUT
C:/Javac MyClass.java
C:/ Java MyClass
import java.io.*;
public class cal
{
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int ans;
System.out.println("1. For Addition\n2. For Subtraction\n3. For Multiplication\n4. For
Division");
int n=Integer.parseInt(br.readLine());
System.out.println("Enter First Number");
int n1=Integer.parseInt(br.readLine());
System.out.println("Enter Second Number");
int n2=Integer.parseInt(br.readLine());
switch(n)
{
case 1:
ans=n1+n2;
System.out.println("Answer is:"+ans);
break;
case 2:
ans=n1-n2;
System.out.println("Answer is:"+ans);
break;
case 3:
ans=n1*n2;
System.out.println("Answer is:"+ans);
break;
case 4:
ans=n1/n2;
System.out.println("Answer is:"+ans);
break;
default:
System.out.println("ERROR");
}
}
}
OUTPUT
C:/javac cal.java
C:/java cal
1. Addition
2. Subtraction
3. Multiplication
4. Division
1
Enter First Number : 12
Enter Second Number : 8
Answer is : 20
EX.NO. :8
WRITE A PROGRAM TO DISPLAY EMPLOYEE DETAILS USING PACKAGE.
package Employee1;
public class Emp
{
String name,empid,cty;
int bpay;
double hra,da,npay,pf;
public Emp(String n,String id,String c,int b)
{
name=n;
empid=id;
cty=c;
bpay=b;
}
public void call()
{
da=bpay*0.05;
hra=bpay*0.05;
pf=bpay*0.08;
npay=bpay+da+hra-pf;
}
public void display()
{
System.out.println("\n\t\tEMPLOYEE DETAILS");
System.out.println("\nName: "+name);
System.out.println("\nEmployee ID: "+empid);
System.out.println("\nCategory: "+cty);
System.out.println("\nBpay: "+bpay);
System.out.println("\nHra: "+hra);
System.out.println("\nDa: "+da);
System.out.println("\nPf: "+pf);
System.out.println("\nNpay: "+npay);
}
}
import java.io.*;
import java.util.*;
import Employee1.Emp;
class Emppay
{
public static void main(String args[])throws IOException
{
Emp e=new Emp("Rama","IT101","Female",10000);
e.call();
e.display();
}
}
class details
{
void info()
{
System.out.println("Karan");
System.out.println("ALC18009");
System.out.println("LCA029");
}}
Karan
ALC18009
LCA029
AMET University
EX.NO. :10
WRITE A PROGRAM TO CALCULATE AREA OF CIRCLE USING INTERFACE
interface area
{
double p=3.14;
double calc(double x,double y);
}
} }
}
C:/javac String_Functions.java
C:/ java String_Functions
Enter First String
Enter Second String
Enter First StringAMET
Enter First StringUNIVERSITY
Upper Case of 1st String: AMET
Upper Case of 2nd String: UNIVERSITY
Lower Case of 1st String: amet
Lower Case of 2nd String: university
Joining First and Second String: AMET UNIVERSITY
First String's Substring: ET
Second String's SubString: N
String Compare: -20
IS Empty function: false
Replacing a Word in First String: AMET
Replacing a Word in Second String: UNIVERSITY
Length of the First String: 5
Length of the Second String: 11
EX.NO. :13
import java.io.*;
public class thread implements Runnable
{
public void run()
{
System.out.println("Thread is Running");
}
public static void main(String args[])
{
thread m=new thread();
Thread t=new Thread(m);
t.start();
}
}
import java.applet.*;
import java.awt.*;
/*
<applet code="Main" width=800 height=500>
</applet>
*/
public class Main extends Applet
{
public void paint(Graphics k)
{
k.drawString("WELCOME TO AMET UNIVERSITY B.COM
DEPARTMENT",50.120);
}
}
EX.NO. :15
import java.awt.*;
import java.awt.event.*;
class MyLoginWindow extends Frame
{
TextField name,pass;
Button b1,b2;
MyLoginWindow()
{
setLayout(new FlowLayout());
this.setLayout(null);
Label n=new Label("Name:",Label.CENTER);
Label p=new Label("password:",Label.CENTER);
name=new TextField(20);
pass=new TextField(20);
pass.setEchoChar('#');
b1=new Button("submit");
b2=new Button("cancel");
this.add(n);
this.add(name);
this.add(p);
this.add(pass);
this.add(b1);
this.add(b2);
n.setBounds(70,90,90,60);
p.setBounds(70,130,90,60);
name.setBounds(200,100,90,20);
pass.setBounds(200,140,90,20);
b1.setBounds(100,260,70,40);
b2.setBounds(180,260,70,40);
}
public static void main(String args[])
{
MyLoginWindow ml=new MyLoginWindow();
ml.setVisible(true);
ml.setSize(400,400);
ml.setTitle("my login window");
}
}