Skip to main content

End of the Java Course

Summary and Final Challenge

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.

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

02 · Fundamentals of OOP

Classes, objects on Heap, pass-by-value of references, constructors, rich overloading and enum.

  • if / switch ->
  • for / for-each / while
  • static methods
  • enum & final

03 · OOP Advanced

Class hierarchies with extends, super(), dynamic dispatch, and abstractions with abstract classes.

  • class / private fields
  • this(...) constructors
  • getter / setter
  • overloading

04 · Interfaces and Dynamic Collections

Decoupled behavioral contracts via interface and safe manipulation of ArrayList.

  • extends / super()
  • @Override
  • polymorphism
  • abstract class

05 · Exception Management

Throwable hierarchy, checked vs unchecked, try-catch-finally and AutoCloseable with try-with-resources.

  • interface / implements
  • ArrayList<T>
  • HashMap<K, V>
  • Set & generics

06 · Collections Framework and Generics

HashSet, HashMap idiomatic, access complexity and generic type-safe programming with bounded wildcards.

  • try / catch / finally
  • try-with-resources
  • custom Exception
  • AutoCloseable

07 · Lambda and Stream API

Functional programming on JVM: functional interfaces, method reference, lazy evaluation and Collectors.

  • -> Lambdas
  • Method::reference
  • Stream filter/map
  • Collectors & reduce

08 · Java Modern: Record, Sealed and Optional

Java 17/21 constructs for immutable and expressive domains: Records, Sealed hierarchies, Optional and pattern matching.

  • record Type(...)
  • sealed / permits
  • Optional.orElseGet
  • instanceof pattern

09 · Concurrency and File I/O (NIO.2)

Safe parallel execution with ExecutorService and CompletableFuture, thread-safe structures, and modern API files java.nio.file.

  • ExecutorService
  • CompletableFuture
  • ConcurrentHashMap
  • Files.readString

10 · Testing JUnit 5 and Contracts OOP

Expressive unit tests with JUnit 5 and invariants of equality, hashing and defensive immutability.

  • JUnit 5 @Test
  • assertThrows / assertAll
  • equals & hashCode
  • immutability

The Final Challenge, in Five Steps

Combine Modern Java idioms across five progressive stages: pricing logic, account inheritance, interface billing, Stream sumPositive reduction, and validated immutable record Product.

1 · Calculate Discounted Price

Write a static method computing total price with a 10% discount whenever quantity is at least 10 (Module 1 + Module 2).

Exercise#java.boss.e1
Attempts: 0Loading…

Define public static double getDiscountedPrice(double price, int quantity) returning price * quantity, multiplied by 0.9 when quantity >= 10.

Loading editor…
Show hint

Compute double total = price * quantity;, check if (quantity >= 10) return total * 0.9;, and return total.

Solution available after 3 attempts

2 · Savings Account with Inheritance

Implement `SavingsAccount extends Account`, chaining `super(balance)` and adding interest accrual (Module 3 + Module 4).

Exercise#java.boss.e2
Attempts: 0Loading…

Write class SavingsAccount extends Account with constructor (double balance, double interestRate) calling super(balance) and public void addInterest() adding balance * interestRate.

Loading editor…
Show hint

Extend Account, call super(balance); this.interestRate = interestRate;, and update this.balance += this.balance * interestRate;.

Solution available after 3 attempts

3 · Billing with Interfaces and ArrayList

Implement `Taxable` on `Invoice`, collecting prices in `ArrayList<Double>` and computing total tax (Module 5 + Module 6).

Exercise#java.boss.e3
Attempts: 0Loading…

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()).

Loading editor…
Show hint

Add items.add(price); in addItem, implement getTaxRate() returning 0.22, and sum elements in getTaxAmount().

Solution available after 3 attempts

4 · Stream API Pipeline sumPositive

Filter and sum positive integers from `List<Integer>` lazily via `.stream()`, `.filter(...)`, and `.mapToInt(...)` (Module 7).

Exercise#java.boss.e4
Attempts: 0Loading…

Implement public static int sumPositive(List<Integer> values) using .stream(), .filter(v -> v > 0), .mapToInt(Integer::intValue), and .sum().

Loading editor…
Show hint

Return values.stream().filter(v -> v > 0).mapToInt(Integer::intValue).sum();.

Solution available after 3 attempts

5 · Validated Immutable Product Record

Define an immutable `record Product(String name, double price)` with a compact validation constructor and `discounted(double rate)` (Module 8 + Module 10).

Exercise#java.boss.e5
Attempts: 0Loading…

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).

Loading editor…
Show hint

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

Printable Java Cheatsheet (11 sections)

All essential Java 17/21 syntax — from primitives and String Pool to Streams, Records, Optional, NIO.2, ExecutorService, and JUnit 5.

Open cheatsheet

What now?

Consistent practice builds JVM fluency. Explore String Pool, Streams, and Records scenarios inside the Java Playground or run them on OneCompiler.