Java tutorial
Learn Java basics and build reliable object-oriented applications.
Course contents
Getting Started
- Introduction to Java — Learn what Java is, where it came from, the JVM, JRE and JDK, how to install Java, and how a Java program is written, compiled and run.
- Variables and Data Types — Create variables and constants, choose between Java's primitive and non-primitive types, read input with Scanner, and convert between types with casting, parse methods and String.valueOf.
- Operators — Use Java's arithmetic, increment, comparison, logical, assignment, ternary, bitwise and shift operators, and learn the order Java follows to evaluate an expression.
Control Flow
- Conditional Statements — Make decisions in Java with if, if-else, else-if ladders, nested conditions, combined conditions, the ternary operator and switch.
- Loops — Repeat code with for, while and do-while loops, nest loops, control them with break and continue, and avoid infinite loops.
- Methods — Write and call Java methods with parameters and return values, overload them, use static and instance methods, varargs and recursion, and see how pass by value works.
Reference Types
- Arrays — Store many values in one array, read and update elements, loop with for and for-each, build 2D and jagged arrays, and sort, search, fill and copy with the Arrays class.
- Strings — Work with Java text: immutability, the String Pool, literals and text blocks, formatting, common String methods, comparing strings, and building text with StringBuilder and StringBuffer.
- DateTime — Handle dates and times with LocalDate, LocalTime, LocalDateTime and ZonedDateTime, format and parse them, do date arithmetic, and measure gaps with Duration and Period.
Object-Oriented Programming
- Classes and Objects — Create your own types with classes, make objects with new, use fields, methods, this and constructors, control access with modifiers, and see objects on the stack and heap.
- Static Members — Share data and behaviour across a whole class with static variables, static methods and static blocks, and learn why main is static.
- Advanced Classes — Organise code with static nested, inner, local and anonymous classes, and control extension with final and sealed classes.
- Enums and Records — Model fixed sets of choices with enums, including fields, constructors and methods, and carry immutable data with records.
- Interfaces — Describe abilities with interfaces: declare and implement them, implement several at once, add default and static methods, and use functional interfaces with lambdas.
- Inheritance — Reuse code with inheritance: parent and child classes, the IS-A test, types of inheritance, extends, super and constructor chaining.
- Polymorphism — Use one name for many behaviours with overloading and overriding, @Override, dynamic method dispatch, and safe upcasting and downcasting.
- Abstraction — Hide details and show only what matters with abstract classes, abstract methods and interfaces, and choose between them.
- Encapsulation — Protect object data with private fields, getters and setters, validation and read-only patterns, and see how encapsulation differs from data hiding.
Exception Handling
- Exception Handling — Handle problems while a program runs: errors vs exceptions, checked vs unchecked, try, catch and finally, throw and throws, custom exceptions and propagation.
Packages and Access Control
- Packages — Organise classes into packages: declare and import them, use built-in packages, build custom packages, control access across packages, and use static import.
Generics
- Generics Fundamentals — Write type-safe, reusable code with generic classes, methods and interfaces, bounded type parameters, wildcards, and generic collections.
Collections Framework
- Collections Fundamentals — See why collections beat arrays, how List, Set and Map fit into the Collections Framework, how to choose between them, and how to loop with for-each and Iterator.
- ArrayList — Use ArrayList to add, remove, read, update, search, sort and loop through a resizable list, and understand capacity vs size.
- Set and Map — Store key-value pairs with HashMap and unique items with HashSet, loop through them, use set operations, and compare them with Hashtable and TreeSet.
- Linear Data Structures — Use stacks (LIFO) and queues (FIFO): push, pop and peek, Queue with LinkedList and PriorityQueue, offer vs add, poll vs remove, and real applications.
Functional Programming
- Lambda Expressions — Write short, nameless functions with lambdas, use them with functional interfaces like Predicate, Function, Consumer and Supplier, and shorten them with method references.
- Streams — Process collections with streams: create them, chain filter, map, sorted and more, finish with collect, reduce, count and match operations, and use parallel streams.
File Handling
- File Handling — Read, write and append files with Files, BufferedReader and BufferedWriter, handle bytes with file streams, save objects with serialization, and manage files with try-with-resources.
Multithreading
- Introduction to Threads — Learn processes vs threads, the thread lifecycle, creating threads with Thread and Runnable, and using start, run, sleep, join and priorities.
- Synchronization — Keep shared data correct across threads: race conditions, thread safety, synchronized methods and blocks, and how to avoid deadlocks.
Modern Java Features
- Optional — Handle missing values safely with Optional: create one with of, ofNullable and empty, then use isPresent, ifPresent, orElse and orElseGet.
- Pattern Matching — Check a value's type and use it in one step with pattern matching for instanceof and switch, including guards, null cases and record patterns.
Reference
- Cheat Sheet — Every topic in the Java course on one page: syntax, the methods used most, and the mistakes that cost the most time.