Explore a concept. Read the code. Predict the result. Run it yourself.
A collection of focused Java programs for building language fundamentals, exploring modern features and revising for technical interviews. Browse examples across object-oriented programming, collections, streams, concurrency and Java features through Java 21.
Quick start · Topic explorer · Learning paths · Interview revision · Project structure
- Core Java: variables, types, control flow, strings and exception handling.
- Object-oriented design: inheritance, interfaces, composition, abstraction and polymorphism.
- Data processing: collections, generics, comparators, streams and collectors.
- Concurrency: threads, synchronization, blocking queues, CompletableFuture and virtual threads.
- Modern Java: records, sealed classes, text blocks, pattern matching and sequenced collections.
The examples live in topic folders, so you can study one concept at a time or use the repository as a reference alongside your own projects.
- JDK 21 or newer, with
javaandjavacavailable on your PATH. - Git to clone the repository.
- Network access for the Maven Wrapper and dependencies on the first build.
git clone https://github.com/devendraghag/java_lts_upto21.git
cd java_lts_upto21
java -version
javac -versionWindows PowerShell
.\mvnw.cmd clean packagemacOS / Linux
./mvnw clean packageThe examples target Java 21. The Maven Wrapper downloads the pinned Maven distribution on its first run, so a system Maven installation is not required. Maven reads the project-local .mvn/settings.xml instead of machine-level Maven settings.
After building, run the entry-point example:
java -cp target/classes com.example.helloworldways.HelloWorldEntryPointDemo DevendraExpected output:
Hello, Devendra!
Hello from an overloaded helper method.
Prefer an IDE? Open the repository as a Maven project, select JDK 21 or newer, then run an example class with a public static void main(String[] args) method. Use the package declaration inside each source file to identify its fully qualified class name.
| Your goal | Suggested route |
|---|---|
| Learn Java fundamentals | Variables and types → control flow → methods → strings → exceptions |
| Strengthen object-oriented design | Constructors → inheritance → interfaces → composition → method overriding |
| Get comfortable with data processing | Collections → generics → comparators → lambdas → streams → collectors |
| Explore modern Java | Local type inference → switch expressions → text blocks → records → sealed classes → pattern matching |
| Study concurrency | Multithreading → synchronization → blocking queues → CompletableFuture → virtual threads |
For each topic, practise explaining:
- The rule: what does the language or API guarantee?
- The prediction: what output do you expect before running the program?
- The edge case: what changes for null, empty input, duplicate values or concurrent execution, where relevant?
- The tradeoff: when would you use this approach in an application?
Try a 20-minute revision session
- 5 minutes: read one example and predict its output.
- 5 minutes: run it and explain the result aloud.
- 5 minutes: change one input locally and check your prediction.
- 5 minutes: write a short explanation of the concept without looking at the source.
java_lts_upto21/
├── src/main/java/com/example/example/ # Topic-based Java source folders
├── .mvn/ # Maven Wrapper and project settings
├── mvnw # macOS / Linux wrapper
├── mvnw.cmd # Windows wrapper
├── pom.xml # Java 21 Maven build
└── README.md # Learning guide and navigation
The source directory has an extra example segment; package declarations determine the class names used by the Java launcher. Run individual examples after compiling rather than assuming the JAR has a single application entry point.
- Release version 21 not supported: check
java -version,javac -versionand the JDK selected by your IDE or Maven. - Class not found: build from the repository root and use the package declaration plus class name with
java -cp target/classes. - Wrapper permission denied on macOS / Linux: use
sh mvnw clean package. - Download failure: check network or proxy access and the project-local Maven settings.
This repository is a collection of learning examples and interview practice. The build targets Java 21; individual folders illustrate selected features and concepts, rather than an exhaustive specification or migration guide for every Java release.