What javac does to your code

Java source next to the bytecode javac compiles it to. Each example is compiled with javac 25 for every --release from 8 to 25, so you can see where the output changed.

javac is not an optimising compiler: it translates almost statement by statement and leaves optimisation to the JIT compiler. That makes its output readable, and it shows how much of Java is a layer over a much smaller virtual machine. The JVM knows nothing of inner classes, generics, enums, lambdas, records or finally; javac compiles them all to ordinary classes, methods and jumps.

String concatenation

StringBuilder chains up to Java 8, one invokedynamic since Java 9.

Lambdas and method references

A private synthetic method, and an invokedynamic that LambdaMetafactory links.

Switch on a String

A switch on hashCode(), equals() to confirm, then a second switch.

Switch on an enum

A lookup table in a synthetic class, so reordering the enum cannot break the switch.

Autoboxing

Integer.valueOf on the way in, intValue() on the way out, and a checkcast in between.

The enhanced for loop

An index loop over arrays, an Iterator over everything else.

try-with-resources

close() on every path, and addSuppressed when close() fails too.

finally

No instruction for it: the finally block is copied onto every exit.

synchronized

monitorenter and monitorexit for a block; only a flag for a method.

Inner classes and nestmates

access$000 methods up to Java 10; direct access between nestmates since Java 11.

Records

A final class with fields, accessors and a constructor; toString, equals and hashCode via invokedynamic.

Pattern-matching switch

SwitchBootstraps.typeSwitch picks the case; guards jump back and try again.

Compile-time constants

Copied into the code that uses them, so they are never read at run time.

assert

A static flag set from desiredAssertionStatus(), checked before each assertion.

Generics and bridge methods

Erased types, the casts javac inserts, and a synthetic bridge method.

Boolean logic and the ternary operator

No boolean instructions: && and || become chains of jumps.

for, while and do-while

The test at the top and a goto at the bottom, except for do-while.

instanceof patterns

No new instructions: the same instanceof, then a checkcast into a new local.

Text blocks

By the time it reaches the class file, a text block is an ordinary String constant.

Varargs

The caller builds the array, even for no arguments.

Comparing longs, floats and doubles

A compare instruction pushes -1, 0 or 1; then an ordinary int branch.

x++ and friends

iinc for locals; read, add and write for fields and arrays, with dup to keep the value.