Learn / macOS

Learn Java with lessons and practice

Use Java worked examples, drills, and linked challenges to turn a language concept into a skill.

Java lessons with the lesson catalog and worked examples.
Java lessons with the lesson catalog and worked examples. Select the image to enlarge.
  1. Choose a concept

    Choose a lesson that matches a language gap, such as collections, equality, or generics. Read the worked examples before the drill.

    Example

    Compare a list that stores values in order with a set used for membership. Explain which operation your algorithm needs most often.

  2. Trace and explain

    Complete a lesson drill and trace an edge case. Explain how the language’s value, reference, or type rules affect it.

    Example

    Compare object references and logical equality. State why two distinct objects can represent the same value without being the same reference.

  3. Apply it in practice

    Choose Java in a supported Coding challenge and keep the supplied class and method signature. Run the visible cases.

    Example

    For Two Sum, use a map from values to indices. Verify a pair of equal values at different positions and preserve the required index order.

Check your work

You can explain a worked example and use the same rule on a new input or exercise.

Try it yourself

Trace a set-based duplicate check on [4, 1, 4]. Say which add operations change the set and whether a list would preserve all three positions.

What to look for
The second insertion of 4 leaves the set unchanged. A list retains both occurrences and their positions, so choose the collection according to what the problem asks you to retain.