Command Palette

Search for a command to run...

Phase 15Advanced16 of 17 in Core Java

Advanced Language and Tooling

Annotations, reflection, the module system, Maven and Gradle, JUnit 5 testing and logging done right: the tools every professional Java codebase is built on.

By now you can write correct, fast, concurrent Java. This phase is about the machinery around your code that every real project depends on. Annotations let you attach labels to code that compilers, frameworks and test runners read. Reflection lets a running program look at its own classes and call methods it only knows by name, which is how Spring, Hibernate, Jackson and JUnit work. The module system (Java 9) draws hard borders around packages so a library's internals stay internal.

Then come the tools of the trade. Topic 15.4 shows how Maven and Gradle download libraries, compile, test and package a project with one command. Topic 15.5 teaches JUnit 5, the standard way to write automated tests, and Topic 15.6 shows how to log properly with SLF4J and Logback: levels, parameterized messages and why string concatenation in log calls is a quiet performance bug.

Every runnable example uses only the JDK, so it runs in your browser. Where a topic needs a library (JUnit, SLF4J, Maven), you see the real code and the real terminal output as a read-only block, and a runnable example rebuilds the core idea by hand: Topic 15.5 ends with a tiny test runner built from the annotations of 15.1 and the reflection of 15.2. Reflection lists members in an unspecified order, so every example sorts them by name before printing.

0/6 · 0%
6 topics ~3 h 24 code blocks & diagrams
Start with the first topic
1
15.1

Annotations

An annotation is a label such as @Override or @Test that you attach to a class, method, field or parameter. It doesn't change what the code does by itself; the compiler, an annotation processor or a framework reads it (at compile time or, with RUNTIME retention, through reflection) and acts on it.

31 min 4 code practice

2
15.2

Reflection

Reflection (java.lang.reflect) lets a running program examine classes it was never compiled against: list their fields, methods and constructors, create objects, call methods and read fields by name. It powers frameworks, serializers and test runners, at the cost of speed, compile-time safety and encapsulation, and since Java 16 the module system blocks it from reaching into JDK internals.

33 min 4 code practice

3
15.3

The Module System (JPMS)

The Java Platform Module System (JPMS, Java 9) groups packages into named modules described by a module-info.java file. A module states which modules it requires and which packages it exports; everything else is hidden, even from reflection, which gives libraries real encapsulation, reliable startup checks and small custom runtimes with jlink.

28 min 4 code practice

4
15.4

Maven and Gradle Basics

Maven and Gradle are build tools: from one file (pom.xml or build.gradle.kts) they download your libraries and the libraries those need, compile your code, run the tests and package a JAR with one command. Maven uses a fixed lifecycle of phases and XML configuration; Gradle uses a task graph, a Kotlin or Groovy script, and skips work whose inputs haven't changed.

34 min 4 code practice

5
15.5

Unit Testing with JUnit 5

A unit test is a small program that calls your code with known inputs and checks the result automatically. JUnit 5 (the Jupiter API) finds methods marked @Test, runs each on a fresh instance of the test class, and reports passes and failures; assertions such as assertEquals and assertThrows, lifecycle methods like @BeforeEach, and @ParameterizedTest make tests short and readable.

36 min 4 code practice

6
15.6

Logging Done Right

Logging records what a running program did, so you can understand it in production where there's no debugger. Professional Java code logs through the SLF4J API with a back-end such as Logback, uses levels (TRACE to ERROR) to control volume, writes parameterized messages (log.info("Order {} placed", id)) instead of string concatenation, and passes exceptions as the last argument so their stack traces are kept.

35 min 4 code practice