Java Exercises
Practice Java with hands-on exercises designed to reinforce key concepts across all modules and difficulty levels. From beginner fundamentals to advanced topics, each exercise helps you apply what you’ve learned through real coding scenarios.
Use the filters to quickly find exercises by module and level, focus on specific areas, and progress at your own pace. Each exercise includes clear objectives, input/output examples, and starter code(when applicable) to guide your implementation.
Build your skills, gain confidence, and move from theory to practice with structured, real-world Java exercises.
Most Frequent Character
Return the most frequent character in a string.
aabbbcOutput:
b
Check Anagram
Check if two strings are anagrams.
listen, silentOutput:
TRUE
Reverse String
Reverse a string without using a loop.
javaOutput:
avaj
Count Vowels
Count the number of vowels in a string.
helloOutput:
2
String Length Without Built-in
Compute the length of a string without using length().
helloOutput:
5
Flatten 2D Array
Convert a 2D array into a single list where each item preserves its position.
[[1,2],[3,4]]Output:
[1,2,3,4]
Rotate Array Right
Rotate an array to the right by one position.
[1,2,3,4]Output:
[4,1,2,3]
Find Duplicate Element
Return the first duplicate value in an array.
[1,2,3,2]Output:
2
Diagonal Sum Matrix
Compute the sum of the main diagonal of a square matrix.
[[1,2],[3,4]]Output:
5
Matrix Row Sum
Compute the sum of each row in a 2D array.
[[1,2],[3,4]]Output:
[3,7]