Exercices on Java Programming Language
Exercices on Java Programming Language
1. Basics of Java
2. Control Structures
Write a program to check if a number entered by the user is odd or even using an if-
else statement.
Use a switch statement to create a simple calculator that performs addition,
subtraction, multiplication, and division.
Write a program that prints the multiplication table of a number entered by the user
using a for loop.
Create a program to calculate the sum of all even numbers between 1 and 100 using a
while loop.
3. Arrays
Write a program to read 10 integers into an array, and print the sum and average of the
elements.
Create a program that sorts an array of integers in ascending order.
Implement a program to find the largest and smallest numbers in an array.
4. Strings
Write a program to check if a given string is a palindrome (reads the same forward and
backward).
Create a program that counts the number of vowels, consonants, digits, and whitespace
characters in a string.
Write a program that reverses a given string without using built-in methods.
5. Object-Oriented Programming
Create a class Person with attributes name, age, and gender. Add a method
displayInfo() to print the attributes. Create objects of the class and call the method.
Write a program that demonstrates inheritance. Define a base class Animal with a
method speak(). Derive a class Dog that overrides the speak() method.
Write a program that demonstrates polymorphism using method overloading (e.g.,
add(int, int) and add(float, float)).
6. Exception Handling
Write a program that handles division by zero errors using try-catch.
Create a program that demonstrates multiple catch blocks for different exceptions.
Write a custom exception class for invalid age input and use it in a program.
7. File Handling
Write a program to create a text file, write data into it, and read the data back to
display on the console.
Develop a program that counts the number of lines, words, and characters in a text
file.
Write a program to copy the contents of one file into another.
8. Collections Framework
9. Multithreading
Write a program to create a thread using Thread class and Runnable interface. Print
numbers from 1 to 10 in the thread.
Create a program that demonstrates the use of thread synchronization.
Write a program that simulates a producer-consumer problem using threads.
Additional Challenges
1. Write a program that simulates a library management system using classes and
collections (e.g., add books, issue books, return books).
2. Create a simple "To-Do List" application using ArrayList where users can add tasks,
mark tasks as complete, and remove tasks.
3. Write a program to implement a text-based Tic-Tac-Toe game for two players.
Bonus Challenge
Build a Java program that demonstrates the use of Java Swing to create a GUI for
managing employee records.