Practice Java Exercises & Challenges with Solutions [575+ Coding Questions]
Free Coding Exercises for Java Developers. Practice Java with 21 topic-wise exercises with over 576 coding questions covering everything from Java basics to advanced topics like data structures, JDBC, and reflection.
What is included in these Java Exercises?
- All exercises are tested on Java 8 and above.
- Each exercise contains 20-40 coding questions or challenges, focusing on specific Java topics to give you targeted practice
- Hints and solutions are provided for every question. This enables you to immediately check your code and learn from any mistakes
- Practice each Exercise using our Online Java Compiler.
Whether you're a beginner taking your first steps or an experienced developer looking to refine your skills, these exercises are designed to be beneficial.
Below is the list of exercises. Select the exercise you want to solve. All the Best.
Basic Java Exercises for Beginners
Total Exercises: 38
This Java beginner's exercise helps you quickly learn and practice basic skills by solving coding questions and challenges on the below topics.
Topics: Java Basics, Variables, Operators, Conditionals, Loops, Arrays
Java Loops Exercises
Total Exercises: 40
This exercise contains coding challenges to solve using if-else conditions, for loops, and while loops, including number patterns and array-based problems.
Topics: Control flow statements, for loop, while loop
Java String Exercises
Total Exercises: 30
Solve Java string coding questions to learn and practice string operations, manipulations, and pattern-matching techniques.
Topic: Java String
Java ArrayList Exercises
Total Exercises: 30
This exercise contains coding questions to learn and practice ArrayList operations, manipulations, sorting, searching, and functions.
Topic: Java ArrayList
Java LinkedList Exercises
Total Exercises: 25
Practice and solve various LinkedList operations and manipulations using both the built-in java.util.LinkedList and a custom Node-based list.
Topic: Java LinkedList
Java HashMap and TreeMap Exercises
Total Exercises: 25
Practice coding questions on Java's Map interface, including HashMap, TreeMap, and LinkedHashMap, to work with key-value data structures.
Topics: HashMap, TreeMap, LinkedHashMap
Java HashSet and TreeSet Exercises
Total Exercises: 25
Practice and solve various Set operations, manipulations, and navigation methods using HashSet and TreeSet.
Topics: HashSet, TreeSet
Java OOP Exercises
Total Exercises: 40
This Java Object-Oriented Programming (OOP) exercise helps developers learn and practice encapsulation, inheritance, polymorphism, and abstraction concepts.
Topics: OOP, Classes, Inheritance, Polymorphism
Java Methods Exercises
Total Exercises: 21
Practice how to create a method, overload it, use varargs and recursion, and pass arguments effectively in Java by solving different questions.
Topics: Methods, Overloading, Recursion, Pass-by-value
Java Enums Exercises
Total Exercises: 12
Practice and solve coding questions to learn how to declare and use enums, including constant-specific behavior, interfaces, and the enum singleton pattern.
Topic: Enums
Java Exception Handling Exercises
Total Exercises: 20
This exercise contains coding questions to gain proficiency in exception handling, including try-catch blocks, custom exceptions, and try-with-resources.
Topic: Exception Handling
Java File Handling Exercises
Total Exercises: 32
Exercises contain coding questions to gain proficiency in file operations such as reading, writing, renaming, copying, and deleting files, and working with NIO.
Topic: File Handling
Java Date and Time Exercises
Total Exercises: 30
This exercise aims to help Java developers learn and practice date, time, and duration coding problems using the modern java.time API.
Topic: Date and Time
Java Data Structures Exercises
Total Exercises: 30
Practice coding questions on widely used data structures, such as arrays, linked lists, stacks, queues, trees, heaps, and graphs, built from scratch.
Topic: Data Structures
Java Sorting and Searching Exercises
Total Exercises: 35
This exercise provides Java sorting and searching algorithm coding practice questions, covering Bubble, Merge, and Quick Sort, along with binary search variations.
Topics: Sorting Algorithms, Searching Algorithms
Java Lambda and Functional Interfaces Exercises
Total Exercises: 25
Practice Java lambda expressions and functional interfaces through exercises covering Predicate, Function, Supplier, Consumer, and the Stream API.
Topics: Lambda expressions, Functional Interfaces, Streams
Java Regex Exercises
Total Exercises: 30
This regex exercise set helps you build hands-on experience with pattern matching through exercises progressing from basic matching to advanced text extraction.
Topic: Regex
Java Random Data Generation Exercises
Total Exercises: 25
Practice and solve coding questions to learn the various techniques to generate random data in Java.
Topics: Random class, SecureRandom, ThreadLocalRandom
Java Generics Exercises
Total Exercises: 20
Practice Java generics through exercises on generic classes and methods, bounded type parameters, and wildcards, from beginner to advanced level.
Topic: Generics
Java Reflection Exercises
Total Exercises: 20
Practice coding questions to inspect and manipulate classes, fields, methods, and constructors at runtime using Java's Reflection API.
Topic: Reflection
Java JDBC Database Exercises
Total Exercises: 20
Solve database coding problems to master JDBC operations step by step, using connections, prepared statements, transactions, and the DAO pattern.
Use any of MySQL, PostgreSQL, or SQLite to solve the exercise.