Java Lab Assignments (Full Programs with Output)
Q1: Student Class with Constructors and Method Overloading
Objective: Practice classes, constructors (default & parameterized) and method overloading.
Problem Statement: Create a class Student with attributes name, rollNo and marks. Provide a
default constructor and a parameterized constructor. Overload a method updateMarks(int
marks) and updateMarks(String name, int marks). Write display() to print student details.
Demonstrate with two Student objects.
Q2: Employee and Manager (Inheritance and Overriding)
Objective: Implement inheritance and method overriding.
Problem Statement: Create a base class Employee with fields name and basicSalary and method
calculateSalary() that returns basicSalary. Create subclass Manager that adds incentive and
overrides calculateSalary() to include incentive. Demonstrate both.
Q3: Shape Hierarchy with Polymorphism (Overriding)
Objective: Practice inheritance polymorphism and method overriding.
Problem Statement: Create a base class Shape with method area() returning 0. Create
subclasses Circle and Rectangle that override area(). Demonstrate runtime polymorphism by
storing different shapes in a Shape reference array and printing areas.
Q4: Wrapper Class - Autoboxing and Unboxing
Objective: Understand wrapper classes, autoboxing, and unboxing.
Problem Statement: Read an int value, convert it to Integer, Double and String using wrapper
classes. Perform addition using unboxed values.
Q5: Array Operations - Max, Min, Sort
Objective: Practice single-dimensional arrays and common operations.
Problem Statement: Given an integer array, write methods to find maximum, minimum and to
sort the array (use [Link]). Display original and sorted arrays.
Q6: Two-Dimensional Array - Matrix Addition
Objective: Practice multidimensional arrays.
Problem Statement: Write a program to add two 2x2 matrices and display the result.
Q7: Multiple Inheritance using Interfaces
Objective: Implement multiple inheritance using interfaces.
Problem Statement: Create interfaces Printable and Showable with methods print() and show().
Implement both in class Result that prints student info.
Q8: Extending Interfaces - Shape and ThreeDShape
Objective: Practice interface extension and implementation.
Problem Statement: Create interface Shape with area() and extend it to ThreeDShape with
volume(). Implement Rectangle (area) and Cuboid (area & volume).
Q9: Default and Static Methods in Interfaces
Objective: Learn default and static methods in interfaces.
Problem Statement: Create interface Displayable with a default method greet() and static
method info(). Implement it in a class DemoDisplay.
Q10: Creating and Accessing a Simple Package (college)
Objective: Create a package and access its class from outside.
Problem Statement: Create package 'college' with class Department (fields name, facultyCount
and method display()). In another file (in default package) import [Link] and use it.
Q11: Multiple Classes in a Package and Importing
Objective: Organize related classes in a package and import them.
Problem Statement: Create package mathoperations with classes Addition and Subtraction. Use
them from a main class using import mathoperations.*;
Q12: Package with Subpackage and Access Modifiers
Objective: Understand package structure and public/private access across packages.
Problem Statement: Create package [Link] with class CollegeInfo (public) and
subpackage [Link] with class Utils (public). Demonstrate importing and using
both.
Q13: Creating Threads by Extending Thread Class
Objective: Create and run threads by extending Thread.
Problem Statement: Create two threads by extending Thread. One prints numbers 1-5, another
prints letters A-E. Start both threads.
Q14: Implementing Runnable and Thread Synchronization
Objective: Implement Runnable and demonstrate synchronization.
Problem Statement: Create a Counter class with synchronized increment() method. Create two
threads (Runnable) that call increment 5 times each on shared Counter. Print final value.
Q15: Thread Communication using wait() and notify()
Objective: Understand basic thread communication.
Problem Statement: Implement Producer-Consumer for a single integer buffer using wait() and
notify(). Producer produces 1..5, Consumer consumes and prints.
Q16: Simple Applet Drawing Shapes (Note: Applet deprecated in modern JDKs)
Objective: Learn basic applet graphics. (Run in appletviewer or compatible environment)
Problem Statement: Write an applet that draws a rectangle, circle and a line with different
colors.
Q17: Applet with Parameters (Sum of two numbers)
Objective: Use <param> tags to pass parameters to applet.
Problem Statement: Write an applet that reads two numeric parameters (num1 and num2) and
displays their sum. Use applet tag with <param> in an HTML file.
Q18: Interactive Applet with Mouse Events (Click to change color)
Objective: Handle basic events in applet (mouse) to change drawing behavior.
Problem Statement: Create an applet that changes the displayed message when the user clicks
on the applet area.