Language vs Platform

b. 1996, Java has endured in the enterprise space owing to advantages over low-level languages such as C++, in areas such as:

  • Security: array bounds checking prevents hacker exploits due to unchecked bounds
  • Memory Management: automatic garbage collection instead of pointers and malloc
  • Simplified inheritance model (interfaces as opposed to multiple inheritance)
  • Multi-threading support
  • Portability: using JVMs for different platforms that interpret a bytecode specification - a universal intruction format for a virtual machine
  • Speed: JIT compilation for near native speeds

A key design pivot is the distinction between:

  1. the Language: a statically typed, object-oriented and cleanly designed (simple, small set of constructs) language governed by the Java Language Specification (JLS) , and,
  2. the Platform : a runtime (JRE), that implements a virtual machine (the JVM), governed by the JVM Specification (VMSpec)
    • the platform links (compiled bytecode with platform libraries) and executes the bytecode
    • source code -> javac compiler -> bytecode (instructions for a virtual machine)
    • bytecode is a form of intermediate language interpreted by the JVM
    • the runtime has a JIT compiler that compiles the bytecode into native machine code So Java is both interpreted and compiled.
    • Adaptive Compilation: the JIT compiler uses structural information emitted by the bytecode compiler to perform optimizations at runtime. This can slow down startup time as the optimizations are performed at startup.
      Also, most programs spend the majority of their time executing (in) a relatively small section of their code.
      So Adaptive Compilation is a technique implemented by the HotSpot Java compiler that profiles (measures) the code at runtime (as it executes), to discover what those frequently executed sections are. These are then compiled to optimal native machine code.
      In this process it reduces startup time for future runs and saves memory, as opposed to the regular JIT compilation of the entire program. The JVM has two modes that account for this process:
      • Client mode: for quick startup time
      • Server mode: for out-right optimization – increases startup time
    • The JVM is not a general purpose, language-agnostic execution environment for programs. - General-purpose: the JVM is a bytecode interpreter implemented as a stack-based machine. As a linker, it interfaces with native code libraries from the host OS, which grants low-level access to networking, windowing, and file system resources. So, while the JVM bytecode format is platform independent (bytecodes can run universally on any JVM), the JVM is implemented in a natively compiled language on the host platform (a JVM is implemented for each platform). - It supports compiling multiple languages (Kotlin, Scala, Clojure) to JVM bytecode

The bifurcation of language and platform and their governance through two independent standards specifications (JLS and VMSpec) has helped manage evolution over the history of Java.
The two are linked only by the shared class file (bytecode) format.