Basic Exercises JAVA
Basic Exercises JAVA
Write a program that takes two numbers as input and prints their sum.
Write a program to calculate the area of a circle given its radius. Use the formula: Area = π * radius *
radius.
Temperature Converter:
Write a program that converts temperature from Celsius to Fahrenheit. The formula is: Fahrenheit =
(Celsius * 9/5) + 32.
Factorial Calculator:
Write a program to calculate the factorial of a given number. The factorial of a number is the product of
all positive integers less than or equal to that number.
Fibonacci Series:
Reverse a String:
Write a program that acts as a simple calculator, capable of performing addition, subtraction,
multiplication, and division.
Intermediate Exercises:
Matrix Addition:
Matrix Multiplication:
Sorting Algorithms:
Implement various sorting algorithms such as Bubble Sort, Selection Sort, Insertion Sort, etc., and use
them to sort arrays of integers.
File Handling:
Write a program to read data from a file, perform some operations, and write the results back to
another file.
Implement a singly linked list and perform basic operations like insertion, deletion, and traversal.
Stack Implementation:
Implement a stack data structure and perform basic operations like push, pop, peek, and isEmpty.
These exercises cover a range of topics and difficulty levels, helping beginners build a solid foundation in
Java programming.
Use classes like File, FileReader, or BufferedReader to read data from a text file line by line or character
by character.
Writing to a File:
Use classes like File, FileWriter, or BufferedWriter to write data to a text file.
Java provides FileInputStream and FileOutputStream for reading and writing binary data from and to
files.
Exception Handling:
Proper exception handling is crucial when dealing with file operations, as files may not always be
accessible or may not exist.
Word Counter:
Write a program that reads a text file and counts the number of words in it. Exclude punctuation marks
and consider spaces as word separators.
File Copy:
Create a program that copies the contents of one text file into another.
File Concatenation:
Write a program that concatenates the contents of two text files into a single text file.
File Encryption/Decryption:
Implement a simple encryption/decryption algorithm to encode and decode the contents of a text file.
File Search:
Write a program that searches for a specific word or phrase within a text file and prints the line numbers
where it occurs.
CSV Parser:
Create a program that reads data from a CSV (Comma Separated Values) file, parses it, and performs
some operations like calculating averages, finding maximum/minimum values, etc., on the data.
File Compression/Decompression:
Implement a simple file compression algorithm to compress the contents of a text file and then
decompress it back to its original form.
Serialization/Deserialization:
Learn about Java's Serialization API and write a program to serialize objects into a file and deserialize
them back.
File Information:
Write a program that displays information about a file, such as its size, last modified timestamp,
permissions, etc.
Log Analyzer:
Create a program that reads a log file generated by another application, parses the log entries, and
extracts useful information like error messages, timestamps, etc.
These exercises will help you become familiar with various aspects of file handling in Java while also
enhancing your programming skills. Feel free to explore additional features and functionalities as you
become more comfortable with file handling concepts in Java