Java Lab Manual1
Java Lab Manual1
BHAWANIPATNA
PREPARED BY MR.GOPAL BEHERA, ASST. PROFESSOR, CSE
LAB MANUAL
JAVA LAB
GOVT.COLLEGE OF ENGINEERING
KALAHANDI
4
2 Lab Objective
36
6 References
Week-6
15 Write a Program That reads on a file and display the information that 25
whether the file exists or not, to display the information about the file
and find the type of file whether readable, writable and the length of
bytes.
16 Write a Program That reads a file and displays the file on the screen 27
within line number before each line
Week-7
17 Write a Program That prints a number of characters ,words, lines in 29
that file
Week-8
19 Write an applet that displays a simple message 31
Week-9
21 Write a Program That works as a simple calculator using Grid layout 32
to arrange buttons for the digits and +,-,* % operations. Add a text
filed to print the result.
Week-11
25 Write a Program That implements the client/server application. The 37
client sends the data to the server; the client receives the data, uses it
to produce a result and then sends the result back to the client. The
client displays the result on the console.
Ex: The data sent by the client is radius of a circle and the result
produced by the server is area of a circle
Text Editor
Javac
Java
program
Output
The way these tools are applied to build and run application programs is create a program. We
need create a source code file using a text editor. The source code is then compiled using the java
compiler javac and executed using the java interpreter java. The java debugger jdb is used to find
errors. A complied java program can be converted into a source code.
Compilation steps
Step2: Create new file and write your java program.
Step3: Save the file as classname.jave for example if your class name is test then your file
name should be test.java
Step4: Open command prompt (Go to start menu->run->type cmd then enter key press)
Step5: Type javac filename and press enter.
If everything is ok the compiler creates a file called fliname.class which contains byte
code.
Step6: To run /to see the output type java class name. (This step is the Executing java
program)
AIM:
Name of the Experiment No1:
1. Write a java program to find the simple interest.
HW/SW requirements:
Processor : AMD Athelon ™ 1.67 GHz
RAM : 256 MB
Hard Disk : 40 GB
JDK is required, with compilers.
Algorithm:
1. Start the program.
3. Interest To pay=principle*time*rate/100;
Test Data:
a) Valid data sets: 25000 int value as principal, 12.5f float value as rate, 2.75 as double
as interest To Pay.
b) Limiting value sets: Only integer values can be stored in the var. principal.
c) Invalid data sets: If we assign float value in var. principal error will occur.
Results for different data sets:
I/P: Principal amount is Rs.25000 interest=Rs.8593.75
O/P: Total amount to pay to clear the loan = Rs.33593.75
Write a Java program to convert any number to character number format from 0 to 9
Software/Hardware Requirements:
ALGORITHM:
Algorithm:
AIM:
Name of the Experiment No3:
AIM:
Name of the Experiment No-4:
S/W: JDK1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
Step1: start
Step2: input n,I,f
Step3: f=i=1
Step4: if(i<=n)
Step5: f=f*i
Step6: i=i+1
Step7: repeat from step5 to step6 till steps true
Step8: print f
tep9: stop
Test Data:
AIM:
Name of the Experiment No-5:
Write a java program to check whether the first number is a multiple of second number.
Software/Hardware Requirements:
S/W: JDK1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
1. Start the program.
4. By using switch case (multi way decision statement) when a match is found, that case is
executed.
Test Data:
AIM:
Name of the Experiment No-6:
Software/Hardware Requirements:
S/W: JDK 1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
1. Start the program.
Test Data:
AIM:
Name of the Experiment No-7:
S/W: JDK 1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
7. r=N%10
8. sum=sum+r*r*r formula.
9. N=N/10
Test Data:
AIM:
Name of the Experiment No-8:
Software/Hardware Requirements:
S/W: JDK1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
Test Data:
Enter value of a:
Enter value of b:
Enter value of c:
Enter value of a:
Enter value of b:
Enter value of c:
Root1 = -0.46887112585072543
Root2 = -8.531128874149275
AIM:
Write a java program to generate the Fibonacci series, given number of n values.
Software/Hardware Requirements:
Step1: start
Step3: f=0,f1=1,f2=1
Step4: do
I++
F1=f2
F2=f
F=f1+f2
While (i<=n)
Step6: stop
Test Data:
AIM:
Name of the Experiment No-11:
S/W: JDK1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
write palandrom
else
Enter a string
madam
Given string is palindrome
Enter a string
cse
Given string is not palindrome
AIM:
Name of the Experiment No-12:
Write a java program arrange strings into ascending order
Software/Hardware Requirements:
7. if a[j]<a[j+1] then
class sorting
{
public static void main(String[] input)
{
int k=input.length;
String temp=new String();
String names[]=new String[k+1];
for(int i=0;i<k;i++)
{
names[i]=input[i];
}
for(int i=0;i<k;i++)
for(int j=i+1;j<k;j++)
{
if(names[i].compareTo(names[j])<0)
{
temp=names[i];
names[i]=names[j];
names[j]=temp;
}
}
System.out.println(“Sorted order is”);
for(int i=0;i<k;i++)
{
System.out.println(names[i]);
}
}
}
Test Data:
Software/Hardware Requirements:
ALGORITHM:
Step1: start
Step2:read I,j,k,a[3][3],b[3][2],c[3][2]
Step3: read a[3][3] & b[3][2]
Step 4:i=0,j=0,k=0
Step5: if i<3 then i++ else goto 1
Step6: if j<3 then j++ else goto 5
Step7: if k<3 then k++ else goto 6
Step8: c[i][j]=c[i][j]+a[k][j]*b[i][k]
Step9: print a[i][j],b[i][j],c[i][j]
Step 10: stop
Test Data:
AIM:
Name of the Experiment No-14:
Write java program display the file is exists and number of bytes in the given file
Software/Hardware Requirements:
S/W: JDK1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
1. Start the program, import the packages.
else
Test Data:
C:\DOCUME~1\student\Desktop>java p15
number of bytes in this file is:249
AIM:
Name of the Experiment No-16:
Write java program display the no of lines,words and characters of a given file
Software/Hardware Requirements:
3) compute count=0,word=0,line=1,space=0
line++
else
word++
else
char++
6) print word,line,char
Test Data:
2. Now override the “public void run()” method and write your logic there (This is the method
which will be executed when this thread is started).
Test Data:
AIM:
Name of the Experiment No-17:
Write a java applet to display simple message
Software/Hardware Requirements:
AIM:
Name of the Experiment No-18:
Write an applet that computes the payment of a loan on the amount of the loan,the interest rate
and the number of months.it takes one parameter from the browser:monthly rate,if true,the
interest rate is per month otherwise the interest rate is per annual.
Software/Hardware Requirements:
S/W: JDK1.5(JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
1 start
2 take applet
3 add(new Label("select months/years "));
4 actionPerformed(ActionEvent e)
5 else
6 stop
Integer.parseInt(ta.getText())*Integer.parseInt(tm1.getText())*Integer.parseInt(tr.getText())/1200
Test Data:
Valid Data Set: 24 months
Invalid Data Set: Not applicable
Limiting Data Sets: Integer Range (-32768 to 32767)
Results for different Data Sets
AIM:
Name of the Experiment No-19:
Write a java program that works as a simple calculator
Software/Hardware Requirements:
AIM:
Name of the Experiment No20:
Write a java program to implement the APPLET PACKAGES, draw Mouse event handler
programs.
Software/Hardware Requirements:
ALGORITHM:
1. Start the program.
4. Mouse moments, mouse Clicked, mouse Pressed, mouse Released, mouse Entered, mouse
Exited, mouse Dragged events args.
Test Data:
AIM:
Name of the Experiment No21:
Software/Hardware Requirements:
S/W: JDK1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
1 Start
2 take class
3 for singal wait
4 true 0r false
5 println new InterThread(job)
6 stop
Test Data:
put: 0
got: 0
put: 1
got: 1
put: 2
got: 2
put: 3
got: 3
put: 4
got: 4
AIM:
Name of the Experiment No22:
Write a java program to implement the APPLET PACKAGES, draw Lines, Rectangles, Rounded
Rectangles, filled Polygons programs.
Software/Hardware Requirements:
ALGORITHM:
Test Data:
AIM:
Name of the Experiment No-23:
Software/Hardware Requirements:
S/W: JDK1.5 (JAVA), Office XP, Windows NT Server with Service Pack
H/W: Pentium IV, Intel Mother Board Processor, 40 GB HDD, 256 MB RAM
ALGORITHM:
1 Start the program.
Test Data:
Valid Data Set: hai
enter socket no:”127.0.0”,21
REFERENCES:
BOOKS:
1. Programming in Java. Second Edition. OXFORD HIGHER EDUCATION. (SACHIN
MALHOTRA/SAURAV CHOUDHARY).
2. JAVA Complete Reference (9th Edition) Herbalt Schelidt.
3. Just Java 1.2- Peter van der linder
WEBSITES:
1. www.java.com
2. www.java.sun.com
3. www.freewarejava.com
4. www.javalobby.org