Java Lab Cycle Programs 2022

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

LAB CYCLE PROGRAMS

(Headings are given in bold font)

Cycle 1
1) Write a Java program to check whether a given number is prime or not.

2) Write a Java program to find the second smallest element in an array.

3) Write a Java program to display the transpose of a given matrix.

4) Matrix Multiplication

Write a Java program to multiply two given matrices.

5) Write a Java program that checks whether a given string is a palindrome or not.
Ex: MALAYALAM is palindrome.

6) Write a Java Program to find the frequency of a given character in a string.

7) Inheritance

Write a Java program which creates a class named 'Employee' having the following members: Name,
Age, Phone number, Address, Salary. It also has a method named 'printSalary( )' which prints the
salary of the Employee. Two classes 'Officer' and 'Manager' inherits the 'Employee' class. The 'Officer'
and 'Manager' classes have data members 'specialization' and 'department' respectively. Now, assign
name, age, phone number, address and salary to an officer and a manager by making an object of
both of these classes and print the same.

8) Abstract Class

Write a java program to create an abstract class named Shape that contains an empty
method named numberOfSides( ). Provide three classes named Rectangle, Triangle and
Hexagon such that each one of the classes extends the class Shape. Each one of the classes
contains only the method numberOfSides( ) that shows the number of sides in the given geometrical
structures.

Cycle 2

9) Exception Handling

Write a Java program that shows the usage of try, catch, throws and finally.

10) File Handling using FileInputStream and FileOutputStream classes

Write a Java program that reads from a file and writes to a file by handling all file related exceptions.
(Using FileInputStream and FileOutputStream classes)

11) File Handling using FileReader and FileWriter classes

Write a Java program using reader/writer class that displays the number of characters, lines and
words in a text file.

12) String Tokenizer

Write a Java program that reads a line of integers, and then displays each integer, and the
sum of all the integers (Use String Tokenizer class of java.util).
Cycle 3

13) Doubly Linked List

Write a java program for the following:

1) Create a doubly linked list of elements.


2) Delete a given element from the above list.
3) Display the contents of the list after deletion.
14) Quick sort

Write a Java program that implements Quick sort algorithm for sorting a list of names in ascending
order.

15) Square and Cube of a Number using Thread Synchronization

Write a Java program that implements a multi-threaded program which has three threads. First thread
generates a random integer every 1 second. If the value is even, second thread computes the square
of the number and prints. If the value is odd the third thread will print the value of cube of the number.
Use thread Synchronization.

16) Simple Calculator using Swing

Write a Java program that works as a simple calculator. Arrange Buttons for digits and the + - * %
operations properly. Add a text field to display the result. Handle any possible exceptions like divide
by zero. Use Java Swing.

17) Traffic Light Simulation using Swing

Write a Java program that simulates a traffic light. The program lets the user select one of three lights:
red, yellow, or green. When a radio button is selected, the light is turned on, and only one light can be
on at a time. No light is on when the program starts.

You might also like