0% found this document useful (0 votes)
107 views27 pages

Java Programming Laboratory Lab Manual

The document is a lab manual for a Java Programming course. It outlines the hardware and software requirements for the course, including recommended systems with at least 2.6GHz processors, 256MB RAM, 40GB storage, and Windows or Linux operating systems. It also lists 12 sample programming exercises that students will complete in the lab, covering basic Java concepts like variables, conditionals, loops, classes and objects. It describes how students will be evaluated, including assignments, observation, attendance, exams and projects.

Uploaded by

M Joshua Alfred
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
107 views27 pages

Java Programming Laboratory Lab Manual

The document is a lab manual for a Java Programming course. It outlines the hardware and software requirements for the course, including recommended systems with at least 2.6GHz processors, 256MB RAM, 40GB storage, and Windows or Linux operating systems. It also lists 12 sample programming exercises that students will complete in the lab, covering basic Java concepts like variables, conditionals, loops, classes and objects. It describes how students will be evaluated, including assignments, observation, attendance, exams and projects.

Uploaded by

M Joshua Alfred
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 27

JAVA PROGRAMMING LABORATORY

LAB MANUAL

PROGRAMME: B.COM (LCA)

COURSE CODE:

COURSE NAME : JAVA PROGRAMMING

YEAR / SEM: II/II

DEPARTMENT OF MARITIME COMMERCE

AMET DEEMMED TO BE UNIVERSITY

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)

Recommended System/Software Requirements:


Intel based desktop PC with minimum of 2.6GHZ or faster processor with at least 256
MB RAM and 40GB free disk space.
Operating system: Flavor of any WINDOWS.
Software:j2sdk1.7.
Linux and MvSQL.
Eclipse or Net beam.

COURSE OBJECTIVE:

COURSE OUTCOME :
MARKS SCHEME

Internal Assessment Mark Split Up


Observation : 20 Marks
Attendance : 5 Marks
Mini Project with the Report
(Max. 8 Pages & 3 Students per Batch) : 20 Marks
Model Exam : 15 Marks
TOTAL MARKS : 60 Marks
INDEX

S.NO. Page No.


LIST OF EXPERIMENTS
1. Write a program to find Sum and average of two numbers.
public class calculation
{
public static void main(String args[])
{
int n=10,n1=12;
int sum;
double avg;
sum=n+n1;
avg=sum/2;
System.out.println("Sum of "+n+" and "+n1+" is:"+sum);
System.out.println("Average of "+sum+" is:"+avg);
}
}

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

// A program for finding the largest number


public class Largest
{
public static void main(String args[])
{
int a=10,b=15,c=17;
if(a>b && a>c)
{
System.out.println("A:"+a+" is Greater");
}
else if(b>a && b>c)
{
System.out.println("B:"+b+" is Greater");
}
else
{
System.out.println("C:"+c+" is Greater");
}
}
}
OUTPUT
C: 17 is Greater
EX.NO. :3
WRITE A PROGRAM TO DEMONSTRATE STATIC VARIABLE AND STATIC
METHOD.

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

Name: Karan Raj


Number: 12345
EX.NO. :4
WRITE A PROGRAM TO FIND THE GIVEN VALUE IS ODD OR EVEN.

// A program for finding a number is odd or even


public class Odd_Even
{
public static void main(String args[])
{
int a=11;
if(a%2==0)
{
System.out.println("The Number "+a+" is Even");
}
else
{
System.out.println("The Number "+a+" is Odd");
}
}
}

C:/ javac Odd_Even.java


C:/ java Odd_Even
The Number 11 is Odd.
EX.NO. :5
WRITE THE PROGRAM TO FIND THE SUM OF SERIES 1+2+3……..N.

// A program for finding the sum of series


public class sseries
{
public static void main(String args[])
{
int sum=0;
int n=6;
for(int i=0;i<=n;i++)
{
sum=i+sum;
}
System.out.println("Sum of Series is: "+sum);
}
}
OUTPUT
C:/javac series.java
C:/java series
Sum of Series is : 21
EX.NO. :6

WRITE A PROGRAM TO FIND WHETHER THE GIVEN NUMBER IS


ARMSTRONG NUMBER OR NOT.

public class Armstrong


{
public static void main(String args[])
{
int n=154;
int temp,n1,sum=0;
temp=n;
while(temp!=0)
{
n1= temp%10;
sum=sum+(n1*n1*n1);
temp=temp/10;
}
if(sum == n)
System.out.println("The number "+n+" is an armstrong number.");
else
System.out.println("The number "+n+" is not an armstrong number.");
}
}
C:/ javac Armstrong.java
C:/ java Armstrong
The number 154 is not an armstrong number.
EX.NO. :7

WRITE A PROGRAM TO EXECUTE ARITHMETIC OPERATION USING


SWITCH STATEMENT.

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();
}
}

C:/ javac Emppay.java


C:/java Emppay
EX.NO. : 9

WRITE A PROGRAM TO IMPLEMENT THE STUDENT DETAILS USING


INHERITANCE.

class details
{
void info()
{
System.out.println("Karan");

System.out.println("ALC18009");

System.out.println("LCA029");
}}

public class Main extends details


{
public static void main(String args[])
{
Main ob=new Main();
String clg="AMET University";
ob.info();
System.out.println(clg);
}
}
C:// javac Main.java
C:// java Main

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);
}

class circle implements area


{
public double calc(double x,double y)
{
return(p*x*x);
}
}

public class Main


{
public static void main(String args[])
{
circle c=new circle();
area a;
a=c;
System.out.println("Circle Area is:"+a.calc(4,4));
}
}
C:/javac Main.java
C:// java Main
Circle Area is : 50.24
EX.NO. :11

WRITE A PROGRAM TO HANDLE ARITHMETIC ERROR USING EXCEPTION


HANDLING

public class Exception_Handling


{
public static void main(String args[])
{
try{
int n=5, n1=0;
int c=n/n1;
System.out.println ("Result: "+c);
}
catch(ArithmeticException e){
System.out.println ("You Shouldn't divide a number by zero");
}
}
}
C://javac Exception_Handling.java
C:// java Exception_Handling
You Shouldn’t divide a number by zero.
EX.NO. :12
WRITE A PROGRAM TO MANIPULATE VARIOUS STRING FUNCTIONS.
import java.io.*;
public class String_Functions
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter First String");
String s=br.readLine();
System.out.println("Enter Second String");
String s1=br.readLine();
System.out.println("Enter First String"+s);
System.out.println("Enter First String"+s1);
System.out.println("Upper Case of 1st String: "+s.toUpperCase());
System.out.println("Upper Case of 2nd String: "+s1.toUpperCase());
System.out.println("Lower Case of 1st String: "+s.toLowerCase());
System.out.println("Lower Case of 2nd String: "+s1.toLowerCase());
System.out.println("Joining First and Second String: "+s.concat(s1));
System.out.println("First String's Substring: "+s.substring(2,4));
System.out.println("Second String's SubString: "+s1.substring(1,2));
System.out.println("String Compare: "+s.compareTo(s1));
System.out.println("IS Empty function: "+s.isEmpty());
System.out.println("Replacing a Word in First String: "+s.replace('a','x'));
System.out.println("Replacing a Word in Second String: "+s1.replace('a','y'));
System.out.println("Length of the First String: "+s.length());
System.out.println("Length of the Second String: "+s1.length());
if(s.equals(s1))
{
System.out.println("Same");
}
else
{
System.out.println("Different");

} }
}

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

WRITE A PROGRAM TO HANDLE MULTIPLE THREADS USING IMPLEMENTS


FUNCTION.

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();
}
}

C:// javac thread.java


C://java thread
Thread is running

Using extends function


import java.io.*;
public class thread extends Thread
{
public void run()
{
System.out.println("Welcome");
}
public static void main(String args[])
{
thread m=new thread();
m.start();
}
}
EX.NO. :14
WRITE A APPLET PROGRAM TO DISPLAY A MESSAGE.

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

WRITE AN APPLET PROGRAM TO DISPLAY LOGIN PAGE USING AWT


CONTROLS

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");
}
}

You might also like