Java Programming Language
Chapter 1: Introduction
A Comprehensive Guide to Java Fundamentals
Course: 4343203 - Java Programming
What We'll Cover
- Java Overview & History
- Java Features & Applications
- Java Platform Architecture
- Setting up Java Environment
- Basic Java Program Structure
- Compilation & Execution Process
- Bytecode & Garbage Collection
Java Overview
Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible.
- Developer: James Gosling at Sun Microsystems
- Released: 1995
- Philosophy: "Write Once, Run Anywhere" (WORA)
- Current Owner: Oracle Corporation
Brief History & Evolution
Key Java Features
Platform Independence
Write Once, Run Anywhere (WORA)
- Java code compiles to bytecode
- Bytecode runs on any device with JVM
- No need for platform-specific compilation
Object-Oriented
Java strictly follows OOP principles:
- Encapsulation - Data hiding
- Inheritance - Code reusability
- Polymorphism - Multiple forms
- Abstraction - Essential features only
Robust and Secure
Robust Features:
- Strong memory management
- Exception handling
- Type-checking
- Automatic garbage collection
Security Features:
- Sandbox environment
- Bytecode verification
- No explicit pointers
- Runtime security checks
Other Important Features
Multithreaded
Built-in support for concurrent programming
High Performance
JIT compilation and optimization techniques
Rich API
Comprehensive standard library
Dynamic
Runtime memory allocation and class loading
Java Applications
Desktop Applications
- Swing and JavaFX GUIs
- Cross-platform compatibility
- IDE development (NetBeans, Eclipse)
Web Applications
- Servlets and JSPs
- Spring Framework
- Enterprise web development
Mobile Applications
- Android development
- Mobile enterprise applications
Enterprise & Big Data
- Large-scale enterprise systems
- Hadoop and Spark ecosystems
- Scientific applications
Java Platform Architecture
JDK (Java Development Kit)
Full-featured software development kit for Java applications
Includes:
- javac - Java compiler
- javadoc - Documentation generator
- jar - Archive tool
- jdb - Debugger
- JRE - Runtime environment
JRE (Java Runtime Environment)
Minimum requirements to run Java applications
Components:
- JVM - Java Virtual Machine
- Java Class Libraries - Core APIs
- java - Runtime launcher
- Supporting files - Configuration and resources
JVM (Java Virtual Machine)
Abstract computing machine that enables platform independence
Key Components:
- Class Loader Subsystem - Loads bytecode
- Execution Engine - Interprets/compiles bytecode
- Memory Management - Heap, stack, method area
- Garbage Collector - Automatic memory cleanup
Setting up Java Development Environment
Step 1: Download JDK
- Visit Oracle's official website or adopt OpenJDK
- Choose appropriate version for your OS
- Download the installer package
Recommended: Use latest LTS (Long Term Support) version
Step 2: Install JDK
- Run the downloaded installer
- Follow installation wizard
- Note the installation directory
Default locations:
- Windows: C:\Program Files\Java\jdk-version
- macOS: /Library/Java/JavaVirtualMachines/
- Linux: /usr/lib/jvm/
Step 3: Set Environment Variables
JAVA_HOME
# Windows
set JAVA_HOME=C:\Program Files\Java\jdk-11
# Linux/macOS
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
PATH
# Windows
set PATH=%JAVA_HOME%\bin;%PATH%
# Linux/macOS
export PATH=$JAVA_HOME/bin:$PATH
Step 4: Verify Installation
# Check Java version
java -version
# Check compiler version
javac -version
Expected output:
java version "11.0.12" 2021-07-20 LTS
Java(TM) SE Runtime Environment (build 11.0.12+8-LTS-237)
Java HotSpot(TM) 64-Bit Server VM (build 11.0.12+8-LTS-237)
Structure of a Java Program
Basic Java Program
public class MyFirstProgram {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Key Points:
- Class name must match filename
- main() method is the entry point
- Every statement ends with semicolon
Class Declaration
public class MyFirstProgram {
// Class body
}
- public - Access modifier
- class - Keyword to define a class
- MyFirstProgram - Class name (must match filename)
- Class body enclosed in curly braces { }
Main Method
public static void main(String[] args) {
// Program logic goes here
}
- public - Accessible from anywhere
- static - No object creation needed
- void - Returns nothing
- main - Special method name
- String[] args - Command line arguments
Output Methods
println() method
System.out.println("Hello, World!");
System.out.println(42);
System.out.println(3.14);
print() method
System.out.print("Hello ");
System.out.print("World!");
// Output: Hello World!
Difference: println() adds a new line, print() doesn't
Comments in Java
Single-line comments
// This is a single-line comment
System.out.println("Hello World"); // Comment at end of line
Multi-line comments
/* This is a multi-line comment
that spans multiple lines
and explains complex code */
System.out.println("Hello World");
Compilation and Execution Process
Step 1: Write Java Code
Create a file with .java extension
// HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Important: Filename must match the public class name
Step 2: Compile the Code
javac HelloWorld.java
- Compiler (javac) converts source code to bytecode
- Creates HelloWorld.class file
- Bytecode is platform-independent
- If compilation errors occur, fix them first
Step 3: Execute the Program
java HelloWorld
- Use class name (without .class extension)
- JVM interprets and executes bytecode
- Output: Hello, World!
Note: JRE must be installed to run Java programs
Complete Workflow
Source Code (.java)
↓
javac compiler
↓
Bytecode (.class)
↓
JVM
↓
Machine Code
↓
Output
Detailed Compilation & Execution Process
Importance of Bytecode
Bytecode is platform-independent intermediate code generated by Java compiler
Key Benefits:
- Platform Independence - Same bytecode runs on any OS
- Security - Bytecode verification before execution
- Optimization - JIT compilation for better performance
- Portability - "Write Once, Run Anywhere"
Garbage Collection
Garbage Collection is automatic memory management in Java
How it works:
- Automatic - No manual memory deallocation
- Background Process - Runs when needed
- Unreferenced Objects - Collects unused objects
- Memory Efficiency - Prevents memory leaks
Benefits:
- Prevents memory leaks
- Improves program stability
- Simplifies memory management
Chapter Summary
What we learned:
- Java overview and history
- Key features of Java
- Java platform architecture
- Environment setup
What we learned:
- Basic program structure
- Compilation process
- Bytecode importance
- Garbage collection
Next: Data Types and Variables
Thank You!
Questions?
Ready to dive deeper into Java programming!

