Introduction to Java
Java is a statically typed, object oriented language that compiles to bytecode and runs on a virtual machine, which is what makes it portable.
-
Java Basics
- Introduction to Java
- Setting Up Java and Writing Your First Program
- Variables, Data Types and Literals in Java
- Type Casting and Type Conversion in Java
- Operators and Expressions in Java
- Input and Output in Java
- Comments, Keywords and Naming Conventions in Java
- Control Flow in Java: if, else and switch
- Loops in Java: for, while and do-while
- Methods
- Arrays and Strings
-
OOP
- Classes and Objects in Java
- Constructors in Java
- The this Keyword in Java
- The static Keyword in Java
- Encapsulation in Java
- Access Modifiers in Java
- Inheritance in Java
- Method Overriding and super in Java
- Polymorphism in Java
- Abstraction, Abstract Classes and Interfaces in Java
- Composition, Aggregation and Association in Java
- The Object Lifecycle in Java
- Core Java
- Exception Handling
-
Collections
- The Java Collections Framework
- List in Java: ArrayList, LinkedList, Vector and Stack
- Set in Java: HashSet, LinkedHashSet and TreeSet
- Map in Java: HashMap, LinkedHashMap and TreeMap
- How HashMap Works Internally in Java
- Queue and Deque in Java: ArrayDeque and PriorityQueue
- Iterators in Java
- Comparable and Comparator in Java
- Collections Utilities and Choosing the Right Collection
- Generics
- Java 8+
- Stream API
- Date and Time
- File and I/O
-
Multithreading
- Threads in Java: Processes, Runnable and Thread
- Thread Lifecycle in Java
- Synchronization in Java: synchronized and volatile
- Locks and Atomic Classes in Java
- Race Conditions and Deadlocks in Java
- The Executor Framework and Thread Pools in Java
- Future and CompletableFuture in Java
- Concurrent Collections in Java
- The Java Memory Model
- JVM and Memory
- Advanced Java
- Networking
- JDBC
- Testing
What Java is
Java is a general purpose programming language that is statically typed, class based and object oriented. Source code is not translated straight into instructions for one particular processor. It is compiled into an intermediate form called bytecode, and a program called the Java Virtual Machine executes that bytecode on whatever machine it happens to be installed on.
That single design decision explains most of what people associate with Java: portability, a managed memory model, and a platform that many languages other than Java now target.
Why the language exists in this shape
- Portability. One compiled artefact runs anywhere a compatible JVM exists, without recompilation.
- Safety. There is no direct pointer arithmetic, array bounds are checked, and memory is reclaimed automatically.
- Readability over cleverness. The language deliberately keeps a small set of ideas and applies them consistently.
- Stability. Code compiled many years ago still runs, because backward compatibility is treated as a hard requirement.
How a Java program actually runs
Hello.java -- the source you write
| javac (compiler)
v
Hello.class -- bytecode, platform independent
| java (launcher starts the JVM)
v
JVM: verify -> load -> interpret, then JIT compile the hot code
|
v
native machine instructionsThe JVM starts by interpreting bytecode. Methods that run often are detected at runtime and compiled to native code by the just in time compiler, which is why a long running Java process usually gets faster after it warms up.
JDK, JRE and JVM
| Term | What it is | You need it to |
|---|---|---|
| JVM | The engine that loads, verifies and executes bytecode. | Run bytecode. |
| JRE | The JVM plus the standard class library. | Run a Java application. |
| JDK | The JRE plus development tools such as javac, jar and javadoc. | Write and compile Java. |
Since Java 11 the separate JRE download was discontinued. You install a JDK and, if a trimmed runtime is needed for shipping, you build one with jlink.Editions
- Java SE - the standard edition. The language, the JVM and the core libraries. This is what these notes cover.
- Jakarta EE - a set of server side specifications built on top of Java SE. Mentioned only so the name is familiar.
- Java ME - a much reduced edition for constrained devices, rarely encountered today.
Versions and the release cadence
Since Java 9 a feature release arrives every six months. Some of those are designated long term support releases, which is what production systems normally target.
| Release | Status | Notable for |
|---|---|---|
| Java 8 | LTS, legacy | Lambdas, streams, java.time |
| Java 11 | LTS, legacy | Modern HTTP client, single file source launch |
| Java 17 | LTS | Sealed classes, records finalised |
| Java 21 | LTS | Virtual threads, pattern matching for switch |
| Java 25 | LTS | Compact source files and instance main methods |
These notes teach current Java. Wherever a feature depends on a version, the version is stated beside it.
Characteristics worth knowing by name
- Statically typed - the type of every expression is known at compile time, so many errors are caught before the program runs.
- Garbage collected - objects that are no longer reachable are reclaimed automatically.
- Multi threaded - threads and a defined memory model are part of the platform, not an add on.
- Not purely object oriented - the eight primitive types are not objects. That is a deliberate performance trade off.
Common misconceptions
- Java is interpreted, therefore slow. It is interpreted at first and compiled at runtime afterwards. Steady state performance is generally close to natively compiled languages.
- Java and JavaScript are related. They are separate languages with separate designs. The similarity is only in the name.
- The JVM only runs Java. Any language that emits valid bytecode can run on it.
Practice
- Explain in two sentences why the same
.classfile runs on two different operating systems. - A colleague installs a runtime only and cannot compile. What is missing, and why?
- Why does a server application often report better throughput after several minutes of load?
Conclusion
Java compiles to bytecode and a virtual machine runs it. Hold on to that one sentence, because portability, the memory model, class loading and the just in time compiler all follow from it.