Java Exercises
java exercises reading code teaches you the syntax; writing code makes it stick. work through these exercises in the playground above each
Introduction
Reading code teaches you the syntax; writing code makes it stick. Work through these exercises in the playground above each lesson — or in your IDE — until the patterns feel automatic.
Understanding the topic
Beginner
- Print numbers 1-100, but 'Fizz' for multiples of 3, 'Buzz' for 5, 'FizzBuzz' for both.
- Reverse a string without using
StringBuilder.reverse(). - Count vowels and consonants in a sentence.
- Find the largest element in an int[].
Syntax reference
Intermediate
- Implement an LRU cache backed by
LinkedHashMap. - Group a list of orders by customer using Streams.
- Detect if two strings are anagrams in O(n).
- Build a simple producer/consumer with
BlockingQueue.
Informative example
Advanced
- Implement a thread-safe rate limiter (token bucket).
- Stream a 10 GB log file and count error rates per minute.
- Write a tiny dependency-injection container in 100 lines.
- Build a JWT-protected REST endpoint with Spring Boot.
Real-world use
Mini-projects to put on your CV:
• E-commerce backend — products, cart, checkout, JWT auth.
• Task manager — users, projects, tasks, due dates, notifications.
• Authentication system — signup, login, password reset, 2FA.
Purpose of this lesson
Cement everything you've learned by writing real Java code from scratch.
Step-by-step explanation
- Understand the core idea behind Java Exercises.
- Walk through the runnable example and tweak it in the playground.
- Apply the pattern in a small Spring Boot or CLI exercise of your own.
- Re-read the common mistakes and interview Q&A to lock the concept in.
Interactive workflow diagram
Identify use case
Recognize when java exercises is the right tool for the problem.
Debugging tips
- Read the full stack trace — Java's exception messages name the offending class and line.
- Reproduce in the smallest possible
main()method before fixing in the real app. - Use IntelliJ's debugger breakpoints and 'Evaluate Expression' rather than scattering
System.out.
Optimization strategies
- Profile before optimizing — JFR (Java Flight Recorder) and async-profiler reveal real hotspots.
- Prefer immutable data and stream pipelines over hand-rolled loops when readability matters.
- Reach for the right JDK collection (ArrayList vs LinkedList vs ArrayDeque) before writing custom data structures.
Enterprise example
Teams at Netflix, Uber and Goldman Sachs apply Java Exercises daily — usually wrapped behind Spring Boot services with observability hooks (Micrometer + OpenTelemetry).
Interview questions & answers
Q1Explain Java Exercises in one minute.
Q2When would you avoid Java Exercises?
Summary
In this lesson you learned Java Exercises — the concept, syntax, a runnable example, and the production pitfalls to avoid. Apply it in the playground before moving on.