Java Lab Manual Improved
Java Lab Manual Improved
PART A
A.1 Aim:
To study and implement the concept of basic input/output and arithmetic operations in
Java programming language and understand its practical use in software development.
A.2 Prerequisite:
Before performing this experiment, students should have knowledge of:
A.3 Outcome:
After successful completion of this experiment, students will be able to:
A.4 Theory:
Java is a high-level, object-oriented, platform-independent programming language
developed by Sun Microsystems (now Oracle Corporation). It follows the principle of
"Write Once, Run Anywhere" (WORA), meaning that Java programs can run on any
platform that supports the Java Virtual Machine (JVM).
One of the most important aspects of programming is the ability to accept input from
users and process it to generate meaningful output. In Java, user input can be accepted
using the Scanner class available in the [Link] package.
A variable is a named memory location used to store data values. In this experiment,
integer variables are used to store the two numbers entered by the user.
The concept learned in this experiment forms the foundation for more advanced
programming tasks such as calculations, data processing, database operations, and
software development.
Task 1:
Analyze the role of the Scanner class and identify how user input is received and stored
in variables.
Task 2:
Modify the program to calculate the sum of three numbers instead of two and identify the
changes required in the code.
Experiment No. 1
PART B
[Link]();
}
}
B.4 Conclusion:
From this experiment, it can be concluded that Java provides simple and effective
mechanisms for accepting user input and performing arithmetic calculations. The Scanner
class enables interaction between the user and the program, while arithmetic operators
facilitate data processing.
The experiment helped students understand the basic structure of Java programs, variable
handling, and console-based interaction. These concepts serve as the foundation for
developing more complex software applications. Students gained confidence in writing,
compiling, and executing Java programs.
Why is the Scanner class required for taking input from the user?
Answer:
The Scanner class is used to take input from the keyboard.
It reads data entered by the user during program execution.
The input is stored in variables for processing.
It supports different data types like int, float, and String.
It makes Java programs interactive and user-friendly.
What is the difference between int, float, and double data types?
Answer:
int is used to store whole numbers without decimals.
float stores decimal numbers with single precision.
double stores decimal numbers with higher precision than float.
double is more accurate for calculations involving decimals.
The choice depends on the type of data being stored.
Can the program be modified to add more than two numbers? How?
Answer
Yes, the program can be modified to add more numbers.
Create additional variables for the extra inputs.
Use the Scanner class to read each number.
Add all the numbers using the + operator.
Display the final sum on the console.
PART A
A.1 Aim
To write a program to calculate the addition of two numbers using prototyping of
methods.
A.2 Prerequisite
A.3 Outcome
A.4 Theory
In Java, methods can accept data through parameters, process the data, and optionally
return a result. A method generally consists of:
Return Type
Method Name
Parameter List
Method Body
General syntax:
returnType methodName(parameters)
{ // statements
1. Code Reusability :A method can be called multiple times from different parts of the
program without rewriting the same code.
2. Reduced Complexity :Large programs become easier to understand when divided into
smaller methods.
3. Easy Maintenance :Changes made in a method automatically affect all places where it
is called.
4. Better Debugging:Errors can be identified and corrected more easily within a method.
In this experiment, a method named add() is created to perform the addition of two
numbers. The numbers are passed as arguments to the method. The method calculates
their sum and returns the result to the calling statement.
This experiment demonstrates how methods improve program organization and prepare
students for advanced concepts such as function overloading, recursion, inheritance, and
object-oriented software development.
Task 1
Analyze the role of parameters and return values in the add() method and explain how
data is transferred between the calling method and the called method.
Task 2
Modify the program to perform subtraction, multiplication, and division using separate
methods and compare the structure of the program with the original version.
Experiment No. 2
PART B
During the execution of the program, it was observed that the addition operation was
performed inside a separate method rather than directly within the main() method. The
values passed as arguments were successfully received by the method through
parameters, processed internally, and the result was returned to the calling statement.
The experiment provided practical exposure to the concept of methods and demonstrated
how software developers use methods to organize large applications efficiently.
B.4 Conclusion
From this experiment, it can be concluded that methods are one of the most important
building blocks of Java programming. They help organize programs into reusable and
manageable components, reducing redundancy and improving program structure.
The knowledge gained from this experiment serves as a foundation for advanced Java
concepts such as function overloading, recursion, interfaces, and object-oriented
application development.
Answer:
A parameter is a variable declared in a method definition.
An argument is the actual value passed to the method.
Parameters receive the values from arguments.
They help methods process different inputs.
Both are essential for method execution.
2. Why is a return statement important in a method?
Answer:
The return statement sends a value back to the calling method.
It ends the execution of the method.
The returned value can be used in further calculations.
It makes methods more useful and reusable.
It improves program efficiency.
Answer:
A method cannot return multiple values directly.
It can return an array or an object containing multiple values.
Another way is to use a collection like ArrayList.
These methods allow multiple values to be accessed together.
This improves data organization.
4. What is the difference between a method with a return type and a void method?
Answer:
A method with a return type returns a value.
A void method does not return any value.
The return type is specified before the method name.
A void method performs a task only.
Both methods are useful for different purposes.
Answer:
Methods divide a program into smaller modules.
They reduce code duplication.
Changes are made in one place only.
Debugging becomes easier and faster.
This makes software easier to maintain.
Answer:
Methods are used in banking applications.
They are used in e-commerce websites.
Mobile and desktop applications use methods extensively.
Hospital and student management systems also use methods.
Methods are essential in almost every software application
Experiment No. 3
PART A
A.1 Aim
A.2 Prerequisite
A.3 Outcome
A.4 Theory
Number of parameters
Data type of parameters
Order of parameters
Example:
average(10,20)
average(10,20,30)
Both methods perform average calculations but accept different numbers of parameters.
2. Code Reusability :Developers can use the same method name for related operations,
making programs easier to understand and maintain.
Method name
Number of arguments
Data type of arguments
Based on these factors, the compiler determines which version of the method should be
executed.
Mathematical calculations
Banking applications
Scientific software
Calculator programs
Enterprise applications
API development
In this experiment, two methods named average() are created. One method calculates the
average of two numbers, while the other calculates the average of three numbers. The
compiler automatically selects the appropriate method based on the arguments supplied.
Thus, this experiment demonstrates how Java supports method overloading and how it
simplifies software development.
Task 1
Analyze how the Java compiler differentiates between overloaded methods and identify
the parameter list used for each method call.
Task 2
Modify the program by creating another overloaded method to calculate the average of
four numbers and explain the changes required.
PART B
Roll No : 0818CL241108 Name: Kunal Patil
Program: [Link] AIML Second Year Division: AIML 2
Semester: IV Batch : B1
Date of Experiment: Date of Submission:
Grade :
return (a + b) / 2.0;
return (a + b + c) / 3.0;
}
B.2 Input and Output
During the execution of the program, it was observed that Java allows multiple methods
having the same name within the same class provided their parameter lists are different.
The compiler successfully identified the appropriate method based on the number of
arguments supplied during method invocation.
Methods can have the same name with different parameter lists.
The compiler selects the correct method during compilation.
Method overloading simplifies program design.
A single operation can be implemented for different input requirements.
Code becomes more readable and maintainable.
B.4 Conclusion
From this experiment, it can be concluded that method overloading is a powerful feature
of Java that enables multiple methods with the same name to perform related tasks. It
improves code readability, maintainability, and flexibility by allowing a single method
name to handle different parameter combinations.
Answer:
Method overloading means having multiple methods with the same name.
The methods must have different parameter lists.
It allows the same operation for different inputs.
It improves code readability and flexibility.
It is a feature of object-oriented programming.
Answer:
The compiler decides which method to call during compilation.
The decision is based on the parameter list.
No decision is made during program execution.
Therefore, it is called compile-time polymorphism.
It is also known as static polymorphism
Answer:
No, methods cannot be overloaded by changing only the return type.
The parameter list must be different.
The compiler ignores the return type when selecting methods.
Changing only the return type causes a compilation error.
Therefore, parameter changes are necessary.
Answer:
The compiler checks the method name.
It compares the number of arguments passed.
It also checks the data types of the arguments.
Then it selects the matching method.
This selection happens during compilation.
5. What are the advantages of method overloading in software development
Answer:
Method overloading improves code readability.
It reduces the need for multiple method names.
It increases code reusability.
It makes programs easier to maintain.
It provides flexibility in handling different inputs.
Experiment No. 4
PART A
A.1 Aim
A.2 Prerequisite
Instance variables
Methods in Java
Constructors
Parameter passing
Object-Oriented Programming fundamentals
A.3 Outcome
A.4 Theory
A constructor has the same name as the class and does not have any return type, not even
void.
Characteristics of Constructors
Types of Constructors
1. Default Constructor
Example:
Box() {
length = breadth = height = 1;
}
2. Parameterized Constructor
Example:
Box(int l, int b, int h) {
length = l;
breadth = b;
height = h;
}
Constructor Overloading
When a class contains more than one constructor with different parameter lists, it is
called Constructor Overloading.
Example:
2. Code Reusability :A single class can support multiple object creation scenarios.
3. Better Program Design “:It makes object initialization simple and organized.
4. Improved Readability :Programmers can easily understand how objects are created.
Volume of a Box
The formula for calculating the volume of a box is: V=l×b×hV = l \times b \times
hV=l×b×h
The calculated volume represents the total space occupied by the box.
Applications of Constructor Overloading
Banking applications
Student management systems
Inventory management systems
E-commerce applications
Database applications
Enterprise software development
In this experiment, two constructors are created to initialize box dimensions. One
constructor initializes default dimensions while the other initializes user-defined
dimensions. The volume is then calculated using the initialized values.
Task 1
Analyze how different constructors are invoked during object creation and identify the
values assigned to object attributes by each constructor.
Task 2
Modify the program by creating an additional constructor that accepts only one parameter
and initializes a cube. Explain how constructor overloading supports different object
initialization requirements.
PART B
Roll No : 0818CL241108 Name: Kunal Patil
Program: [Link] AIML Second Year Division: AIML 2
Semester: IV Batch : B1
Date of Experiment: Date of Submission:
Grade :
int length;
int breadth;
int height;
Box() {
length = 1;
breadth = 1;
height = 1;
length = l;
breadth = b;
height = h;
int calculateVolume() {
During the execution of the program, it was observed that constructors are automatically
called when objects are created. The default constructor initialized the dimensions of the
first box with predefined values, while the parameterized constructor initialized the
second box with user-specified values.
B.4 Conclusion
Answer:
A constructor is a special method used to initialize objects.
It has the same name as the class.
It is called automatically when an object is created.
It does not have a return type.
It initializes the object's data members.
Answer:
A constructor initializes an object.
A method performs a specific task.
A constructor has no return type.
A method may return a value.
A constructor is called automatically, while a method is called explicitly.
Answer:
Constructor overloading means having multiple constructors in the same class.
Each constructor has a different parameter list.
It allows different ways of creating objects.
The compiler selects the correct constructor automatically.
It improves flexibility in object creation.
Answer:
No, a constructor cannot return a value.
It does not have a return type.
Its purpose is to initialize the object.
Java automatically calls it during object creation.
Returning a value from a constructor is not allowed.
Answer:
It provides multiple ways to initialize objects.
It improves code flexibility.
It reduces code duplication.
It makes programs easier to understand.
It supports reusable and maintainable code.
Answer:
Constructor overloading uses multiple constructors with different parameters.
Method overloading uses multiple methods with the same name.
Constructors initialize objects.
Methods perform specific operations.
Both support compile-time polymorphism
Experiment No. 5
PART A
A.1 Aim
To write a program to show the details of students using the concept of inheritance.
A.2 Prerequisite
A.3 Outcome
A.4 Theory
The class whose properties are inherited is called the Parent Class, Base Class, or
Superclass.
The class that inherits those properties is called the Child Class, Derived Class, or
Subclass.
Inheritance promotes:
The extends keyword is used to establish the inheritance relationship between classes.
1. Code Reusability : Instead of writing the same code repeatedly, a child class can reuse
the members of the parent class.
2. Reduced Redundancy :Common features can be written once in the parent class and
shared among multiple child classes.
3. Easy Maintenance :Changes made in the parent class automatically become available
to child classes.
1. Single Inheritance
class A { }
class B extends A { }
2. Multilevel Inheritance : A class inherits from another derived class.
class A { }
class B extends A { }
class C extends B { }
3. Hierarchical Inheritance : Multiple child classes inherit from a single parent class.
class A { }
class B extends A { }
class C extends A { }
Java does not support multiple inheritance through classes to avoid ambiguity problems,
but it can be achieved using interfaces.
Consider:
Person
o Student
o Teacher
Every student is a person and every teacher is a person. Therefore, common properties
such as name, age, and address can be placed in the Person class and inherited by Student
and Teacher classes.
Applications of Inheritance
In this experiment, a parent class named Person contains common information, while a
child class named Student inherits these properties and displays student details.
The experiment demonstrates how inheritance promotes code reuse and simplifies
program development.
Task 1
Analyze the relationship between the parent class and child class and identify which
members are inherited by the child class.
Task 2
Modify the program by adding additional student information such as branch and
semester. Explain how inheritance reduces code duplication.
PART B
Roll No : 0818CL241108 Name : Kunal Patil
Program: [Link] AIML Second Year Division: AIML 2
Semester: IV Batch : B1
Date of Experiment: Date of Submission:
Grade :
void display() {
}
public static void main(String[] args) {
[Link]();
During the execution of the program, it was observed that the child class successfully
inherited the data members of the parent class. The Student class accessed the variable
name directly without redefining it, demonstrating the concept of code reusability.
The experiment clearly demonstrated how Java supports inheritance and how it simplifies
software development by creating hierarchical relationships among classes.
B.4 Conclusion
Students successfully learned how to create parent and child classes using the extends
keyword and how inherited members can be accessed by derived classes. The concept is
widely used in real-world software systems to develop scalable, efficient, and
maintainable applications.
Answer:
Inheritance is an OOP feature in Java.
It allows one class to inherit the properties of another class.
The child class reuses the parent class members.
It reduces code duplication.
It improves code reusability.
Answer:
The extends keyword creates an inheritance relationship.
It connects the child class to the parent class.
The child class can access inherited members.
It promotes code reuse.
It simplifies program development.
Answer:
A parent class contains common properties and methods.
A child class inherits those members.
The child class can also have its own members.
The parent class is also called the superclass.
The child class is also called the subclass.
Answer:
Java avoids ambiguity problems.
Multiple inheritance may create confusion when methods have the same name.
This is called the Diamond Problem.
Java uses interfaces to achieve multiple inheritance.
This keeps programs simple and reliable.
Answer:
Common code is written only once in the parent class.
The child class inherits the common members.
There is no need to rewrite the same code.
It reduces redundancy.
It makes programs easier to update.
Answer:
Java supports single inheritance.
It also supports multilevel inheritance.
Hierarchical inheritance is also supported.
Multiple inheritance is supported only through interfaces.
These types improve code organization.
Answer:
Inheritance is used in student management systems.
It is used in banking applications.
Hospital management software also uses [Link] and e-commerce
systems use it.
It is widely used in enterprise application
Experiment No. 6
PART A
A.1 Aim
A.2 Prerequisite
Access modifiers
Compilation and execution of Java programs
Basic Object-Oriented Programming concepts
Directory structure in Java
A.3 Outcome
A.4 Theory
A Package in Java is a mechanism used to organize related classes, interfaces, and sub-
packages into a single namespace. Packages help in managing large projects by grouping
similar classes together.
For example:
java
├── util
├── io
├── lang
├── net
Here:
1. Avoid Naming Conflicts :Two classes can have the same name if they belong to
different packages.
Example:
[Link]
[Link]
Both classes have the same name but belong to different packages.
Types of Packages
1. Built-in Packages
Examples:
[Link]
[Link]
[Link]
[Link]
[Link]
2. User-Defined Packages
package mypack;
Creating a Package
}
Step 3: Compile Package
javac -d . [Link]
Step 4: Import Package
import [Link];
Package Syntax
package package_name;
Example:
package mypack;
Importing a Package
Example:
import [Link];
or
import mypack.*;
Applications of Packages
Packages play a vital role in large software projects where hundreds or thousands of
classes are involved.
This experiment demonstrates how packages help organize Java applications efficiently.
Task 1
Analyze how packages help in avoiding class name conflicts in large software projects.
Task 2
Create another class inside the same package and explain how multiple related classes
can be organized within a package.
PART B
Roll No ; Kunal Patil Name; 0818CL241108
Program: [Link] AIML Second Year Division: AIML 2
Semester: IV Batch : B1
Date of Experiment: Date of Submission:
Grade :
import [Link];
[Link]();
Sample Input
No user input required
B.3 Observations and Learning
During the execution of the program, it was observed that Java allows classes to be
grouped into packages for better organization and management. The package class was
successfully imported into another program using the import statement and its methods
were accessed without any difficulty.
The experiment provided practical understanding of how Java applications are structured
and organized in professional software development environments.
Experiment No. 7
PART A
A.1 Aim
A.2 Prerequisite
A.3 Outcome
A.4 Theory
An Interface in Java is a reference type that contains method declarations and constants.
It is used to achieve abstraction and multiple inheritance in Java.
Interfaces define what a class should do, but not how it should do it. The actual
implementation of interface methods is provided by the class that implements the
interface.
An interface acts as a contract between the interface and the implementing class.
Achieve abstraction.
Support multiple inheritance.
Improve program flexibility.
Promote loose coupling.
Standardize behavior across different classes.
Declaration of Interface
Syntax:
interface InterfaceName {
methodDeclaration();
}
Example:
interface Shape {
void square(int x);
void cube(int x);
}
Implementing an Interface
Syntax:
The implementing class must provide definitions for all interface methods.
Example:
}
Achieving Abstraction : Abstraction means hiding implementation details and showing
only essential features.
Example:
When a user presses a button in an application, they know what it does but not how the
internal code works.
Multiple Inheritance Using Interfaces :Java does not support multiple inheritance through
classes, but it supports multiple inheritance through interfaces.
Example:
interface A { }
interface B { }
class C implements A, B { }
Advantages of Interfaces
In this experiment:
Task 1
Analyze the role of interfaces in achieving abstraction and identify how the implementing
class provides functionality for interface methods.
Task 2
Modify the interface by adding another method named fourthPower() and implement it in
the class. Explain how interfaces support extensibility.
PART B
Roll No; 0818CL241108 Name: Kunal Patil
Program: [Link] AIML Second Year Division: AIML 2
Semester: IV Batch : B1
Date of Experiment: Date of Submission:
Grade :
[Link](5);
[Link](5);
}
B.2 Input and Output
Sample Input
Number = 5
Sample Output
During the execution of the program, it was observed that the interface successfully
defined the behavior that must be implemented by the class. The implementing class
provided definitions for all declared methods and executed them correctly.
The experiment demonstrated how interfaces separate method declarations from their
implementations. Students gained practical understanding of abstraction and learned how
interfaces contribute to modular and maintainable software design.
B.4 Conclusion
From this experiment, it can be concluded that interfaces are an important feature of Java
used to achieve abstraction and multiple inheritance. They provide a mechanism for
defining common behavior while allowing different classes to implement that behavior in
their own way.
Students successfully learned how to declare interfaces, implement them in classes, and
override interface methods. The experiment highlighted the role of interfaces in creating
scalable, reusable, and loosely coupled software systems.
The knowledge gained from this experiment is fundamental for advanced Java
technologies such as JDBC, Servlets, Spring Framework, Android Development, and
Enterprise Application Development.
B.5 Questions of Curiosity
Answer:
An interface is a reference type in Java.
It contains method declarations and constants.
It is used to achieve abstraction.
Classes implement interfaces using the implements keyword.
Interfaces improve software flexibility.
Answer:
An interface contains only method declarations (except default/static methods).
A class contains both data members and method implementations.
Interfaces cannot be instantiated directly.
Classes can create objects.
Interfaces define behavior, while classes provide implementation.
Answer:
Interfaces promote abstraction.
They improve code reusability.
They support multiple inheritance.
They reduce dependency between classes.
They make software easier to maintain.
Answer:
The implements keyword is used to implement an interface.
It connects a class with an interface.
The class must define all interface methods.
It enables abstraction in Java.
It supports interface-based programming.
Answer:
Yes, a class can implement multiple interfaces.
Java supports multiple inheritance through interfaces.
The class must implement all interface methods.
This increases flexibility in programming.
It helps build modular applications.
6. Why is interface-based programming preferred in large applications?
Answer:
It reduces coupling between classes.
It improves code flexibility.
It makes software easier to extend.
It supports reusable components.
It simplifies maintenance in large projects.
Answer:
Interfaces hide implementation details.
They define only method declarations.
The implementation is provided by the class.
Users interact with the interface, not the implementation.
This improves program design.
Answer:
Interfaces are used in JDBC.
They are used in Android development.
Enterprise applications use interfaces extensively.
Spring Framework also uses interfaces.
They are common in banking and web applications.
Experiment No. 8
PART A
A.1 Aim
A.2 Prerequisite
A.3 Outcome
A.4 Theory
Exception Handling is a mechanism used to handle runtime errors so that the normal flow
of a program can be maintained.
An Exception is an unwanted event that occurs during program execution and disrupts
the normal execution flow of the program.
Division by zero
Array index out of bounds
Invalid user input
File not found
Null pointer access
1. Prevents Program Crashes : The program can continue execution even after an error
occurs.
Example:
int x = "Hello";
Example:
int result = 10 / 0;
3. Logical Errors : The program runs successfully but produces incorrect output.
Example:
instead of
}
catch
Used to handle the exception.
catch(Exception e) {
}
finally
Executes regardless of whether an exception occurs.
finally {
throw
Used to explicitly generate an exception.
throws
Used to declare exceptions.
// Risky code
}
catch(ExceptionType e) {
// Handling code
}
ArithmeticException
Example:
int result = 10 / 0;
Output:
Execution flow:
Real-World Applications
Banking Systems
ATM Applications
Online Payment Systems
Database Applications
Hospital Management Systems
Enterprise Software
Web Applications
Without exception handling, large software systems would frequently crash during
execution.
Task 1
Analyze how program execution changes when the division operation is placed inside
and outside the try block.
Task 2
Modify the program to handle multiple exceptions and identify how Java selects the
appropriate catch block during execution.
PART B
try {
int denominator = 0;
catch (ArithmeticException e) {
[Link]("Error: Division by zero is not allowed.");
}
Sample Input
Numerator = 100
Denominator = 0
Sample Output
Error: Division by zero is not allowed.
Program executed successfully.
B.3 Observations and Learning
During the execution of the program, it was observed that division by zero generated an
ArithmeticException. Instead of terminating abruptly, the exception was handled by the
catch block, allowing the program to continue execution normally.
B.4 Conclusion
From this experiment, it can be concluded that exception handling is an essential feature
of Java used to manage runtime errors effectively. It enables programs to handle
unexpected situations without crashing and ensures smooth execution.
Students successfully learned how to use try and catch blocks to handle
ArithmeticException caused by division by zero. The experiment highlighted the
importance of error handling in developing secure, reliable, and user-friendly software
applications.
The knowledge gained from this experiment is crucial for building enterprise-level
systems where fault tolerance and reliability are critical requirements.
A.1 Aim
A.2 Prerequisite
A.3 Outcome
A.4 Theory
A process may contain one or more threads. Each thread performs a specific task
independently while sharing the same memory space.
For example:
Every Java program contains at least one thread known as the Main Thread.
Example:
2. Faster Execution
4. Resource Sharing
1. New State
2. Runnable State
3. Running State
4. Blocked/Waiting State
5. Terminated State
Flow:
New → Runnable → Running → Waiting/Blocked → Terminated
}
}
[Link]();
}
}
Thread Scheduler
The JVM contains a thread scheduler that determines which thread executes at a
particular time.
Because scheduling is controlled by the JVM and operating system, thread execution
order may vary.
Applications of Multithreading
Operating Systems
Web Browsers
Gaming Applications
Banking Systems
Online Reservation Systems
Mobile Applications
Multimedia Software
Network Applications
In this experiment:
Task 1
Analyze the difference between calling start() and run() methods and explain how thread
execution changes in each case.
Task 2
Modify the program by creating a second thread and identify how multiple threads
execute concurrently.
PART B
Roll No. Name
Program: [Link] AIML Second Year Division: AIML 1
Semester: IV Batch : B1 /B2
Date of Experiment: Date of Submission:
Grade :
Sample Input
No user input required.
Sample Output
Main Thread Executed
Thread Execution : 1
Thread Execution : 2
Thread Execution : 3
Thread Execution : 4
Thread Execution : 5
Note: Output order may vary because thread scheduling is controlled by the JVM.
B.3 Observations and Learning
During the execution of the program, it was observed that a separate thread was created
and executed independently of the main thread. The thread executed the statements inside
the run() method while the main thread continued its execution.
B.4 Conclusion
Students successfully learned how to create and execute threads using the Thread class
and understood the role of the start() and run() methods. The experiment highlighted the
importance of multithreading in modern software development, where multiple tasks
often need to execute simultaneously.
The knowledge gained from this experiment forms the foundation for advanced concepts
such as thread synchronization, concurrency control, parallel processing, and distributed
computing.
A.1 Aim
A.2 Prerequisite
Exception handling
GUI programming using AWT/Swing
Relational Database Management Systems (RDBMS)
SQL commands (INSERT, UPDATE, DELETE, SELECT)
MySQL database basics
Java packages and libraries
A.3 Outcome
A.4 Theory
Introduction to JDBC
JDBC (Java Database Connectivity) is an API provided by Java that enables Java
applications to interact with relational databases such as MySQL, Oracle, SQL Server,
PostgreSQL, and others.
Connect to a database.
Execute SQL statements.
Retrieve data from tables.
Insert, update, and delete records.
Manage transactions.
Examples:
JDBC Architecture
Java Application
|
v
JDBC API
|
v
JDBC Driver
|
v
Database
JDBC Components
or
ResultSet rs =
[Link](query);
Step 6: Close Connection
[Link]();
GUI-Based Student Information System
Advantages of JDBC
1. Platform Independent
2. Database Independent
3. Secure Data Storage
4. Supports SQL Queries
5. Easy Database Integration
6. Widely Used in Enterprise Applications
Applications of JDBC
Banking Systems
Student Management Systems
Employee Management Systems
Hospital Management Systems
Inventory Systems
E-Commerce Platforms
In this experiment:
The experiment demonstrates integration of Java GUI applications with databases using
JDBC.
Task 1
Analyze the role of JDBC Driver, Connection, Statement, and ResultSet objects in
establishing communication between Java applications and databases.
Task 2
Modify the application to include functionality for updating and deleting student records
and explain the SQL queries required.
PART B
Roll No. Name
Program: [Link] AIML Second Year Division: AIML 1
Semester: IV Batch : B1 /B2
Date of Experiment: Date of Submission:
Grade :
StudentInfo() {
t1 = new JTextField();
t2 = new JTextField();
[Link](50,50,100,30);
[Link](180,50,150,30);
[Link](50,100,100,30);
[Link](180,100,150,30);
[Link](120,170,100,30);
add(l1);
add(t1);
add(l2);
add(t2);
add(save);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
[Link](
"[Link]");
Connection con =
[Link](
"jdbc:mysql://localhost:3306/studentdb",
"root",
"root");
String query =
"insert into student values(?,?)";
PreparedStatement ps =
[Link](query);
[Link](1,
[Link]([Link]()));
[Link](2,
[Link]());
[Link]();
[Link](
null,
"Record Saved Successfully");
[Link]();
} catch(Exception ex) {
[Link](ex);
}
}
});
setSize(450,350);
setLayout(null);
setVisible(true);
}
public static void main(String args[]) {
new StudentInfo();
}
}
B.2 Input and Output
Sample Input
Roll Number : 101
Student Name : Rahul Sharma
Sample Output
Record Saved Successfully
Database Table:
During the execution of the program, it was observed that JDBC successfully established
a connection between the Java application and the MySQL database. Student information
entered through the GUI form was stored in the database table using SQL queries.
B.4 Conclusion
From this experiment, it can be concluded that JDBC is an essential technology for
developing database-driven Java applications. It provides a standardized mechanism for
connecting Java programs with relational databases and performing data manipulation
operations.
The knowledge gained from this experiment forms the foundation for advanced
technologies such as Servlets, JSP, Hibernate, Spring Framework, and Enterprise Java
Applications.
1. What is JDBC?
2. Why is JDBC required in Java applications?
3. What is the role of a JDBC Driver?
4. What is the difference between Statement and PreparedStatement?
5. Why are databases important in software systems?
6. What is a ResultSet?
7. How does JDBC improve data management?
8. What are the advantages of using PreparedStatement over Statement?
9. Which databases can be connected using JDBC?
10. How is JDBC used in enterprise applications?
Experiment No. 12
PART A
A.1 Aim
A.2 Prerequisite
Java Applets
AWT components
Event handling basics
GUI programming concepts
A.3 Outcome
A.4 Theory
Button
Label
TextField
Checkbox
Choice
List
TextArea
These controls help create interactive applications where users can enter data, make
selections, and trigger actions.
Common AWT Controls
Applications
Online Forms
Educational Software
Banking Systems
Reservation Systems
GUI Applications
In this experiment, a button and text field are added to an applet to demonstrate user
controls.
Task 1
Analyze the role of different AWT controls and identify where each control is commonly
used.
Task 2
Modify the applet by adding additional controls such as Checkbox and Choice
components and explain their functionality.
PART B
Roll No. Name
Program: [Link] AIML Second Year Division: AIML 1
Semester: IV Batch : B1 /B2
Date of Experiment: Date of Submission:
Grade :
Label l1;
TextField t1;
Button b1;
t1 = new TextField(20);
b1 = new Button("Submit");
add(l1);
add(t1);
add(b1);
}
}
B.2 Input and Output
Sample Input
Enter Name: Rahul
Sample Output
Applet displays:
Label : Enter Name
Text Field
Submit Button
B.3 Observations and Learning
During the execution of the applet, it was observed that graphical controls could be easily
added using AWT components. The controls were displayed properly and allowed user
interaction.
B.4 Conclusion
From this experiment, it can be concluded that user controls are essential for developing
interactive applications. Java Applets provide support for various GUI components
through AWT.
Students successfully learned how to add controls to applets and create simple user
interfaces. The concept forms the foundation for advanced GUI development using
Swing and JavaFX.
A.1 Aim
A.2 Prerequisite
Event handling
GUI programming basics
AWT concepts
Methods and constructors
A.3 Outcome
A.4 Theory
Swing is a part of the Java Foundation Classes (JFC) and is used for developing
platform-independent graphical user interfaces.
Swing provides a rich set of GUI components that are more powerful and flexible than
AWT components.
Features of Swing
Platform Independent
Lightweight Components
Rich GUI Controls
MVC Architecture
Customizable Components
Common Swing Components
Advantages of Swing
Attractive GUI
Cross-platform support
Rich component library
Easy event handling
Professional application design
Applications of Swing
In this experiment, a simple Swing application is created using JFrame and JButton.
Task 1
Analyze the differences between AWT and Swing components and identify advantages
of Swing.
Task 2
Modify the application by adding labels and text fields to create a simple student
information form.
PART B
Roll No. Name
Program: [Link] AIML Second Year Division: AIML 1
Semester: IV Batch : B1 /B2
Date of Experiment: Date of Submission:
Grade :
Sample Input
No user input required.
Sample Output
A window titled "Swing Application"
containing a button "Click Me"
is displayed on the screen.
B.3 Observations and Learning
During the execution of the program, it was observed that Swing components provided a
graphical interface for user interaction. The JFrame acted as the main window and the
JButton was displayed successfully.
B.4 Conclusion
From this experiment, it can be concluded that Swing is a powerful framework for
developing graphical user interfaces in Java. It provides a rich set of components and
supports event-driven programming.
Students successfully learned how to create GUI windows and add Swing controls. The
concept serves as a foundation for developing professional desktop applications.
1. What is Swing?
2. How is Swing different from AWT?
3. What is the role of JFrame?
4. Why are Swing components called lightweight components?
5. What are the advantages of Swing?
6. How does Swing support platform independence?
7. What is event-driven programming?
8. Where are Swing applications commonly used?
Experiment No. 14
PART A
A.1 Aim
A.2 Prerequisite
A.3 Outcome
A.4 Theory
Introduction to Servlets
A Servlet is a Java program that runs on a web server and handles client requests.
Servlets are used to create dynamic web applications.
A Servlet receives requests from clients (typically web browsers), processes the requests,
and generates responses.
Traditional HTML pages are static and cannot process user requests dynamically.
Servlets provide:
Servlet Architecture
Client Browser
|
Request
|
Web Server (Tomcat)
|
Servlet
|
Response
|
Client Browser
Servlet Life Cycle
1. init()
This means:
User authentication
Shopping carts
Online registration systems
Banking applications
E-learning portals
Without session management, user information would be lost after every request.
In this experiment:
This experiment demonstrates how web applications preserve user information across
multiple requests.
Real-World Applications
Student Portals
Online Examination Systems
Banking Applications
E-Commerce Websites
Hospital Management Systems
Railway Reservation Systems
ERP Solutions
Task 1
Analyze how session management overcomes the stateless nature of HTTP and identify
scenarios where maintaining user state is essential.
Task 2
Modify the registration system to store additional student details such as branch,
semester, and email address, and explain how session attributes can be used to manage
this information.
PART B
Roll No. Name
Program: [Link] AIML Second Year Division: AIML 1
Semester: IV Batch : B1 /B2
Date of Experiment: Date of Submission:
Grade :
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
[Link]("text/html");
[Link]("<html>");
[Link]("<body>");
[Link]("<h2>");
[Link]( "Student Registration Successful");
[Link]("</h2>");
[Link]( "<p>Name : " + name + "</p>");
[Link]( "<p>Roll No : "+ roll + "</p>");
[Link]("</body>");
[Link]("</html>");
}
}
[Link]
<html>
<body>
<form action="StudentRegistrationServlet" method="post">
<br><br>
<br><br>
</form>
</body>
</html>
B.2 Input and Output
Sample Input
Student Name : Rahul Sharma
Roll Number : 101
Sample Output
Student Registration Successful
During the execution of the program, it was observed that the servlet successfully
processed the data submitted through the HTML form. The student details were received
through the HTTP request and stored within the session object.
B.4 Conclusion
From this experiment, it can be concluded that Java Servlets provide an effective
mechanism for developing dynamic web applications. Session management plays a
crucial role in maintaining user information across multiple interactions in a web
environment.
Students successfully learned how to process form data using servlets and how to use
HttpSession for preserving user information. The experiment highlighted the importance
of state management in web applications and demonstrated its practical implementation.
The knowledge gained from this experiment forms the foundation for advanced web
technologies such as JSP, JSTL, Spring MVC, Hibernate, and Enterprise Web
Application Development.
1. What is a Servlet?
2. Why are Servlets used in web applications?
3. What is the servlet life cycle?
4. Why is HTTP called a stateless protocol?
5. What is session management?
6. What is HttpSession?
7. How does a servlet process client requests?
8. What is the difference between GET and POST methods?
9. How are session attributes stored and retrieved?
10. Where is session management used in real-world applications?