0% found this document useful (0 votes)
3 views2 pages

Exercices on Java Programming Language

The document contains a comprehensive set of exercises for learning Java programming, organized into categories such as Basics, Control Structures, Arrays, Strings, Object-Oriented Programming, Exception Handling, File Handling, Collections Framework, Multithreading, and Advanced Topics. Each category includes specific programming tasks aimed at developing various skills, from basic syntax to advanced concepts like generics and GUI development. Additional challenges and a bonus challenge are also provided to further enhance learning and application of Java programming skills.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
3 views2 pages

Exercices on Java Programming Language

The document contains a comprehensive set of exercises for learning Java programming, organized into categories such as Basics, Control Structures, Arrays, Strings, Object-Oriented Programming, Exception Handling, File Handling, Collections Framework, Multithreading, and Advanced Topics. Each category includes specific programming tasks aimed at developing various skills, from basic syntax to advanced concepts like generics and GUI development. Additional challenges and a bonus challenge are also provided to further enhance learning and application of Java programming skills.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

EXERCICES ON Java PROGRAMMING LANGUAGE

Exercises on Java Programming

1. Basics of Java

 Write a program that prints "Welcome to Java Programming!" to the console.


 Declare variables of types int, float, boolean, and String. Assign values to them
and print their values along with their types.
 Write a program to calculate the area and perimeter of a rectangle, taking input from
the user.

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

 Write a program to demonstrate the use of ArrayList by adding, removing, and


iterating through elements.
 Create a program that uses a HashMap to store key-value pairs and demonstrates
methods like put(), get(), and remove().
 Write a program that uses a TreeSet to store unique values in sorted order.

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.

10. Advanced Topics

 Create a program that demonstrates the use of generics with a GenericClass<T> to


store and retrieve data of any type.
 Write a program that fetches JSON data from a public API using the
HttpURLConnection class.
 Implement a program using JavaFX to create a graphical user interface (GUI) for a
basic calculator.

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.

You might also like