Figure 1.1: Core Features of Java (The Java Buzzwords)
Figure 1.1: Core Features of Java (The Java Buzzwords)
1. Simple
Clean syntax based on C++, no pointers or operator overloading
2. Object-Oriented
Everything in Java revolves around Classes and Objects
3. Platform Independent
Compiles to Bytecode (.class) that runs on any OS with a JVM
4. Secured
No explicit pointers; runs inside a protected JVM Sandbox
5. Robust
Strong memory management, Automatic Garbage Collection & Exception Handling
6. Multithreaded
Executes multiple tasks simultaneously using built-in Thread support
Explanation
- Java source compiles to bytecode for a compatible virtual machine.
- Its runtime also manages memory and supports concurrent tasks.
Figure 1.2: The 4 Pillars of Object-Oriented Programming (OOP)
Figure 1.2: The 4 Pillars of Object-Oriented Programming (OOP)
1. Encapsulation
Binding data (private variables) and methods together into a single capsule (Class)
2. Abstraction
Hiding complex internal implementation details and showing only essential features
3. Inheritance
Child class acquiring properties and behaviors of a Parent class (Code Reusability)
4. Polymorphism
"One name, many forms" — achieved via Method Overloading and Method Overriding
Explanation
- Encapsulation brings state and behaviour together and abstraction presents essential operations.
- Inheritance shares behaviour and polymorphism allows different implementations of an operation.
Figure 1.3: How Java Achieves Platform Independence (WORA)
Figure 1.3: How Java Achieves Platform Independence (WORA)
HelloWorld.javaJava Source Code
→
javac CompilerChecks syntax & compiles
→
HelloWorld.classUniversal Bytecode
→
OS-Specific JVMWindows / Linux / Mac JVM
→
Machine CodeExecutes on CPU
Explanation
- Compile the source once into a class file for a target Java version.
- A compatible JVM on each platform runs the same bytecode.
Figure 1.4: Internal Architecture of the Java Virtual Machine (JVM)
Figure 1.4: Internal Architecture of the Java Virtual Machine (JVM)
1Class Loader Subsystem
Loads, links, and initializes .class files into RAM (Bootstrap, Extension, Application Loaders)
2Runtime Data Areas (Memory)
Method Area (class data), Heap (objects), Java Stacks (local vars/method calls), PC Register, Native Stack
3Execution Engine
Interpreter + JIT (Just-In-Time) Compiler + Garbage Collector (GC)
Explanation
- The loader brings classes in and runtime areas hold data and execution state.
- The execution engine interprets bytecode or compiles it for the host processor.
Figure 1.5: Relationship Between JDK, JRE, and JVM
Figure 1.5: Relationship Between JDK, JRE, and JVM
JDK (Java Development Kit) — Full kit for Developers (JRE + javac, javadoc, jar, jdb)
JRE (Java Runtime Environment)
For End-Users to RUN Java apps (JVM + Core Libraries java.lang, java.util, etc.)
For End-Users to RUN Java apps (JVM + Core Libraries java.lang, java.util, etc.)
JVM (Java Virtual Machine)
The core engine that executes Bytecode (.class) + JIT Compiler
The core engine that executes Bytecode (.class) + JIT Compiler
Explanation
- The JVM executes bytecode and a runtime supplies the libraries needed to run it.
- The JDK adds tools for writing and compiling programs.
Figure 1.6: Standard Structure of a Java Program
Figure 1.6: Standard Structure of a Java Program
1Documentation Section
Optional — Comments (//, /*...*/, /**...*/) explaining author, date, and purpose
2Package Statement
Optional — Must be the FIRST non-comment line (e.g., package com.campusnotes;)
3Import Statements
Optional — Imports built-in or user packages (e.g., import java.util.Scanner;)
4Interface Section
Optional — Declares interfaces containing abstract methods and constants
5Class Definitions
Optional — Helper classes (e.g., class Student, class Account)
6Main Method Class
Essential — Contains public static void main(String[] args) where execution starts
Explanation
- Package and import declarations establish names before the class definition.
- The main method provides the usual starting point for a simple application.
Figure 1.7: Classification of Data Types in Java
Figure 1.7: Classification of Data Types in Java
Primitive Data Types (8 Types)
- Integers: byte (1B), short (2B), int (4B), long (8B)
- Floating-Point: float (4B), double (8B)
- Character: char (2B - Unicode)
- Boolean: boolean (1 bit - true / false)
Non-Primitive (Reference) Types
- Classes: String, Scanner, Student
- Interfaces: Runnable, ActionListener
- Arrays: int[], String[][]
- Default value of any reference is null
Explanation
- Primitive types hold values such as a number or a boolean.
- Reference variables refer to objects, including arrays.
Figure 1.8: Classification of Control Statements in Java
Figure 1.8: Classification of Control Statements in Java
1. Branching (Decision Making)
if, if-else, if-else-if ladder, nested if, switch-case
2. Looping (Iteration)
for loop, enhanced for-each loop, while loop, do-while loop
3. Jumping (Transfer of Control)
break, continue, return, and Labeled break / continue
Explanation
- Selection chooses a branch and repetition returns to a loop body.
- Jump statements change the usual flow by leaving or skipping part of it.