Professional Documents
Culture Documents
Java Programming Lab Manual Sastra University
Java Programming Lab Manual Sastra University
School of Computing
Shanmugha Arts, Science, Technology and Research Academy [SASTRA]
Thanjavur – 613 401
List of Experiments
1. Polymorphism in java.
2. Inheritance in Java.
3. Interface in Java.
4. Packages in java.
5. Multiple Threads in JAVA.
6. Exceptions in JAVA.
7. Applet using Labels, Text Fields and Buttons.
8. Applet using Checkbox, Option Buttons, Choice, List and Scrollbar.
9. Standalone GUI interface using Frames.
10. Applet for demonstrating font features.
11. Applet using Panels and Layout manager.
12. Applet for demonstrating graphics features – using brush styles, colors.
13. Library Management using JDBC.
Additional Exercises
Algorithm :
Sample I/O :
Area of rectangle = 32
Area of triangle = 16
2. Inheritance in Java
Pre Lab : Define a class named ‘Vehicle’ with data members - name, model
number, price, service station name; add constructor and display() method.
Define another class ‘Bike’ that extends the class ‘Vehicle’ with data member
discount rate and methods constructor, display() ,discount() to compute discount.
Use object of the extended class to compute the discount and display the details
of the vehicle, inherited from its parent.
Algorithm :
Sample I/O :
Enter marks : 78
87
82
Grade = A
Person
Category
Student Staff
name name
regno id
address dateOfJoining
yearOfJoinning
getdata()
getStudentDetails()
display()
m1 qualification certification
m2 skills yearsOfExperience
m3 areaofinterest expertise
getMarkDetails()
getPersonalDetails() inputdata()
display() showdata()
Result
tot
grade
computeGrade()
3. Interface in Java
Objective: To implement the concept of interface in Java.
PreLab : Create two interfaces inter1 and inter2 with the signatures meth1()
and meth2() respectively. Create Class Test and implement the two interfaces and
override the signatures. Also write your own methods in Class Test. Use the
instance of the Class Test and call the methods.
Algorithm :
Sample Output :
PreLab : Define a package named in that contains only one class named InValue.
This class contains three methods named stringReader(), intReader() and
fractReader() to read a string, integer, and fractional number respectively. Import
the in package in the code InValueDemo.java that contains only one class named
InValueDemo. This class contains the main() method that creates an object for the
class InValue and then invokes the stringReader(), intReader() and fractReader()
methods.
Algorithm :
Create two packages having the same class name in each package.
For example, create STUDENT class in two packages named P1 and P2
with data members such as name, register number, course, department,
year of study.
Create methods with same name in both the classes to accept data, display
data, with different implementation.
Create instance of class STUDENT from the above two packages.
Invoke the methods using those objects (of both classes named
STUDENT)
PreLab : Write a simple program to create a thread using Thread class. Call
the start() method which gives a call to run().
Algorithm :
Sample input/output :
Algorithm :
Sample input/output :
Exception1 thrown
Exception1 caught
.
.
.
7. Simple Applet using Labels, Text Field and Buttons
(Calculator)
Algorithm :
Sample output :
8. Simple Applet using Option Buttons, Choice, List and
Scrollbars
Objective: To design a Student Response Form with java Applet application.
Algorithm :
Sample output :
Algorithm :
Sample output :
10.Applet demonstrating font features
Objective: Create a java applet program that demonstrates the font features.
PreLab : Create a class that inherits Font class and assign values to the pre-
defined variables of the class. Assign these values to the object of the Font
class and observe the result.
Algorithm :
Sample output :
11.Applet using Panels and Layout Managers
Objective: To demonstrate panels and the various layout managers using
Applet.
PreLab : Create an Applet extending the Panel class. Use methods that loads
and displays images, plays audio clips
Algorithm :
Create an Applet for layout demo. Add various controls like textbox,
checkbox. Add some meaningful text on the screen
Apply the various layouts like Flow Layout, Border Layout, Insets, Grid
Layout and Card Layout.
Sample Output :
12. Applet demonstrating graphics features using brush
styles, colors
Objective: To demonstrate the various graphics features available in JAVA by
taking paintbrush application as an example.
PreLab :
Algorithm :
Sample output :
13.Library Management using JDBC
Objective: To understand database connectivity, operation and manipulation
using JDBC, with the help of a library management system.
Algorithm :
Create a frame and controls like textbox for entering text and for
displaying the details, list for displaying the available list of books, grid for
searching, etc.
Create tables like Books, Journals, Users, etc
Enter some book name in text field and display its details, if the record is
available.
Enter the details of new books received in the library and add this new
record to the database.
Create windows for issue and return of books and update the database
accordingly.
Delete the record details of a book, if it was lost.
Sample Output :