01 · Basics of Java and JVM
Program structure Java, primitive types, modern flow control, String Pool and static arrays.
- int / double / boolean
- String Pool vs new
- Arrays.toString
- StringBuilder
End of the Java Course
Congratulations! You have completed all 10 modules and 22 lessons of the Java course — from primitives, String Pool, OOP, inheritance, interfaces, Collections & Generics to try-with-resources, Stream API, Records, Optional, concurrency, and JUnit 5 testing.
10 modules · 22 lessons · 110 checkpoints
Java exercises are verified locally in the browser via Tree-sitter AST (`tree-sitter-java.wasm`) plus structural and keyword checks; to compile and execute real Java code, click Open on OneCompiler in any editor.
Program structure Java, primitive types, modern flow control, String Pool and static arrays.
Classes, objects on Heap, pass-by-value of references, constructors, rich overloading and enum.
Class hierarchies with extends, super(), dynamic dispatch, and abstractions with abstract classes.
Decoupled behavioral contracts via interface and safe manipulation of ArrayList.
Throwable hierarchy, checked vs unchecked, try-catch-finally and AutoCloseable with try-with-resources.
HashSet, HashMap idiomatic, access complexity and generic type-safe programming with bounded wildcards.
Functional programming on JVM: functional interfaces, method reference, lazy evaluation and Collectors.
Java 17/21 constructs for immutable and expressive domains: Records, Sealed hierarchies, Optional and pattern matching.
Safe parallel execution with ExecutorService and CompletableFuture, thread-safe structures, and modern API files java.nio.file.
Expressive unit tests with JUnit 5 and invariants of equality, hashing and defensive immutability.
Combine Modern Java idioms across five progressive stages: pricing logic, account inheritance, interface billing, Stream sumPositive reduction, and validated immutable record Product.
Write a static method computing total price with a 10% discount whenever quantity is at least 10 (Module 1 + Module 2).
Define public static double getDiscountedPrice(double price, int quantity) returning price * quantity, multiplied by 0.9 when quantity >= 10.
Compute double total = price * quantity;, check if (quantity >= 10) return total * 0.9;, and return total.
Solution available after 3 attempts
Implement `SavingsAccount extends Account`, chaining `super(balance)` and adding interest accrual (Module 3 + Module 4).
Write class SavingsAccount extends Account with constructor (double balance, double interestRate) calling super(balance) and public void addInterest() adding balance * interestRate.
Extend Account, call super(balance); this.interestRate = interestRate;, and update this.balance += this.balance * interestRate;.
Solution available after 3 attempts
Implement `Taxable` on `Invoice`, collecting prices in `ArrayList<Double>` and computing total tax (Module 5 + Module 6).
Complete class Invoice implements Taxable: implement addItem(double price) (items.add(price)), @Override public double getTaxRate() (returning 0.22), and public double getTaxAmount() (sum times getTaxRate()).
Add items.add(price); in addItem, implement getTaxRate() returning 0.22, and sum elements in getTaxAmount().
Solution available after 3 attempts
Filter and sum positive integers from `List<Integer>` lazily via `.stream()`, `.filter(...)`, and `.mapToInt(...)` (Module 7).
Implement public static int sumPositive(List<Integer> values) using .stream(), .filter(v -> v > 0), .mapToInt(Integer::intValue), and .sum().
Return values.stream().filter(v -> v > 0).mapToInt(Integer::intValue).sum();.
Solution available after 3 attempts
Define an immutable `record Product(String name, double price)` with a compact validation constructor and `discounted(double rate)` (Module 8 + Module 10).
Complete public record Product(String name, double price) adding a compact constructor that throws IllegalArgumentException if price < 0, plus public Product discounted(double rate) returning a copy with price * (1.0 - rate).
Add public Product { if (price < 0) throw new IllegalArgumentException("Negative price"); } and return new Product(name, price * (1.0 - rate)); inside discounted.
Solution available after 3 attempts
All essential Java 17/21 syntax — from primitives and String Pool to Streams, Records, Optional, NIO.2, ExecutorService, and JUnit 5.
Consistent practice builds JVM fluency. Explore String Pool, Streams, and Records scenarios inside the Java Playground or run them on OneCompiler.