Java Tutorial

Java is a strongly typed, object-oriented language that runs on almost any machine through the JVM. These lessons cover the building blocks you need before classes and objects.

Start the first lesson

1Getting Started

  1. Your First Java ProgramWhat Java is, how to install the JDK, and how a Java program is structured.
  2. How Java Works (JDK, JRE, JVM)What happens between writing Main.java and seeing output, and how Java uses memory.
  3. Variables and Data TypesPrimitive types, String, type conversion and the var keyword.
  4. Type Casting and Wrapper ClassesConvert between numeric types, and use Integer, Double and friends.
  5. OperatorsArithmetic, assignment, comparison and logical operators in Java.
  6. Reading User InputRead numbers and text from the keyboard with the Scanner class.

2Control Flow

  1. Conditions with if and switchBranch your program with if, else if, the ternary operator and switch.
  2. Loops in JavaRepeat code with for, enhanced for, while and do-while.

3Methods

  1. MethodsWrite reusable methods with parameters, return values and overloading.
  2. RecursionWrite methods that call themselves to solve problems step by step.
  3. static and finalUnderstand class-level members, constants, and values that cannot change.

4Arrays and Strings

  1. ArraysCreate, loop over, sort and copy arrays.
  2. StringsCompare, search, split and build strings efficiently.

5Object-Oriented Programming

  1. Classes and ObjectsDefine your own types with fields, constructors and methods.
  2. Constructors and thisOverload constructors, chain them with this(), and use initializer blocks.
  3. Access Modifiers and PackagesControl who can see your classes and members, and organize code into packages.
  4. InheritanceExtend classes, override methods and use polymorphism.
  5. PolymorphismCompile-time and run-time polymorphism, upcasting, downcasting and instanceof.
  6. InterfacesDefine contracts that many unrelated classes can implement.
  7. The Object ClasstoString, equals and hashCode, the methods every Java class inherits.
  8. Nested, Inner and Anonymous ClassesDefine classes inside other classes and create one-off implementations.
  9. Enums and RecordsModel fixed sets of values with enum, and simple data carriers with record.

6Collections and Generics

  1. GenericsWrite classes and methods that work with any type while staying type safe.
  2. ArrayListUse a resizable list that grows and shrinks as you add and remove items.
  3. HashMapLook values up by key with HashMap and TreeMap.
  4. The Collections FrameworkAn overview of List, Set, Queue, Deque and Map, and when to use each.
  5. Sorting with Comparable and ComparatorDefine a natural order for your classes and sort by any field you like.

7Functional Programming

  1. Lambdas and Functional InterfacesPass behaviour as a value with lambda expressions and method references.
  2. The Stream APIFilter, transform, group and summarize collections in a readable pipeline.

8Exceptions and Files

  1. ExceptionsHandle errors with try, catch and finally, and throw your own exceptions.
  2. File HandlingRead and write files with java.nio.file.Files, BufferedReader and try-with-resources.

9Advanced Topics

  1. MultithreadingRun tasks at the same time with Thread, Runnable, synchronized and ExecutorService.
  2. Date and Time APIWork with dates, times, durations and formatting using java.time.