Name - Anupama
Course - [Link](CS) 6th sem
Enroll number - 230360
Subject - Java Programming
JAVA PROGRAMMING LAB FILE
Experiment 1
Java Basics and Environment Setup
Aim
To write and execute a simple Java program and understand the Java development
environment.
Algorithm
1. Start.
2. Create a Java class.
3. Define the main() method.
4. Print a message using [Link]().
5. Compile the program.
6. Execute the program.
7. Stop.
Program
class HelloWorld {
public static void main(String[] args) {
[Link]("Hello Java");
}
}
Output
Hello Java
Result
The Java program was compiled and executed successfully.
Experiment 2
Conditional Statements and Looping
Programs
Aim
To check whether a number is prime or not.
Algorithm
1. Start.
2. Read a number n.
3. Initialize count = 0.
4. Check divisibility from 1 to n.
5. If divisible, increment count.
6. If count = 2, number is prime.
7. Otherwise not prime.
8. Stop.
Program
import [Link];
class PrimeNumber {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
[Link]("Enter Number: ");
int n = [Link]();
int count = 0;
for(int i=1;i<=n;i++) {
if(n%i==0) {
count++;
}
}
if(count==2)
[Link]("Prime Number");
else
[Link]("Not Prime Number");
}
}
Output
Enter Number: 7
Prime Number
Result
Successfully checked whether a number is prime or not.
Experiment 3
Arrays and String Operations
Aim
To find the largest and smallest element in an array.
Algorithm
1. Start.
2. Read array elements.
3. Initialize max and min with first element.
4. Traverse array.
5. Update max and min accordingly.
6. Display results.
7. Stop.
Program
class LargestSmallest {
public static void main(String[] args) {
int arr[] = {10, 5, 20, 8, 30};
int max = arr[0];
int min = arr[0];
for(int i=1;i<[Link];i++) {
if(arr[i] > max)
max = arr[i];
if(arr[i] < min)
min = arr[i];
}
[Link]("Largest = " + max);
[Link]("Smallest = " + min);
}
}
Output
Largest = 30
Smallest = 5
Result
Successfully found the largest and smallest element in an array.
Experiment 4
String Reverse and Palindrome
Aim
To reverse a string and check whether it is palindrome.
Algorithm
1. Read string.
2. Reverse the string.
3. Compare original and reversed strings.
4. If equal, palindrome.
5. Else not palindrome.
Program
import [Link];
class Palindrome {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
String str = [Link]();
String rev = "";
for(int i=[Link]()-1;i>=0;i--) {
rev += [Link](i);
}
[Link]("Reverse = " + rev);
if([Link](rev))
[Link]("Palindrome");
else
[Link]("Not Palindrome");
}
}
Output
madam
Reverse = madam
Palindrome
Result
Successfully reversed a string and checked palindrome.
Experiment 5
Matrix Addition Using 2D Arrays
Aim
To perform matrix addition.
Algorithm
1. Create two matrices.
2. Traverse matrices.
3. Add corresponding elements.
4. Store result in third matrix.
5. Display result.
Program
class MatrixAddition {
public static void main(String[] args) {
int a[][] = {{1,2},{3,4}};
int b[][] = {{5,6},{7,8}};
int c[][] = new int[2][2];
for(int i=0;i<2;i++) {
for(int j=0;j<2;j++) {
c[i][j] = a[i][j] + b[i][j];
}
}
for(int i=0;i<2;i++) {
for(int j=0;j<2;j++) {
[Link](c[i][j]+" ");
}
[Link]();
}
}
}
Output
68
10 12
Result
Successfully performed matrix addition.
Experiment 6
Inheritance and Method Overriding
Aim
To demonstrate single inheritance and method overriding.
Program
class Vehicle {
void start() {
[Link]("Vehicle Started");
}
}
class Car extends Vehicle {
@Override
void start() {
[Link]("Car Started");
}
}
class Main {
public static void main(String[] args) {
Car c = new Car();
[Link]();
}
}
Output
Car Started
Result
Successfully demonstrated inheritance and method overriding.
Experiment 7
Multithreading Using Runnable Interface
Aim
To execute multiple tasks simultaneously using threads.
Program
class MyThread implements Runnable {
public void run() {
[Link]("Thread Running");
}
}
class Main {
public static void main(String[] args) {
Thread t = new Thread(new MyThread());
[Link]();
}
}
Output
Thread Running
Result
Successfully implemented multithreading.
Experiment 8
Collection Framework and Generics
Aim
To demonstrate ArrayList and Generics.
Program
import [Link].*;
class CollectionDemo {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
[Link]("Java");
[Link]("Python");
[Link]("C++");
for(String s : list) {
[Link](s);
}
}
}
MINI PROJECT
EMPLOYEE MANAGEMENT SYSTEM
1. Problem Statement
Develop a console-based Employee Management System using Core Java. The system should
allow users to add, view, search, update, and delete employee records.
2. Objectives
1. To implement Object-Oriented Programming concepts.
2. To use Collections Framework for data storage.
3. To perform CRUD operations.
4. To demonstrate exception handling.
5. To build a real-world console application using Core Java.
3. Software Requirements
● Java JDK 8 or Above
● VS Code / IntelliJ IDEA / Eclipse
● Command Prompt / Terminal
4. Project Structure
EmployeeManagementSystem/
├── [Link]
├── [Link]
├── [Link]
└── [Link]
5. Source Code
[Link]
public class Employee {
private int id;
private String name;
private double salary;
public Employee(int id, String name, double salary) {
[Link] = id;
[Link] = name;
[Link] = salary;
public int getId() {
return id;
public String getName() {
return name;
}
public double getSalary() {
return salary;
public void setName(String name) {
[Link] = name;
public void setSalary(double salary) {
[Link] = salary;
@Override
public String toString() {
return "ID: " + id +
" Name: " + name +
" Salary: " + salary;
[Link]
import [Link];
public class EmployeeManager {
private ArrayList<Employee> employees = new ArrayList<>();
public void addEmployee(Employee employee) {
[Link](employee);
[Link]("Employee Added Successfully.");
public void viewEmployees() {
if ([Link]()) {
[Link]("No Employees Found.");
return;
for (Employee employee : employees) {
[Link](employee);
public void searchEmployee(int id) {
for (Employee employee : employees) {
if ([Link]() == id) {
[Link](employee);
return;
[Link]("Employee Not Found.");
public void updateEmployee(int id,
String newName,
double newSalary) {
for (Employee employee : employees) {
if ([Link]() == id) {
[Link](newName);
[Link](newSalary);
[Link]("Employee Updated Successfully.");
return;
}
[Link]("Employee Not Found.");
public void deleteEmployee(int id) {
for (Employee employee : employees) {
if ([Link]() == id) {
[Link](employee);
[Link]("Employee Deleted Successfully.");
return;
[Link]("Employee Not Found.");
}
[Link]
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
EmployeeManager manager = new EmployeeManager();
while (true) {
[Link]("\n===== Employee Management System =====");
[Link]("1. Add Employee");
[Link]("2. View Employees");
[Link]("3. Search Employee");
[Link]("4. Update Employee");
[Link]("5. Delete Employee");
[Link]("6. Exit");
[Link]("Enter Choice: ");
int choice = [Link]();
switch (choice) {
case 1:
[Link]("Enter ID: ");
int id = [Link]();
[Link]();
[Link]("Enter Name: ");
String name = [Link]();
[Link]("Enter Salary: ");
double salary = [Link]();
[Link](
new Employee(id, name, salary));
break;
case 2:
[Link]();
break;
case 3:
[Link]("Enter Employee ID: ");
[Link]([Link]());
break;
case 4:
[Link]("Enter Employee ID: ");
int updateId = [Link]();
[Link]();
[Link]("Enter New Name: ");
String newName = [Link]();
[Link]("Enter New Salary: ");
double newSalary = [Link]();
[Link](
updateId,
newName,
newSalary);
break;
case 5:
[Link]("Enter Employee ID: ");
[Link]([Link]());
break;
case 6:
[Link]("Exiting...");
[Link](0);
default:
[Link]("Invalid Choice");
}
6. Compilation and Execution
Compile:
javac [Link] [Link] [Link]
Run:
java Main
7. Result
Successfully developed and executed an Employee Management System using Core Java
concepts such as classes, objects, constructors, encapsulation, collections framework, and
exception handling.