Java Lab (AL 406) Lab Manual June 2025 For ALS1 ALS2
Java Lab (AL 406) Lab Manual June 2025 For ALS1 ALS2
Acropolis Institute of
Technology and
Research, Indore
Department of CSE
Submitted To:
(Artificial Intelligence & Machine
Mr. Dharmendra Singh Chouhan
Learning)
Submitted By:
Name of Student
Enrollment No. : 0827
Class/Year/Sem : ALS-/2nd / 4th
The Objective of this laboratory work is to strengthen the ability of the students to identify
and apply the suitable Java Programming for the given real world problem. It enables them to
gain knowledge in practical applications of Java Programming.
ACROPOLIS INSTITUTE OF TECHNOLOGY & RESEARCH,
INDORE
CERTIFICATE
This is to certify that the experimental work entered in this journal as per
the B. TECH. II year syllabus prescribed by the RGPV was done by Mr./
Java Lab (AL-406) Laboratory of this institute during the academic year
2024- 2025.
The Java Programming Lab is designed to provide students with a strong foundation in object-
oriented programming using Java. Through practical exercises and real-time coding sessions,
students will develop the skills needed to design, implement, and debug Java programs.
This lab complements the core Java programming course by offering a hands-on learning
environment where students apply theoretical concepts to solve real-world problems. Students will
explore object-oriented principles such as encapsulation, inheritance, polymorphism, and
abstraction, and implement these concepts in various Java applications.
Writing and executing Java programs to solve computational and logical problems.
Working with packages, interfaces, exception handling, multithreading, file I/O, and GUI
development using AWT.
Utilizing modern IDEs and Java Development Kit (JDK) on the latest platforms for coding,
compiling, and debugging.
This lab enables students to build strong programming logic, structured code development skills,
and prepares them for advanced courses and industry-level software development.
GENERAL INSTRUCTIONS FOR LABORATORY CLASSES
DO’S
While entering into the LAB students should wear their ID cards.
Students should sign in the LOGIN REGISTER before entering into the
laboratory.
Students should come with observation and record note book to the laboratory.
After completing the laboratory exercise, make sure to shutdown the system
properly.
DONT’S
Module3: The Applet Class: Applet Basics, The Applet Class, Applet Architecture,
Applet Initialization and Termination, Simple Applet Display Methods, Simple Banner
Applet, Usingthe Status Window, The HTML APPLET Tag, Passing Parameters to
Applets, Improving the Banner Applet.
Module4: Introducing the AWT: Working with Windows, Graphics, and Text, AWT
Classes, Window Fundamentals, Component, Container, Panel, Frame, Working with
Frame Windows, Handling Events in a Frame Window, AWT Controls, Layout
Managers, and Menus, Adding and Removing Controls, Grid Layout, Border Layout,
introduction to swing and servlet.
Module5: Event Handling, Two Event Handling Mechanisms, The Delegation Event
Model, Events, Event Sources, Event Listeners, Event Classes, The Mouse Event Class
and others, JDBC: JDBCODBC Bridge, the connectivity model, the driver manager,
navigating the result set object contents, the JDBC exceptional classes, connecting to
remote database.
PREREQUISITE:-
Basic knowledge of programming in C/C++ is preferred. Prior understanding of object-
oriented principles is helpful but not mandatory.
Course Objectives
Course Outcomes
Additional remarks
Tutor
1 Title
Implementation of a Simple Calculator using Switch-Case in Java
2 Neatly Drawn and labeled experimental setup
3 Theoretical solution of the instant problem
3.1 Algorithm
Start
2. Prompt the user to enter two numbers and an operator (+,
-, *, /)
3. Use a switch-case structure to perform the operation based
on the operator:
• + ➝ Addition
• - ➝ Subtraction
• * ➝ Multiplication
• / ➝ Division (check for divide by zero)
4. Display the result
5. Stop
3.2 Program
import java.util.Scanner;
switch (operator) {
case '+':
result = num1 + num2;
System.out.println("Result: " + result);
break;
case '-':
result = num1 - num2;
System.out.println("Result: " + result);
break;
Page 10
case '*':
result = num1 * num2;
System.out.println("Result: " + result);
break;
case '/':
if (num2 != 0) {
result = num1 / num2;
System.out.println("Result: " + result);
} else {
System.out.println("Error: Cannot divide by zero.");
}
break;
default:
System.out.println("Invalid operator!");
}
sc.close();
}
}
4 Tabulation Sheet
INPUT OUTPUT
5
10,5,+ 15.0
20,4,/ 5.0
7,3,* 21.0
Results
The program successfully accepts two numbers and an operator
from the user and performs the correct arithmetic operation using a
switch-case. It also handles invalid operators and division by zero
cases.
Page 11
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine
Learning)
Group / Title: Demonstration of Class and Object
using a Student Class in Java
Lab: Java Lab (AL-406)
Additional remarks
Tutor
1 Title
Demonstration of Class and Object using a Student Class in Java
2 Neatly Drawn and labeled experimental setup
Page 12
3 Theoretical solution of the instant problem
3.1 Algorithm
1. Start
2. Define a class named Student
•Declare instance variables: name, roll number, and marks
• Define a method display() to show details
1. Create an object of the Student class in the main() method
2. Assign values to the object
3. Call the display() method to show student data
4. Stop
3.2 Program
class Student {
String name;
int rollNo;
double marks;
// Assigning values
s1.name = "Anubhi Jain";
s1.rollNo = 101;
s1.marks = 92.5;
Page 13
4 Tabulation Sheet
INPUT OUTPUT
5
“Anil Jain”, 101, 92.5 Student Name: Anil Jain
Roll Number: 101
Marks: 92.5
Results
Page 14
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine
Learning)
Group / Title: Implementation of Single,
Multilevel, and Hierarchical Inheritance using
Lab: Java Lab (AL-406) Animal, Dog, and Cat Classes in Java
Additional remarks
Tutor
1 Title
Implementation of Single, Multilevel, and Hierarchical Inheritance
using Animal, Dog, and Cat Classes in Java
Page 15
3 Theoretical solution of the instant problem
3.1 Algorithm
Start
2. Create a base class Animal with a method eat()
3. Derive Dog and Cat classes from Animal (Hierarchical
Inheritance)
4. Derive a Puppy class from Dog (Multilevel Inheritance)
5. In each derived class, create specific methods (e.g., bark(),
meow(), weeping())
6. In the main() method, create objects of each class and call their
respective methods
7. Stop
3.2 Program
// Base class
class Animal {
void eat() {
System.out.println("Animal is eating...");
}
}
// Multilevel Inheritance
class Puppy extends Dog {
void weep() {
System.out.println("Puppy is weeping...");
}
}
// Hierarchical Inheritance
class Cat extends Animal {
void meow() {
System.out.println("Cat is meowing...");
}
}
Page 16
public class InheritanceDemo {
public static void main(String[] args) {
// Single Inheritance
Dog dog = new Dog();
dog.eat(); // from Animal
dog.bark(); // from Dog
System.out.println();
// Multilevel Inheritance
Puppy puppy = new Puppy();
puppy.eat(); // from Animal
puppy.bark(); // from Dog
puppy.weep(); // from Puppy
System.out.println();
// Hierarchical Inheritance
Cat cat = new Cat();
cat.eat(); // from Animal
cat.meow(); // from Cat
}
}
4 Tabulation Sheet
CLASS METHOD OUTPUT
OBJECT CALLED
Dog eat(), bark() Animal is eating…Dog is barking…
Puppy eat(), bark(), Animal is eating…Dog is barking…Puppy
weep() is weeping…
Cat eat(), meow() Animal is eating…Cat is meowing…
5 Results
The program successfully demonstrates:
•Single Inheritance through the Dog class,
•Multilevel Inheritance via the Puppy class extending Dog,
•Hierarchical Inheritance using both Dog and Cat extending the
common Animal base class.
Page 17
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine
Learning)
Group / Title: Demonstration of Constructor
Chaining using this and super Keywords in Java
Lab: Java Lab (AL-406)
Additional remarks
Tutor
1 Title
Demonstration of Constructor Chaining using this and super
Keywords in Java
2 Neatly Drawn and labeled experimental setup
Page 18
3 Theoretical solution of the instant problem
3.1 Algorithm
1. Start
2. Create a base class Person with a parameterized constructor
3. Create a derived class Student that extends Person
4. Define multiple constructors in Student
1. Use this() to call another constructor of the same class
2. Use super() to invoke the parent class constructor
5. Create a main() method and instantiate the Student class
6. Observe constructor call order through printed messages
7. Stop
3.2 Program
class Person {
Person(String name) {
System.out.println("Person constructor called. Name: " + name);
}
}
// Derived class
class Student extends Person {
Student() {
this("John", 101); // Calls another constructor in the same class
System.out.println("Default Student constructor called.");
}
Page 19
4 Tabulation Sheet
CONSTRUCTOR OUTPUT
CALL
new Student() Person constructor called. Name:
John
Student constructor called. Roll
No: 101
Default Student constructor
called.
5 Results
The program demonstrates constructor chaining in Java:
• this() is used to invoke another constructor of the same class
• super() is used to call the constructor of the parent class
This confirms how Java manages constructor execution order in
inheritance and overloading.
Page 20
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine
Learning)
Group / Title: Implementation of Abstract Class
Shape and its Extension in Circle Class
Lab: Java Lab (AL-406)
Additional remarks
Tutor
1 Title
Implementation of Abstract Class Shape and its Extension in Circle
Class
Page 21
2 Neatly Drawn and labeled experimental setup
// Concrete subclass
class Circle extends Shape {
double radius;
Circle(double r) {
radius = r;
}
Page 22
}
4 Tabulation Sheet
INPU OUTPUT
T
5.0 Area of Circle:
78.53981633974483
3.5 Area of Circle:
38.48451000647496
2.0 Area of Circle:
12.566370614359172
5 Results
The program successfully demonstrates the use of abstract classes
and method overriding.
The abstract class Shape provides a general structure, and Circle
provides a concrete implementation of the area() method.
Page 23
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine
Learning)
Group / Title: Implementation of Interface in Java using Vehicle,
Lab: Java Lab (AL-406) Car, and Bike classes.
Additional remarks
Page 24
Grade: Cross the grade.
A B C D F
Tutor
6 Title: Implementation of Interface in Java using Vehicle, Car, and Bike classes.
7 Neatly Drawn and labeled experimental setup:
Page 25
8.2 Program:
// Interface definition
interface Vehicle {
void start();
void stop();
}
// Main class
public class InterfaceDemo {
Page 26
public static void main(String[] args) {
Vehicle car = new Car();
Vehicle bike = new Bike();
System.out.println("Car actions:");
car.start();
car.stop();
System.out.println("\nBike actions:");
bike.start();
bike.stop();
}
}
9 Tabulation Sheet
INPUT OUTPUT
Car actions:
Car has started.
Car has stopped.
Bike actions:
Bike has started.
Bike has stopped.
Page 27
1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work
Additional remarks
Tutor
Page 28
interface A {
void methodA();
}
// Interface B
interface B {
void methodB();
}
// Main class
public class MultipleDemo {
public static void main(String[] args) {
MyClass obj = new MyClass();
obj.methodA();
obj.methodB();
}
}
4 Tabulation Sheet
INPUT OUTPUT
5
Method A from Interface A
Method B from Interface B
Page 29
Results: The experiment demonstrates that Java allows multiple inheritance through interfaces.
The class MyClass successfully implements both interfaces A and B without any ambiguity
or conflict.
Additional remarks
Page 30
Grade: Cross the grade.
A B C D F
Tutor
1 Title: Demonstration of Method Overriding in Java using Vehicle and Bike Classes.
2 Neatly Drawn and labeled experimental setup:
3.2 Program:
// Parent class
class Vehicle {
void run() {
System.out.println("Vehicle is running");
}
Page 31
}
// Main class
public class OverrideDemo {
public static void main(String[] args) {
Vehicle obj = new Bike(); // Upcasting
obj.run(); // Calls the overridden method in Bike
}
}
4 Tabulation Sheet
INPUT OUTPUT
Bike is running safely
5
Page 32
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine
Learning)
Group / Title: Demonstration of Method Overloading in Java
Lab: Java Lab (AL-406)
using Calculator Class.
EVALUATION RECORD Type/ Lab Session:
Name Enrollment No. 0827AL
Performing on First submission Second submission
Extra Regular
Additional remarks
Page 33
Grade: Cross the grade.
A B C D F
Tutor
Page 34
3.2 Program:
// Class with overloaded add() methods
class Calculator {
int add(int a, int b) {
return a + b;
}
// Main class
public class OverloadDemo {
public static void main(String[] args) {
Calculator calc = new Calculator();
INPUT OUTPUT
(10,20) Addition of 2 integers: 30
(5.5,6.3) Addition of 2 doubles: 11.8
(1,2,3) Addition of 3 integers: 6
Page 35
5 Results: This experiment successfully demonstrates method overloading. The
Calculator class has multiple add() methods, and the correct one is chosen based
on the number and types of arguments provided at compile time.
Additional remarks
Page 36
Tutor
3.2 Program:
// Custom exception class
class CustomException extends Exception {
public CustomException(String message) {
super(message);
}
Page 37
}
// Main method
public static void main(String[] args) {
try {
checkNumber(10);
checkNumber(-5); // This will throw the exception
} catch (CustomException e) {
System.out.println("Caught Custom Exception: " + e.getMessage());
}
}
}
4 Tabulation Sheet
INPUT OUTPUT
Valid number: 10
5
Caught Custom Exception: Negative
numbers are not allowed!
Results: The experiment demonstrates how to define and use a custom exception
Page 38
class in Java. The program successfully throws and catches an exception based on
specific business logic (negative number check).
Page 39