Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
32 views

Java Programming Lab Lesson Plan - Spring 2025

Uploaded by

23051322
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Java Programming Lab Lesson Plan - Spring 2025

Uploaded by

23051322
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

CS29004 Java Programming Lab Manual

School of Computer Engineering


KIIT Deemed to be University

Java Programming Laboratory Lesson Plan

Spring 2024-25 (4th Semester)

Discipline : CSE

Course name and Code : Java Programming Laboratory (CS29004)

L-T-P-Cr : 0-0-2-1

Instructor Name : Dr. Partha Sarathi Paul, Email: parthasarathi.paulfcs@kiit.ac.in

Instructor Office : FB-101, Block-C, Campus-14

Technical Assistants Names:

1) Mr. Siddhartha Sankar Mishra, Email: siddhartha.mishra@kiit.ac.in

2) Mr. Kiran Jyoti Behera, Email: kiranjyoti76090@gmail.com

Weekly Laboratory Schedule: Thursday, 12:00 Noon - 02:00 PM

Course Outcomes:
Upon completion of this course, the students will be able to:

CO1: Run java programs using java compiler/IDE

CO2: Write java programs using basic object oriented programming concepts

CO3: Write programs using abstract classes interfaces and packages

CO4: Write java program using multi-threading and exception handling

CO5: Design Java application using String and I/O classes

CO6: Design GUI application using Swing and interactive application using event
handling and JDBC

School of Computer Engineering Page 1 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

List of Experiments (Day wise):


Lab 1 - Course Contents:

-Writing compiling and executing a simple Java programs

List of Programs :
1. Aim of the program -Write a program to print your name, roll no, section and
branch in separate lines.

Input: Mention Name, Roll no, Section and branch


Output: Display Name
Display Roll No
Display Section
Display Branch

2. Aim of the program: Write a program to print the corresponding grade for the
given mark using if..else statement in Java
Input: Mention the grade in the program
Output: Display the Grade either O/E/A/B/C

3. Aim of the program: Write a program to print the week day for the given day no. of
the current month using switch case statement

Input: Mention the Day no in the program


Output: Display the week day(either Sunday/Monday/Tuesday/Wednesday
/Thursday/Friday/Saturday)

4. Aim of the program : Program to check a user entered number is palindrome or not

Input: Mention the number in the program


Output: display the number is Palindrome or not.

5. Aim of the program : Write a program in Java to take first name and last name from
user and print both in one line as last name followed by first name

Input: Enter first name: KIIT


Enter Second Name: UNIVERSITY
Output: UNIVERSITY KIIT

School of Computer Engineering Page 2 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Lab 2 - Course Contents: - Array in Java


- Command line arguments in Java, Scanner Class
- static modifier in Java
List of Programs :

1. Aim of the program : Find the largest among 3 user entered nos. at the command
prompt using Java

Input: Enter three number .


Output: Display the Largest Number

2. Aim of the program : Accept 10 numbers from command line and check how many of
them are even and how many are odd.

Input: Enter 10 number from keyboard


Output: Display number of even and odd number

3. Aim of the program: Program to sort the user entered list of numbers of any size

Input: List of Numbers


Output: Display the numbers in Ascending order

4. Aim of the program: Program to find no. of objects created out of a class using
‘static’ modifier.

Input: No of objects created


Output: Display the number of objects created (e.g. no of objects=3)

5. Aim of the program: Find the no. of occurrence of each element in a user entered list
of nos.

Input: Enter list of numbers e.g.( 15 25 15 11 25 32 15 32)


Output: Occurrence of 15=3
Occurrence of 25=2
Occurrence of 11=1
Occurrence of 32=2

6. Aim of the program: Find sum of each diagonal (left & right) elements separately of a
user entered 3 X 3 matrix in Java.

Input: Enter 3X3 matrix


e.g. 673
892
129
Output: Left=24
Right=13

School of Computer Engineering Page 3 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Lab 3 - Course Contents: -class and objects in Java


-method overloading in Java
-constructor overloading in Java
List of Programs :

1. Aim of the program :Write a class file – box with three data members(length, width,
height) and a method volume() . Also implement the application class Demo where
an object of the box class is created with user entered dimensions and volume is printed.
Input: length,width and height.
Output: Volume
2. Aim of the program : Write a program in Java to create a class Rectangle having data
members length and breadth and three methods called read, calculate and display to read
the values of length and breadth, calculate the area and perimeter of the rectangle and display
the result respectively.

Input: Mention length and breadth


Output: Display Area of Rectangle and Perimeter of rectangle.

3. Aim of the program : Write a program in java to input and display the details of n
number of students having roll, name and cgpa as data members. Also display the
name of the student having lowest cgpa.

Input: Enter Roll No, Name and cgpa of ‘n’ number of students.
Output: Display the details of ‘n’ number of students. Also display the
name of student with lowest cgpa

4. Aim of the program : Write a program to overload subtract method with various
parameters in a class in Java. Write the driver class to use the different subtract
methods using object.
Input: Mention various subtract method having different parameters.
Output: Subtract method will display the result accordingly

5. Aim of the program : Write a program which will overload the area () method and
display the area of a circle, triangle and square as per user choice and user entered
dimensions.

Input: Mention dimensions like radius, base, height, side


Output: Display area of circle
Display area of triangle
Display area of square

6. Aim of the program : Write a program in java using constructor overloading concept
to calculate the area of a rectangle having data member as length and breadth. Use
default constructor to initialize the value of the data member to zero and parameterized
constructor to initialize the value of data member according to the user input.

Input: Mention the value of length and breadth


Output: Display the area of rectangle accordingly.

School of Computer Engineering Page 4 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Lab 4 - Course Contents: - Single level inheritance in Java


-Multi-level inheritance in Java
- Method Overriding and use of final and super keyword in java
- Dynamic Method Dispatch
List of Programs :

1. Aim of the program : A Plastic manufacturer sells plastic in different shapes like 2D
sheet and 3D box. The cost of sheet is Rs 40/ per square ft. and the cost of box is Rs 60/ per
cubic ft. Implement it in Java to calculate the cost of plastic as per the dimensions given by
the user where 3D inherits from 2D.

Input: Enter dimensions


Output: Display the cost of plastic

2. Aim of the program : Illustrate the execution of constructors in multi-level inheritance


with three Java classes – plate(length, width), box(length, width, height), wood box (length,
width, height, thick) where box inherits from plate and woodbox inherits from box class.
Each class has constructor where dimensions are taken from user.

Input: Enter the dimensions


Output: Display the dimensions accordingly

3. Aim of the program : Write a program in Java having three classes Apple, Banana
and Cherry. Class Banana and Cherry are inherited from class Apple and each class
have their own member function show() . Using Dynamic Method Dispatch concept
display all the show() method of each class.

Input: Mention show function of each class.


Output: Display show function of each class accordingly.

4. Aim of the program :Write a class Account containing acc_no, balance as data
members and two methods as input() for taking input from user and disp() method to
display the details. Create a subclass Person which has name and aadhar_no as
extra data members and override disp() function. Write the complete program to take
and print details of three persons.

Input: Enter details of three persons.


Output: Display details of three persons.

School of Computer Engineering Page 5 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Lab 5 - Course Contents: – Abstract class in Java


– Interface in Java
- Package in Java
List of Programs :

1. Aim of the program -Illustrate the usage of abstract class with following Java
classes –
 An abstract class ‘student’ with two data members roll no, reg no, a method getinput() and
an abstract method course()
 A subclass ‘kiitian’ with course() method implementation
Write the driver class to print the all details of a kiitian object.

Input - Rollno - 2205180


Registration no - 1234567890
Output -Rollno - 2205180
Registration no - 1234567890
Course - B.Tech. (Computer Science & Engg)

2. Aim of the program -Define an interface Motor with a data member –capacity and two
methods such as run() and consume(). Define a Java class ‘Washing machine’ which
implements this interface and write the code to check the value of the interface data
member thru an object of the class.
Input - mentioned in the program
Output - Capacity of the motor is -----

3. Aim of the program -Define an interface with three methods – earnings(), deductions()
and bonus() and define a Java class ‘Manager’ which uses this interface without
implementing bonus() method. Also define another Java class ‘Substaff’ which extends
from ‘Manager’ class and implements bonus() method. Write the complete program to
find out earnings, deduction and bonus of a substaff with basic salary amount entered
by the user as per the following guidelines –
earnings basic + DA (80% of basic) + HRA (15% of basic)
deduction PF 12% of basic
bonus 50% of basic
Input -Basic salary - 50000
Output -Earnings - 97500
Deduction -6000
Bonus - 25000

4. Aim of the program - Define an interface Emploee with a method getDetails() to get
emplyee details as Empid and Ename. Also define a derived interface Manager with a
method getDeptDetails() to get department details such as Deptid and Deptname.Then
define a class Head which implements Manager interface and also prints all details of the
employee. Write the complete program to display all details of one head of the department.

Input - Enter employee id - 123


Enter employee name - Sidharth Ambani
Enter department id - 06

School of Computer Engineering Page 6 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Enter department name -Marketing


Output - Employee id - 123
Employee name - Sidharth Ambani
Department id - 06
Department name -Marketing

5. Aim of the program - Define two packages as – General and Marketing. In General
package define a class ‘employee’ with data members as empid(protected), ename(private)
and a public method as earnings() which calculate total earnings as

earnings basic + DA (80% of basic) + HRA (15% of basic)

In Marketing package define a class ‘sales’ which is extending from ‘employee’ class and
has a method tallowance() which calculates Travelling Allowance as 5% of total earning.
Write the programs to find out total earning of a sales person for the given basic salary
amount and print along with the emp id.
Input: Enter the employee id and emploee name 123 Amit
Enter the basic salary 1000
Output: The emp id of the employee is 123
The total earning is 1950.0

Lab 6 - Course Contents: - Exception handling in Java


- User defined exception in Java
List of Programs :
1. Aim of the program - Write a Java program to generate an
ArrayIndexOutofBoundsException and handle it using catch statement.

Input: Enter the numbers -Example: 1 2 3 4 5 ( Suppose array size is 4 )


Output: Exception in thread “main”
java.lang.ArrayIndexOutOfBoundsException:4

2. Aim of the program- Write a Java program to handle an ArithmeticException


using try, catch, and finally block.

Input: Operand values for division operation mentioned in the program


Output: ArithmeticException caught by try-catch-finally block

3. Aim of the program- Write a Java class which has a method called
ProcessInput(). This method checks the number entered by the user. If the
entered number is negative then throw an user defined exception called
NegativeNumberException, otherwise it displays the double value of the entered
number.

Input: Enter a number 4


Output: Double value: 8
School of Computer Engineering Page 7 of 16
___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Input: Enter a number -4


Output: Caught the exception
Exception occurred: NegativeNumberException: number should be
positive

4. Aim of the Program: Write a program to create user defined exceptions called
HrsException, MinException and SecException. Create a class Time which
contains data members hours, minutes, seconds and a method to take a time
from user which throws the user defined exceptions if hours (>24
&<0),minutes(>60 &<0),seconds(>60 &<0).

Input: Enter hours: 4


Enter minutes: 54
Enter seconds: 34
Output: Correct Time-> 4:54:34

Input: Enter hours: 30


Enter minutes: 65
Enter seconds: 65
Output: Caught the exception
Exception occurred: InvalidHourException:hour is not greater than
24
Exception occurred: InvalidMinuteException:hour is not greater than
60
Exception occurred: InvalidSecondException:hour is not greater than
60

5. Aim of the Program: Create an user defined exception named CheckArgument to


check the number of arguments passed through command line. If the number of
arguments is less than four then throw the Check Argument exception, else print
the addition of squares of all the four elements.
Input: 4 3 2 1
Output : 30
Input: 4 3 2
Output : Exception occurred - CheckArgument

Lab 7 - Course Contents: - String handling in Java

- File Handling in Java

List of Programs :
1. Aim of the program -Write a program to perform following operations on user entered
strings and a character –
i) Change the case of the string
ii) Reverse the string
iii) Compare two strings

School of Computer Engineering Page 8 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

iv) Insert one string into another string


v) Convert the string to upper case and lower case
vi) Check whether the character is present in the string and at which position
vii) Check whether the string is palindrome or not.
viii) Check the number of word, vowel and consonant in the string

Input: Enter a String : amit


Output: The string after changing the case is AMIT
The string after reversing is tima

Input: Enter the second string for comparision : kumar


Output: The difference between ASCII value is 10

Input: Enter the string to be inserted into first string : thakur


Output: The string after insertion is : amit thakur

Input: Enter a String : Amit


Output: Uppercase: AMIT
Lowercase: amit

Input: Enter a String :Amitkumar


Enter a character : m
Output: Position of entered character: 2

Input: Enter a String : Amitkumar


Enter a character : Y
Output: Entered character is not present

Input: Enter a String : madam


Output: Entered string is palindrome

Input: Enter a String : muscle


Output: Entered string is not a palindrome

Input: Enter a String : Ram is going to school


Output: No. of words: 5
No. of vowels: 7
No. of consonants: 11

School of Computer Engineering Page 9 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

2. Aim of the program - Write a java program which will accept students details like
Student RollNo, Name, Subject, Marks from the keyboard using scanner class,
stored the same in a file. Again open the file, read the content and display all.

Input: Enter student details - Rollno, name, subject, marks


Enter the name of existing file to which student details will be written.
Output: Display the content of existing file

3. Aim of the program - Write a program in Java to copy the content of a given file to
another user entered file using character stream (using File Reader and FileWriter
Classes) and byte Stream (using FileInputStream and FileOutputStream Class).

Input: Enter the source file name - sourcefile.txt (Assume Input file exists
in the system)
Enter the destination file name - destinationfile.txt
Output: File Copied

4. Aim of the program -Write a java program to compare two binary files, printing the
first byte position where they differ.

Input: Specify two binary files in the program (Assume two files are exist in
the system)
Output: Two files are equal
Input: Specify two binary files in the program
Output: Two files are not equal: byte position at which two files differ is 30

5. Aim of the program -Write a java program that displays the number of characters,
no. of lines and no. of words present in a text file whose name is given by the user.

Input: Name of the file - filename


Output: No. of characters - A,
No .of lines - B
No . of words - C

Lab 8 - Course Contents: - Multi-threading in Java

List of Programs :
1. Aim of the program - Write a program in Java using multi-threading which will display a
counter value within a specified range with a gap of 5 milliseconds after setting it’s name
as given by the user.
Input : Name of the thread - First
Lower range of counter - 10
Upper range of counter - 15
Output : Thread - First
Counter - 10 11 12 13 14 15
School of Computer Engineering Page 10 of 16
___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

2. Aim of the program -Write a program in java which will display the working of two
threads in synchronization.
Input:
Output:

3. Aim of the program -Design a Stop Watch using event handling and multi-threading in
Java.

Practice Program Sets:-

1. Aim of the program - Design a swing application using event and multithreading which
will display multiple images one after another moving in a square shape with a gap of 10
millisecond. At the same time, four messages like - " Welcome "," Enjoy "," Thanks "," Visit
Again " will also be displayed one after another on the same page.

Output: Animation of images

School of Computer Engineering Page 11 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Lab 9- Course Contents: – Java Database Connectivity

List of Programs :
1. Aim of the program -Write a java program which will display all the records from the
student table.
Input : Table name mentioned in the program
Output :
2205123 rakesh yadav 76

2. Aim of the program - Write a 2205230 sanjiv kumar 82 java


program which will display a
particular record from the 2206345 pranab dutta 73
student table on the basis of 2206242 asish mukherjee 78
RollNo supplied from the
keyboard. 2205542 suman singh 85
Input : Rollno (2205542)
Output : 2205542 suman singh 85

3. Aim of the program - Write a java program which will insert a record, update and delete
a particular record in the student table.
Input : Enter rollno to be inserted : 2205650
Enter name : Aditya Bajaj
Enter marks : 93
Output : 1 record inserted

4. Aim of the program -Write a java program which will display all the records from the
student table along with the column heading.
Input :Table name mentioned in the program

Roll no Name Marks

2205123 rakesh yadav 76

2205230 sanjiv kumar 82

2206345 pranab dutta 73

School of Computer Engineering Page 12 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Output : 2206242 asish mukherjee 78

2205542 suman singh 85

5. Aim of the program -Design an interface as shown below using Frame and Swing in
Java

Here the user will write a query in the text field and then click on the execute query
button. The output of the query will be displayed on another hidden text area.
Input : select mark from student where rollno= 2205230
Output : 82

Practice Program Sets:-

Aim of the program -Design an interface as shown below using Frame and Swing in Java .

The user will fill up the details and after clicking on the insert button, the data will be
inserted in the table. Similarly Update button will update the record based on the Roll No
and in the same way delete button will delete the corresponding record from the table.
Input : Rollno - 2205423
Name - Manish Malhotra
Marks - 84
Output : On clicking Insert button - one record inserted
School of Computer Engineering Page 13 of 16
___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

On clicking Update button - one record updated


On clicking Delete button - one record deleted

Lab 10 - Course Contents: – GUI Programming using Swing in Java


– Event Handling in Java

List of Programs :
1. Aim of the program -Design a registration form using Swing with following components
on it – Label, Textbox, Text area, Checkbox, Radio button and Button, Image.

2. Aim of the program -Write a GUI program in Java with three Labels – Enter the First
Number, Enter the Second Number, Result, and three text fields for - first number,
second number and result and four buttons - Add, Sub, multiply and reset as shown
below. On clicking of any of these buttons, the corresponding operation should be
performed with input1 and input2 and the result should be displayed in the result box.

Input: First and second number


Output: Appropriate result will be displayed in the result text field

3. Aim of the program -Implement a GUI application which consists of one List Box and
one button. The list box will have four different color names. When the user will select
a color from the list box and click on the button, the panel color will be changed to
that color.

Input: Select any color from the list box


Output: Panel background color will be changed accordingly

School of Computer Engineering Page 14 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

4. Aim of the program -Design a GUI application which consists of three Label named
as Red, Green and blue, three combo boxes which will consist the value from 0 to 255
and one button named as show output. The user will select different values from three
combo boxes. When the user clicks on the button, the panel background will be
changed accordingly as per the value passed in RGB format.

Input: select three color value(0-255) from 3 different combo box.


Output: The panel color will be changed accordingly

Practice Program Sets:-

1. Aim of the program -Design a GUI Calculator as shown below using frame and action
event in Java.

Input: Any two number with one operator and then click on = button.
Output: Appropriate result will be displayed.

2. Aim of the program -Design a GUI application as shown below which consists of two
text fields and various buttons for String operations. On clicking any of the button, the
corresponding operation will be performed on the entered string in the first text field
and the resultant string will be displayed in the second text field.

Input: Any string in the fist text field and click on any button.
Output: Modified string in the second field

School of Computer Engineering Page 15 of 16


___________________________________________________________________________________________________________________
CS29004 Java Programming Lab Manual

Grading Policies:
 Continuous Evaluation components
Internal Evaluation (Continuous Evaluation over the semester which includes
Quiz/Viva/Lab Record/Lab performance/Attendance etc.) : 60 Marks

 End semester evaluation


End-Term Evaluation (Sessional Exam) : 40 Marks

Reference Materials:-
Reference Book:
1. Java-The Complete Reference, Herbert Schildt, 10th Edition, McGraw Hill
Education, 2014
2. Introduction to JAVA Programming, Y.Daniel Liang, 10th Edition, Pearson
Education, 2007
3. Java Programming – for Core and Advanced Users, Sagayaraj, Denis, Karthik and
Gajalakshmi, Universities Press.
4. Java - One Step Ahead, by Anita Seth and B L Juneja, published by Oxford
University Press

School of Computer Engineering Page 16 of 16


___________________________________________________________________________________________________________________

You might also like