Skip to content
academia.sh

Course Beginner

Java Fundamentals

By the end of this course

Start course

01

Language and Runtime

Measuring the chain from source to class file and virtual machine, the steps a program passes through from its entry point to termination, and the trace a package and an import leave in name resolution.

  1. 01 Source, Bytecode, and the Virtual Machine The source written in Java is not the thing that runs: eight of twelve methods carry a step in the class file that is absent from the source, 13 added steps counted in total; a concatenation sitting in the source, by contrast, is entirely absent from the class file.
  2. 02 Program Life Cycle The virtual machine counts as the entry point only the single signature satisfying four conditions at once; a class's static initializer runs not at the program's start but the moment the class is first used, and only once; an enum with two names written in the source carries three fields and five methods in the class file.
  3. 03 Packages and Imports An import is not a loading directive, it is a shorthand rule: class files produced when the same program is written with an import versus a fully qualified name are byte-for-byte identical, and a static import adds no step either; a package name, by contrast, changes the file, and two names cannot fit the same shorthand.

02

Basic Syntax

Autoboxing between primitive types and wrappers, the scope and lifetime of variable kinds, an operator's numeric promotion, control-flow forms, an array's fixed-size layout, a string's immutability, and argument passing's single model.

  1. 01 Primitive Types and Wrappers A one-letter source difference is a method call in the class file: the line Integer count = 5 adds Integer.valueOf, the reverse direction adds Integer.intValue; the same 200 boxings produce between 100 and 200 objects depending on the warehouse, and where the cache ends, identity and value come apart.
  2. 02 Variables and Scope The same int count declaration compiles to three separate things depending on where it sits: a field in the class body, a slot in a method body, statically the class's single-copy field; a method using the same name in two sibling blocks produces the same 20 instructions with one fewer slot.
  3. 03 Operators and Expressions One-character forms leave silent steps in the class file: adding an int and a long inserts a conversion, count += 300 puts in a narrowing never written in the source and the result comes out 45, short-circuit shows up as a branch instruction — with constants, no step is added at all.
  4. 04 Control Flow The same behavior compiles to two separate lookup instructions in the class file: dense labeled selection builds a table that indexes directly, sparse labeled selection builds an instruction that searches among labels; labeled jump earns both a step and the correct row against a plain break, and zero steps against the flagged form.
  5. 05 Arrays An array in Java is an object, and the measurement shows this in three places: production leaves a single instruction, d.length is not a field read but an instruction of its own, and bound checking and array covariance's type check are left to run time without ever showing up in the class file.
  6. 06 Strings The same + operator gives two separate results on strings: between two constants it leaves no trace at all in the class file, between variables it turns into a dynamic call; in a loop, the 24-instruction form leaves 20 string objects while the 27-instruction builder produces a single object.
  7. 07 Value and Reference Passing Java has a single passing model, and the class file writes it down: five arguments of five separate types are loaded the same way, writing to a parameter's field is visible to the caller, rebinding the parameter is not, and on an immutable type the two situations cannot be told apart.

Start typing to search.

↑↓ Esc navigate · open · close