courses / java / level 2

level 2 · medium

intermediate
java.

Build useful Java programs with lists, maps, your own classes, exceptions and files.

  • 28 lessons
  • 7 units
  • 4 h 41 m in all
  • £0, for good

what’s inside.

For people who finished Level 1, or can already write small programs with variables, decisions, loops and functions.

Java Level 2 picks up where Level 1 ended and puts your skills to work on small, real programs. In 28 lessons you master lists, maps and sets, design classes with constructors, inheritance and interfaces, handle errors with exceptions, and save your work in files. It ends with a level check: a little library app that lends books and keeps them safe in a file.

every lesson goes the same way.

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

unit 1

Lists that grow

Keep as many things as you like, in order, and change them as you go.

4 lessons · 37 min

  1. A list that grows9 minMake a list you can keep adding to.
  2. Changing a list9 minSwap, squeeze in and remove items from a list.
  3. Lists of numbers9 minKeep whole numbers and decimals in a list and add them up.
  4. Searching and sorting lists10 minFind things in a list and put it in order.

unit 2

Maps and sets

Look things up by name and keep every value only once.

4 lessons · 38 min

  1. Look it up with a HashMap9 minStore values under names and find them in a flash.
  2. Updating a map10 minChange values, check keys and count things with a map.
  3. Looping over a map10 minVisit every pair in a map, in sorted order when you want it.
  4. No repeats with a HashSet9 minKeep each value only once and check for it fast.

unit 3

Build better objects

Give your objects a proper start, skills of their own and some privacy.

4 lessons · 39 min

  1. Constructors10 minBuild an object with its fields filled in from the start.
  2. Objects that do things10 minGive your objects methods that use their own fields.
  3. Keep your fields private10 minProtect an object's fields so they only change safely.
  4. Objects that describe themselves9 minChoose what appears when you print an object.

unit 4

Shared, equal and fixed

Share values across objects, compare them fairly and fix a set of choices.

4 lessons · 41 min

  1. Shared boxes and constants10 minKeep one value for a whole class, and lock values that never change.
  2. When are two objects equal?12 minTeach Java when two of your objects count as the same.
  3. Enums: a fixed set of choices9 minList every possible choice, so typos cannot sneak in.
  4. Enums with their own values10 minGive each choice its own data, and turn text into a choice.

unit 5

Family trees

Build new classes on top of old ones and give them a shared shape.

4 lessons · 41 min

  1. Inheritance10 minBuild a new class on top of one you already have.
  2. Overriding10 minLet each subclass do the same job its own way.
  3. Interfaces10 minPromise that different classes can all do the same job.
  4. Sort by your own rules11 minSort lists of your own objects any way you choose.

unit 6

When things go wrong

Catch problems, throw your own and keep your program running.

4 lessons · 42 min

  1. Catching an exception10 minHandle a problem and keep your program running.
  2. More catches and finally10 minHandle different problems differently, and always tidy up.
  3. Throwing your own problems10 minRefuse bad values loudly with throw.
  4. Checked exceptions and your own12 minMake your own exception and make callers deal with it.

unit 7

Save your work

Build text, save it in files and read it back.

4 lessons · 43 min

  1. Building text with StringBuilder9 minBuild long text piece by piece, without waste.
  2. Writing and reading a file11 minSave text in a file and read it back.
  3. One line per record11 minSave a list as lines and turn lines back into data.
  4. Try-with-resources12 minOpen a file, use it and let Java close it for you.
end of level 2 level check: a little library Build one small project with everything from this level. Pass it and your face levels up. see the check

next, level 3

advanced
java.

Write Java like a professional: generics, lambdas, streams, safe values, concurrency, patterns and tests.

see level 3