Java Tutorial
Object oriented programming for apps, back ends and Android.
Getting started4 lessons
Basics23 lessons
- 5VariablesStoring values with types.
- 6Data TypesPrimitive and reference types.
- 7Type CastingConverting between types.
- 8OperatorsArithmetic, comparison and logic.
- 9StringsWorking with text.
- 10The Math ClassRounding, powers and random numbers.
- 11Booleans and Conditionstrue, false and comparisons.
- 12Java String MethodsStrings are immutable objects.
- 13StringBuilder and FormattingStringBuilder builds text efficiently.
- 14Wrapper Classes and AutoboxingEach primitive has a wrapper: Integer, Double, Boolean, Character.
- 15var and finalvar lets the compiler infer a local type.
- 16Bitwise Operators and Ternary& | ^ ~ << >> operate on bits.
- 17Variables and ConstantsDeclare a variable with its type.
- 18var Type Inferencevar lets the compiler infer a local variable type.
- 19Primitive TypesJava has byte, short, int, long, float, double, char and boolean.
- 20Type CastingWidening conversions are automatic.
- 21Math ClassMath has abs, max, min, pow, sqrt, round, floor, ceil and random.
- 22String MethodsStrings are immutable.
- 23String.format and Text BlocksString.format and printf use %s, %d, %.2f.
- 24StringBuilderStringBuilder changes text without creating many strings.
- 25Reading Input with ScannerScanner reads from System.in or from a string.
- 26OperatorsArithmetic, comparison, logical, assignment and bitwise operators.
- 27Wrapper Classes and ParsingInteger, Double and Boolean wrap primitives.
Control flow16 lessons
- 28If ... ElseMaking decisions.
- 29SwitchChoosing between many values.
- 30While LoopsRepeating while a condition holds.
- 31For LoopsCounting loops and the for-each loop.
- 32Break and ContinueControlling loops.
- 33ArraysFixed size lists.
- 34Switch Expressions and Pattern MatchingModern switch uses arrows, returns a value and needs no break.
- 35Nested Loops and PatternsLoops can be nested to build tables and patterns.
- 36if, else if and elseBranch on conditions.
- 37switch ExpressionsThe arrow form returns a value, needs no break and can group cases.
- 38for Loopsfor has init, condition and update.
- 39while and do whilewhile checks first, do while runs once before checking.
- 40break, continue and Labelsbreak leaves a loop, continue skips a round and a label exits nested loops.
- 41ArraysArrays have a fixed size.
- 42Two Dimensional ArraysAn array of arrays models grids and tables.
- 43Arrays UtilitiesArrays.sort, fill, copyOf, equals, asList and binarySearch save work.
Methods10 lessons
- 44MethodsReusable blocks of code.
- 45Method OverloadingSame name, different parameters.
- 46RecursionA method that calls itself.
- 47Varargs and Pass by ValueA varargs parameter accepts any number of arguments.
- 48Static Methods and Utility Classesstatic methods belong to the class and are called without an object, like Math.max.
- 49MethodsMethods have a return type, name and parameters.
- 50Method OverloadingMethods may share a name with different parameters.
- 51VarargsType.
- 52RecursionA method can call itself.
- 53Pass by ValueJava passes copies.
Object oriented programming21 lessons
- 54Classes and ObjectsBlueprints and instances.
- 55ConstructorsSetting up new objects.
- 56Access Modifiers and EncapsulationHiding data behind methods.
- 57InheritanceBuilding on another class.
- 58PolymorphismOne reference, many forms.
- 59Abstract Classes and InterfacesContracts for classes.
- 60Static Members and EnumsClass level data and fixed sets of values.
- 61Object, toString, equals and hashCodeEvery class extends Object.
- 62Inner, Nested and Anonymous ClassesA class can live inside another class.
- 63Sealed Classes and RecordsA record is an immutable data class with generated constructor, accessors, equals and toSt.
- 64Classes and ObjectsA class defines fields and methods.
- 65EncapsulationMake fields private and expose getters and setters with checks.
- 66Inheritanceextends inherits from a class.
- 67PolymorphismA parent type variable can hold any child.
- 68Abstract Classes and InterfacesAbstract classes share code and force children to implement methods.
- 69static Fields and Methodsstatic members belong to the class, not to objects.
- 70this and superthis refers to the current object and super to the parent.
- 71EnumsAn enum defines fixed constants.
- 72RecordsA record is a short immutable class with auto constructor, getters, equals and toString.
- 73GenericsGenerics add a type parameter so one class works for many types safely.
- 74equals, hashCode and toStringOverride equals and hashCode together and toString for readable output.
Collections and modern Java21 lessons
- 75ArrayListA list that can grow.
- 76HashMap and HashSetKey and value pairs, and unique values.
- 77Lambdas and StreamsShort functions and data pipelines.
- 78Records and Text BlocksModern shortcuts.
- 79List, Set, Queue and DequeThe Collections Framework offers List (ordered), Set (unique), Queue and Deque (FIFO and d.
- 80Maps In DepthHashMap is fast and unordered, LinkedHashMap keeps insertion order and TreeMap sorts by ke.
- 81Java GenericsGenerics let classes and methods work with many types safely.
- 82Streams and CollectorsStreams process collections declaratively: filter, map, sorted, distinct, limit, reduce an.
- 83OptionalOptional models a value that may be absent.
- 84Sorting and ComparatorsComparable defines natural order and Comparator defines custom orders.
- 85Date and Time APIjava.time provides LocalDate, LocalDateTime, Duration, Period and DateTimeFormatter.
- 86ArrayListArrayList is a resizable list.
- 87HashMapHashMap stores key value pairs.
- 88HashSetA set holds unique values.
- 89Iterating CollectionsUse for each, forEach with a lambda, or Iterator when removing while looping.
- 90Sorting and ComparatorsCollections.sort and List.sort use natural order or a Comparator.
- 91LambdasA lambda is a short anonymous function: (a, b) -> a + b.
- 92StreamsStreams process collections with map, filter and collect.
- 93OptionalOptional holds a value or nothing and avoids null checks.
- 94Queue and DequeQueue is first in first out and Deque works at both ends.
- 95Switch Patterns and instanceofPattern matching tests a type and names it in one step.
Errors and files9 lessons
- 96Exceptionstry, catch, finally and throw.
- 97Reading and Writing FilesThe java.nio.file API.
- 98User Input with ScannerReading from the keyboard.
- 99Custom Exceptions and try with resourcesCreate your own exception by extending Exception (checked) or RuntimeException (unchecked).
- 100Files with java.nioFiles and Path read and write whole files in one line, list directories and walk trees.
- 101try, catch, finallyHandle errors with try catch.
- 102Custom ExceptionsExtend Exception for your own error types.
- 103try with resourcesResources that implement AutoCloseable close automatically.
- 104Files with java.nioFiles.writeString and readAllLines are the modern way to handle small files.
Advanced JavaPremium6 lessons
- 105Threads and ExecutorsThreads run work concurrently.
- 106Synchronization and Atomicssynchronized, ReentrantLock and the atomic classes protect shared data from race condition.
- 107CompletableFuture and Virtual ThreadsCompletableFuture chains asynchronous steps with thenApply and thenCombine.
- 108Reflection and AnnotationsReflection inspects classes at runtime.
- 109Composition, SOLID and Design PatternsPrefer composition to inheritance, program to interfaces and follow SOLID.
- 110JVM, Memory and Garbage CollectionThe JVM runs bytecode.
Java in practicePremium8 lessons
- 111Maven and GradleMaven and Gradle download dependencies, compile, test and package.
- 112Testing with JUnitJUnit 5 is the standard test framework.
- 113JSON with Jackson or GsonLibraries such as Jackson and Gson convert objects to JSON and back.
- 114HTTP Client and RESTjava.net.http.HttpClient sends requests and receives responses, synchronous or async.
- 115Spring Boot OverviewSpring Boot builds production web apps with minimal setup.
- 116Databases with JDBC and JPAJDBC runs SQL from Java with prepared statements.
- 117Logging and ConfigurationUse a logging framework (SLF4J with Logback) instead of System.out.
- 118Java Best PracticesFollow naming conventions, prefer immutability, use interfaces, avoid null, close resource.