Java can feel complicated at the beginning because a new learner immediately hears many unfamiliar words: JDK, JRE, JVM, bytecode, compiler, javac, java, classpath, platform independence, and many more.
But these concepts are not separate pieces that you have to memorize.
They form one simple story:
You write Java source code
↓
Java compiler compiles it
↓
Bytecode is created
↓
JVM reads the bytecode
↓
Your program runsOnce this flow becomes clear, most of the terminology in this chapter becomes much easier.
So instead of memorizing definitions, we will build the complete picture step by step.
This chapter follows the Java introduction scope you supplied, including Java fundamentals, editions, platform architecture, JDK/JRE/JVM, compilation/execution, environment setup, and the first Java program.
1. Before Java: Why Do We Need a Programming Language?#
Think about your computer for a moment.
You can tell another person:
"Add these two numbers."
But a computer does not understand normal human language in the same way.
At the lowest level, computers execute machine instructions.
Those instructions ultimately become binary patterns such as:
10110000 01100001Writing large applications directly using machine instructions would be extremely difficult.
Therefore, programming languages were created.
A programming language gives developers a structured way to express instructions such as:
int total = 10 + 20;
System.out.println(total);The developer writes understandable instructions, and software tools eventually translate those instructions into something the computer can execute.
Different programming languages solve this problem in different ways.
Java is one of them.
But Java became especially important because it introduced a powerful idea:
Compile the source code into an intermediate format that can run on many different operating systems through a Java Virtual Machine.
Keep that idea in mind. We will build it carefully.
2. What Is Java?#
Now that we understand why programming languages exist, we can introduce Java naturally.
Java#
Java is a high-level, class-based, object-oriented, general-purpose programming language and software platform designed to allow applications to run across different environments through the Java Virtual Machine.
That definition contains several terms. Do not memorize it yet.
Let us unpack it.
2.1 High-Level Language#
A high-level programming language allows developers to write instructions using abstractions that are much easier for humans to understand than machine code.
For example:
int age = 25;
if (age >= 18) {
System.out.println("Eligible");
}This is much easier to understand than CPU machine instructions.
Java hides many low-level hardware details from the programmer.
2.2 General-Purpose Language#
A general-purpose language is not designed for only one narrow problem.
Java can be used for many types of applications, including:
- backend systems
- enterprise applications
- financial applications
- web services
- REST APIs
- desktop applications
- distributed systems
- cloud applications
- Android-related development historically and through Java-compatible ecosystems
- data-processing systems
- testing tools
- automation software
This versatility is one reason Java became widely adopted.
2.3 Class-Based Language#
Java programs are primarily organized around classes.
You do not need to understand classes completely yet.
For now, remember this:
A class is a structure in which we can define data and behavior.
Example:
class Employee {
String name;
void work() {
System.out.println("Employee is working");
}
}Later, object-oriented programming will make this much clearer.
2.4 Object-Oriented Language#
Java strongly supports Object-Oriented Programming, commonly called OOP.
OOP organizes software around objects containing:
Data
+
BehaviorFor example, an Employee object may contain:
Data:
name
salary
employeeId
Behavior:
work()
login()
calculateSalary()Java supports important OOP concepts such as:
- encapsulation
- inheritance
- polymorphism
- abstraction
We will not expand those concepts here because they deserve their own chapter.
For now, understand only why this matters:
Java allows large applications to be divided into understandable, reusable software components.
3. Why Was Java Created?#
Before discussing Java's history, consider an older software-development problem.
Suppose a company develops software for one type of computer.
Later, it wants to run the same application on another system.
Traditionally, platform differences could require significant changes or recompilation.
Developers wanted software that could be more portable.
The Java project pursued this idea very strongly.
That brings us to Java's origin.
4. History of Java#
Java originated at Sun Microsystems.
A team led by James Gosling worked on a project beginning in the early 1990s.
The language was initially associated with the name:
OakIt was later renamed:
JavaJava was publicly introduced in the mid-1990s and became strongly associated with the idea:
Write Once, Run Anywhere
Later, Sun Microsystems was acquired by Oracle, and Oracle became the steward of Java.
Java continued evolving through many releases.
The important lesson is not the date memorization.
The important reason Java became significant is its combination of:
- portability
- automatic memory management
- object-oriented programming
- strong standard libraries
- runtime safety mechanisms
- networking capabilities
- enterprise ecosystem
- mature tooling
5. What Problem Did Java Solve?#
Imagine that you create an application for:
WindowsBut your customer wants the same application to run on:
LinuxAnd another customer uses:
macOSA natural question appears:
Do we need a completely different Java program for every operating system?
Java's architecture was designed to reduce this problem.
Instead of compiling Java source code directly into one operating system's native machine instructions, Java normally compiles source code into:
BytecodeThat bytecode is then executed by a:
JVMThis architecture is the foundation of Java's platform independence.
We will examine every part carefully.
6. Features of Java#
Now we have enough context to understand why Java is usually described using a collection of important features.
Do not treat these as marketing words. Each feature describes an actual property of Java's language or runtime ecosystem.
6.1 Simple#
Java was designed to remove or simplify several difficult features commonly associated with lower-level languages.
For example, Java does not expose general-purpose pointer arithmetic in the same way as C or C++.
Memory management is also largely automated.
Instead of manually releasing ordinary Java objects, Java uses garbage collection.
We will discuss garbage collection in a later chapter.
For now:
Java attempts to let developers focus more on application logic and less on manual memory management.
6.2 Object-Oriented#
Java strongly organizes programs around classes and objects.
Example:
class Car {
String model;
void start() {
System.out.println("Car started");
}
}An object created from this class could represent an actual car inside the program.
6.3 Platform Independent#
This is one of Java's most important characteristics.
Consider:
Java Source Code
↓
Java Compiler
↓
Bytecode
↓
JVM for Windows
or
JVM for Linux
or
JVM for macOSThe same compiled bytecode can normally run wherever a compatible JVM exists.
That is the foundation behind:
Write Once, Run Anywhere.
6.4 Portable#
Platform independence and well-defined language/runtime behavior help Java applications move across supported environments.
Java defines consistent primitive type sizes and standardized runtime behavior in many areas.
This improves portability.
But remember:
Platform-independent Java bytecode does not mean every application is automatically portable.
If your program depends on:
- OS-specific files
- native libraries
- platform-specific commands
- hardcoded paths
then portability can still be reduced.
6.5 Secure#
Java includes several mechanisms that contribute to safer application execution.
Examples include:
- bytecode verification
- controlled memory access
- runtime type checking
- class-loading mechanisms
- absence of unrestricted pointer arithmetic in normal Java code
However:
"Java is secure" does not mean "every Java application is automatically secure."
Developers can still introduce:
- SQL injection
- broken authentication
- insecure deserialization
- incorrect authorization
- leaked credentials
- vulnerable dependencies
Language/runtime security and application security are different concerns.
6.6 Robust#
A robust application handles errors and unexpected conditions reliably.
Java supports robustness through mechanisms such as:
- strong type checking
- exception handling
- automatic memory management
- runtime checks
Example:
try {
int value = Integer.parseInt("abc");
} catch (NumberFormatException exception) {
System.out.println("Invalid number");
}You do not need to understand exceptions completely yet.
The important point is:
Java provides structured mechanisms for detecting and responding to many failures.
6.7 Multithreaded#
A thread represents a path of execution inside a process.
A Java application can perform multiple activities concurrently using threads.
For example:
Web Server
Thread 1 → Request from User A
Thread 2 → Request from User B
Thread 3 → Background processingJava provides built-in concurrency APIs.
Multithreading is an advanced subject, so we will leave the detailed mechanics for its dedicated chapter.
6.8 Distributed and Network Friendly#
Java has historically provided strong networking capabilities.
Applications can communicate across machines using:
- sockets
- HTTP libraries
- web frameworks
- messaging systems
- remote APIs
This became especially important for enterprise systems.
6.9 High Performance Through JVM Optimization#
A common beginner misunderstanding is:
"Java uses a JVM, therefore Java must always be slow."
That is too simplistic.
Modern JVM implementations perform sophisticated runtime optimization.
One important mechanism is JIT compilation.
JIT means:
Just-In-Time compilation
Frequently executed bytecode may be compiled into optimized native machine code during program execution.
Simplified view:
Java Source
↓
Bytecode
↓
JVM
↓
Interpreter / JIT optimization
↓
Native machine executionActual JVM internals are more sophisticated, but this model is enough for now.
6.10 Automatic Memory Management#
When objects are no longer reachable, Java's garbage collector can eventually reclaim their memory.
Conceptually:
Object created
↓
Object used
↓
Object becomes unreachable
↓
Garbage Collector may reclaim memoryImportant:
Garbage collection is automatic memory management, not an immediate "delete object" operation.
6.11 Architecture Neutral#
Java bytecode is not designed around one specific CPU instruction set.
The JVM implementation handles the underlying architecture.
This is another piece of Java's portability story.
6.12 Dynamic#
Some classes can be loaded when the application needs them rather than requiring everything to be statically linked into one executable beforehand.
Java's class-loading system supports dynamic loading behavior.
This becomes relevant when studying:
- class loaders
- frameworks
- reflection
- application servers
- plugin systems
Micro-Checkpoint#
At this point, remember:
Java source code is not normally executed directly.
Source Code
↓
Compiler
↓
Bytecode
↓
JVM
↓
ExecutionThis single model will help you understand many upcoming concepts.
7. Java Editions#
A new question naturally appears.
Java is used for everything from desktop applications to enormous enterprise systems.
Does one Java platform specification cover every possible environment in exactly the same way?
Historically, Java has been described through different editions.
7.1 Java SE#
Java SE means:
Java Platform, Standard Edition.
This is the foundation most Java developers learn first.
It provides core language and runtime APIs including areas such as:
- language fundamentals
- collections
- I/O
- networking
- concurrency
- JDBC
- utility APIs
When you learn:
String
ArrayList
HashMap
Thread
Fileyou are largely working within Java SE APIs.
7.2 Java EE / Jakarta EE#
Enterprise applications need additional capabilities.
Examples include:
- web applications
- REST services
- persistence
- transactions
- dependency injection
- messaging
- enterprise security
Historically this platform was called:
Java EEThe ecosystem later transitioned to:
Jakarta EEFor a beginner, remember:
Java SE
↓
Core Java platform
Jakarta EE
↓
Enterprise specifications built around the Java ecosystemSpring and Spring Boot are separate frameworks/ecosystems and should not simply be treated as another name for Jakarta EE.
7.3 Java ME#
Java ME means:
Java Platform, Micro Edition.
It was designed for resource-constrained devices and embedded/mobile environments.
Its historical importance is greater than its importance for most modern enterprise Java developers.
8. Java Editions Comparison#
| Edition | Primary Purpose | Typical Environment |
|---|---|---|
| Java SE | Core Java development | Desktop, backend foundations, libraries |
| Java EE / Jakarta EE | Enterprise applications | Web and enterprise servers |
| Java ME | Resource-constrained devices | Embedded/mobile environments |
Practical Decision Rule#
If you are starting Java programming:
Start with Java SE.Frameworks and enterprise technologies become much easier once the Java SE foundation is strong.
9. Applications of Java#
Now we can ask a practical question:
Where do developers actually use Java?
Java has been used across many domains.
Backend Development#
Java is heavily used for server-side applications.
Common ecosystem examples include:
Java
Spring Framework
Spring Boot
Hibernate
Jakarta EEA typical flow could look like:
Browser / Mobile App
↓
REST API
↓
Spring Boot Java Application
↓
DatabaseBanking and Financial Systems#
Java is widely associated with enterprise and financial software because such systems often value:
- maturity
- maintainability
- strong tooling
- concurrency support
- large ecosystem
- long-term support options
- mature monitoring infrastructure
E-Commerce Systems#
Java can power:
- product services
- order processing
- inventory management
- payment workflows
- notification services
Enterprise Applications#
Large organizations often use Java for:
- HR systems
- insurance software
- healthcare platforms
- billing systems
- workflow systems
- internal business applications
Distributed Systems and Microservices#
Java frameworks are commonly used to create distributed backend services.
Example:
API Gateway
↓
Order Service
Payment Service
Inventory Service
Notification ServiceEach service may be a separate Java application.
Desktop Applications#
Java provides desktop GUI technologies such as Swing and JavaFX.
Desktop development is not Java's only or necessarily dominant modern use, but it remains part of the ecosystem.
10. Java Platform#
We have used the word platform several times.
Before continuing, we need to understand it properly.
A platform is an environment in which software can execute.
For example:
Operating System
Hardware
Runtime Environment
LibrariesJava provides a software execution platform built around the JVM and standard APIs.
That means Java is not merely:
a syntax used to write source code.
It also includes an execution ecosystem.
Conceptually:
Java Language
+
Java Compiler
+
Java Virtual Machine
+
Standard Libraries
=
Java Platform Ecosystem11. Java Development Process#
Suppose a customer gives us this requirement:
Display "Hello Java" on the screen.
How does that requirement become a running Java program?
The simplified development process is:
Requirement
↓
Write Java Source Code
↓
Save .java File
↓
Compile using javac
↓
Generate .class Bytecode
↓
Run using java command
↓
JVM Executes Program
↓
OutputWe will now understand each part individually.
12. Java Source Code#
The code written by a developer is called source code.
Example:
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello Java");
}
}Save it as:
HelloJava.javaThe .java extension identifies a Java source file.
Important distinction:
HelloJava.javacontains source code.
After compilation:
HelloJava.classcontains Java bytecode.
They are not the same file.
13. What Is Compilation?#
The computer does not directly treat our .java source file as JVM bytecode.
Something must translate it.
That translator is the Java compiler.
Java Compilation#
Compilation is the process of converting Java source code into Java bytecode.
The compiler commonly used from the JDK is:
javacExample:
javac HelloJava.javaIf compilation succeeds, a class file is generated:
HelloJava.class14. What Is Bytecode?#
This is one of the most important Java concepts.
A beginner may ask:
Why doesn't javac simply produce Windows machine code?Because Java uses an intermediate representation.
Bytecode#
Bytecode is the instruction format produced by the Java compiler for execution by a compatible JVM.
Simplified flow:
HelloJava.java
↓
javac
↓
HelloJava.class
↓
BytecodeBytecode is not Java source code.
It is also not simply native Windows or Linux machine code.
It is designed for the JVM execution model.
15. Why Bytecode Matters#
Suppose javac produced Windows-specific machine code.
Then Linux could not necessarily execute the same binary.
Instead Java uses:
Source
↓
Bytecode
↓
Platform-specific JVMEach operating system can have its own JVM implementation capable of executing compatible bytecode.
So:
Java Bytecode
/ | \
/ | \
Windows JVM Linux JVM macOS JVM
↓ ↓ ↓
Windows Linux macOSThis architecture is central to Java portability.
16. A New Concept Has Appeared: JVM#
Until now, we have repeatedly said that bytecode runs through the JVM.
If JVM remains unclear, everything after this point will become confusing.
So we should understand it now.
JVM — Java Virtual Machine#
JVM stands for:
Java Virtual Machine
A JVM is the runtime execution engine responsible for executing Java bytecode and providing important runtime services.
Think of it conceptually as a layer between:
Java bytecodeand:
Operating system / hardwareSimplified model:
Java Bytecode
↓
JVM
↓
Operating System
↓
Hardware17. Is the JVM the Same on Every Platform?#
No.
This is a very important interview point.
The bytecode can be platform-independent, but the JVM implementation itself interacts with a particular platform.
For example:
Windows JVM → built for Windows
Linux JVM → built for Linux
macOS JVM → built for macOSTherefore:
JVM implementations are platform-specific, while compatible Java bytecode is designed to be portable across JVM-supported platforms.
This is a much stronger answer than simply saying:
"JVM is platform independent."
That statement can be misleading.
18. What Does the JVM Do?#
At a high level, the JVM is responsible for areas such as:
- loading classes
- verifying bytecode
- managing runtime memory
- executing bytecode
- garbage collection
- runtime type checks
- exception handling infrastructure
- thread management
- runtime optimization
A simplified internal flow is:
.class File
↓
Class Loading
↓
Bytecode Verification
↓
Runtime Structures
↓
Execution Engine
↓
Program ExecutesWe will study the deeper JVM architecture later.
19. A New Question: If JVM Runs Java, What Is JRE?#
This is where beginners frequently become confused.
They hear:
JDK
JRE
JVMand memorize three definitions without understanding how they relate.
Instead, think about what a user needs.
If someone only wants to run a Java program, they need runtime capabilities.
This leads us to the concept historically described as the JRE.
JRE — Java Runtime Environment#
JRE stands for:
Java Runtime Environment
Conceptually, the JRE provides the environment required for running Java applications.
Traditional teaching model:
JRE
│
├── JVM
└── Runtime LibrariesSo:
JVM performs bytecode execution.
while:
JRE represents the broader runtime environment surrounding it.
20. Another Problem Appears: Running Is Not Enough#
A developer does not only run Java applications.
A developer must also:
- compile source code
- inspect tools
- package applications
- debug
- generate documentation
- use development utilities
Therefore, developers need a larger toolset.
That brings us to JDK.
21. JDK — Java Development Kit#
JDK stands for:
Java Development Kit
The JDK contains the tools required for Java development.
Common tools include:
javac
java
javadoc
jar
javapAt a conceptual beginner level:
JDK
│
├── Java runtime capabilities
├── Compiler
└── Development toolsA developer normally installs a JDK.
22. JDK vs JRE vs JVM#
Now we can compare them without memorization.
| Concept | Full Form | Main Role |
|---|---|---|
| JVM | Java Virtual Machine | Executes Java bytecode |
| JRE | Java Runtime Environment | Runtime environment for Java applications |
| JDK | Java Development Kit | Development tools plus runtime capabilities |
Traditional conceptual relationship:
JDK
│
├── Development Tools
│ ├── javac
│ ├── jar
│ ├── javadoc
│ └── ...
│
└── Runtime Environment
│
├── JVM
└── Runtime LibrariesMemory Hook#
Remember:
Want to DEVELOP?
→ JDK
Want to RUN?
→ Runtime capabilities
Who EXECUTES bytecode?
→ JVM23. Important Modern JDK Note#
Older Java teaching material often treats a separately installed standalone JRE as a standard deployment assumption.
Modern Java distributions and deployment practices have evolved.
Today, developers commonly install a JDK, and production runtimes may be created or packaged differently depending on the distribution and deployment model.
Therefore, understand JDK, JRE, and JVM primarily as conceptual roles rather than assuming every modern Java installation must have three physically nested folders exactly matching old diagrams.
This is an important distinction between:
Conceptual architectureand:
Modern distribution packaging24. Platform Independence#
We now have all the pieces needed to understand one of Java's most famous characteristics.
Suppose you compile:
HelloJava.javainto:
HelloJava.classThe class file contains bytecode.
A compatible JVM can execute that bytecode on different supported platforms.
Therefore:
HelloJava.class
↓
┌────────────┼────────────┐
↓ ↓ ↓
Windows JVM Linux JVM macOS JVM
↓ ↓ ↓
Windows Linux macOSThat is Java's basic platform-independence model.
25. Write Once, Run Anywhere#
You may now understand Java's famous expression:
Write Once, Run Anywhere
Often abbreviated:
WORAMeaning:
Write and compile Java code into portable bytecode, then run it on compatible platforms with suitable Java runtime support.
But be careful.
WORA does not mean:
Every Java application automatically works everywhere without any changes.
Platform-specific dependencies can break portability.
Examples:
String path = "C:\\company\\reports\\report.txt";This path assumes Windows conventions.
Another example:
Runtime.getRuntime().exec("some-os-specific-command");Now your application depends on an operating-system command.
So the correct production mindset is:
Java provides strong platform portability, but application design can still introduce platform dependencies.
26. Java Compilation Process#
Let us now slow down and trace exactly what happens.
Suppose we create:
public class Calculator {
public static void main(String[] args) {
int result = 10 + 20;
System.out.println(result);
}
}Saved as:
Calculator.javaWe compile it:
javac Calculator.javaConceptually:
Calculator.java
↓
Lexical / Syntax / Semantic Analysis
↓
Java Compiler
↓
Bytecode Generation
↓
Calculator.classIf the source code violates Java language rules, compilation fails.
Example:
int number = "Hello";This attempts to assign a String value to an int.
The compiler detects the incompatible types.
27. Compile-Time Error#
A compile-time error is an error detected while the source code is being compiled.
Example:
public class Demo {
public static void main(String[] args) {
int number = "Java";
}
}This cannot be compiled successfully because:
"Java"is a String, while:
numberexpects an int.
The program therefore does not reach normal execution.
28. Java Execution Process#
Compilation is only the first half.
Once we have:
Calculator.classwe can run it:
java CalculatorNotice:
java Calculatornot:
java Calculator.classThe launcher locates the class and starts the Java runtime.
Simplified execution:
java Calculator
↓
JVM starts
↓
Class is located
↓
Class is loaded
↓
Bytecode is checked/prepared
↓
main() is invoked
↓
Instructions execute
↓
Output appearsOutput:
3029. Compilation vs Execution#
This difference is extremely important.
| Compilation | Execution |
|---|---|
| Source code is processed | Compiled program runs |
.java is input | compiled class/runtime inputs are used |
javac is commonly used | java launcher is commonly used |
| bytecode may be generated | JVM executes the application |
| compile-time errors can appear | runtime errors can appear |
Memory Rule#
javac = compile
java = run30. Compile-Time vs Runtime#
We have just introduced another important distinction.
Compile Time#
Compile time is when source code is being checked and transformed by the compiler.
Example error:
int value = "Hello";Detected before normal execution.
Runtime#
Runtime is when the compiled application is actually executing.
Example:
public class Demo {
public static void main(String[] args) {
int number = 10 / 0;
System.out.println(number);
}
}This source can compile.
But during execution, integer division by zero causes:
ArithmeticExceptionSo:
Compilation succeeds
↓
Program starts
↓
Problem occurs during execution
↓
Runtime exception31. Java Program Lifecycle#
Now we can connect the entire journey.
1. Requirement
↓
2. Developer writes source code
↓
3. Source saved in .java file
↓
4. javac compiles source
↓
5. Bytecode stored in .class file
↓
6. java command launches application
↓
7. JVM loads required classes
↓
8. Bytecode is prepared/executed
↓
9. Runtime services support execution
↓
10. Program finishesIn a real enterprise project, many additional stages may exist:
Write
↓
Build
↓
Unit Test
↓
Package
↓
Deploy
↓
Run
↓
MonitorBut the fundamental Java lifecycle remains based on the same core model.
32. Before Writing Our First Program, We Need Java Installed#
You now understand what the JDK is conceptually.
The next practical step is to install one.
A JDK distribution contains the tools we need to develop Java programs.
Different JDK distributions exist, but they implement compatible Java standards.
When choosing one for a real project, teams typically consider:
- Java version
- vendor/distribution
- support policy
- licensing
- operating system
- CPU architecture
- organization's production standards
For learning purposes, the important requirement is:
Install a suitable JDK and confirm thejavaandjavaccommands work.
33. Installing JDK#
The exact installer screens depend on the JDK distribution and operating system.
Conceptually the process is:
Choose JDK Distribution
↓
Choose Java Version
↓
Choose Operating System
↓
Choose CPU Architecture
↓
Install / Extract JDK
↓
Configure environment if necessary
↓
Verify java
↓
Verify javacAfter installation, locate the JDK directory.
A typical Windows path might resemble:
C:\Program Files\Java\jdk-XXThe exact location depends on your distribution and version.
34. Checking Java Version#
Open:
Command Promptor another terminal.
Run:
java -versionThis checks the Java runtime/launcher version available from your current command environment.
Then check the compiler:
javac -versionIf both commands work, your development environment is generally on the right track.
35. Why Can java Work While javac Does Not?#
This is a useful debugging question.
Suppose:
java -versionworks.
But:
javac -versionfails.
One possible reason is that your environment exposes runtime tooling but not the JDK compiler location you expect.
Another possibility is:
PATH configuration problemWe therefore need to understand environment variables.
36. What Is an Environment Variable?#
An environment variable is a named configuration value available to processes in the operating system.
Examples:
PATH
JAVA_HOMEThese values can help applications locate software installations.
37. What Is PATH?#
Suppose you enter:
javac HelloJava.javaHow does the operating system know where javac is located?
It searches directories configured in:
PATHIf your JDK's bin directory is included in PATH, the command can normally be found from many working directories.
For example:
C:\Program Files\Java\jdk-XX\binmay be included in PATH.
38. What Is JAVA_HOME?#
Another widely used environment variable is:
JAVA_HOMEJAVA_HOME usually points to the JDK installation root.
Example:
JAVA_HOME=C:\Program Files\Java\jdk-XXNotice:
JAVA_HOMEtypically points to:
jdk-XXnot:
jdk-XX\binThen PATH can include:
%JAVA_HOME%\binConceptually:
JAVA_HOME
↓
JDK Root
PATH
↓
JAVA_HOME/bin
↓
java, javac and other command-line tools39. JAVA_HOME vs PATH#
These are commonly confused.
| Variable | Purpose |
|---|---|
JAVA_HOME | Identifies the JDK installation root for tools that use it |
PATH | Tells the operating system where executable commands can be found |
Example:
JAVA_HOME
C:\Program Files\Java\jdk-21and:
PATH
%JAVA_HOME%\bin40. Common Environment Configuration Mistake#
Risky Configuration#
JAVA_HOME=C:\Program Files\Java\jdk-21\binWhy is this commonly wrong?
Because tools expecting JAVA_HOME generally expect the JDK root.
Preferred#
JAVA_HOME=C:\Program Files\Java\jdk-21Then:
PATH=%JAVA_HOME%\bin;...41. First Java Program#
Now the environment is ready.
Before seeing the code, understand our requirement.
We want Java to print:
Hello JavaThat is all.
We deliberately start with the smallest useful program.
Create:
HelloJava.javaThen write:
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello Java");
}
}Do not try to memorize this immediately.
Several new concepts just appeared.
We will unpack them one by one.
42. public class HelloJava#
Start with:
public class HelloJavaThe keyword:
classdeclares a class.
Its name is:
HelloJavaAt this stage, think of a class as a container that organizes our program.
The keyword:
publicis an access modifier.
It affects accessibility.
Access modifiers are a larger topic and will be taught properly later.
For now, remember only:
public class HelloJavadeclares a publicly accessible class namedHelloJava.
43. Why Must the File Be Named HelloJava.java?#
When a source file contains a top-level public class named:
HelloJavathe source filename is expected to match that public class name:
HelloJava.javaThis would be incorrect:
MyProgram.javaif the public top-level class inside is:
public class HelloJavaA compiler error would occur.
44. Curly Braces#
The braces:
{
}define a block.
Example:
public class HelloJava {
}Everything belonging to the class body appears between these braces.
Inside the class, our main() method has its own block:
public static void main(String[] args) {
}45. A New Concept Appears: Method#
Inside the class we wrote:
public static void main(String[] args)This is a method declaration.
A method represents a named unit of behavior that can execute instructions.
For now:
Class
↓
contains
↓
Method
↓
contains
↓
StatementsOur class contains the main() method.
46. Why Is main() Special?#
When we launch a traditional Java application using:
java HelloJavathe launcher/JVM needs an entry point for the application.
The familiar entry-point method is:
public static void main(String[] args)Conceptually:
JVM starts application
↓
Find entry point
↓
main()
↓
Execute statements47. Understanding public static void main(String[] args)#
This line can intimidate beginners:
public static void main(String[] args)Let us separate it.
public
static
void
main
String[]
argspublic#
Makes the method accessible as required for the normal application-launch contract.
static#
Means the method belongs to the class itself rather than requiring an instance before it can be invoked in the usual way.
Do not worry if this is not fully intuitive yet.
We will learn static properly later.
For now:
The standardmain()entry point is declaredstaticso the launcher can invoke it without first creating your application class object.
void#
void means this method does not return a value to its caller.
Example of a method that returns an integer:
int getNumber() {
return 10;
}But:
void showMessage() {
System.out.println("Hello");
}does not return a value.
Our main() uses:
voidmain#
This is the method name:
mainIt is the conventional application entry-point name used by the Java launcher.
String[]#
This means:
array of String valuesA String represents text.
An array can hold multiple values.
These concepts will be taught properly later.
For now, the launcher can supply command-line arguments as strings.
args#
This is the parameter variable name.
The name is conventional but not magical.
For example, this can also be valid:
public static void main(String[] values) {
}args is simply the common name.
48. System.out.println()#
Now look at:
System.out.println("Hello Java");Several new elements appear.
Let us separate them.
System
↓
out
↓
println()At a beginner level:
Systemis a standard Java class.outprovides access to the standard output stream.println()prints a value and then terminates the line.
So:
System.out.println("Hello Java");prints:
Hello Java49. print() vs println()#
Compare:
System.out.print("Hello ");
System.out.print("Java");Output:
Hello JavaNow:
System.out.println("Hello");
System.out.println("Java");Output:
Hello
JavaSimplified rule:
print()
→ prints without automatically completing the line
println()
→ prints and completes the line50. String Literal#
The text:
"Hello Java"is a String literal.
Quotation marks tell Java that this is text data.
Correct:
System.out.println("Hello Java");Incorrect:
System.out.println(Hello Java);Without the quotes, Java does not treat Hello Java as a string literal.
51. Semicolon#
The line:
System.out.println("Hello Java");ends with:
;Many Java statements use a semicolon terminator.
Missing it may cause a compilation error.
Incorrect:
System.out.println("Hello Java")Correct:
System.out.println("Hello Java");52. Complete First Program Again#
Now the code should look much less mysterious:
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello Java");
}
}Mental model:
HelloJava class
↓
main() entry point
↓
println()
↓
Hello Java53. Compiling the Java Program#
Suppose the file is located in:
C:\java-learningOpen a terminal in that folder.
Check the file:
HelloJava.javaCompile:
javac HelloJava.javaIf successful, you should normally see:
HelloJava.classThe compiler may produce no success message.
That is normal.
Check the folder rather than expecting a message such as:
Compilation successful54. Running the Java Program#
Now run:
java HelloJavaOutput:
Hello JavaThe important relationship is:
javac HelloJava.java
↓
HelloJava.class
java HelloJava
↓
JVM runs application
↓
Hello Java55. javac Command#
javac is the Java compiler tool.
Basic syntax:
javac FileName.javaExample:
javac HelloJava.javaIts job is primarily:
Java Source
↓
Compilation
↓
Bytecode/Class Files56. java Command#
The java launcher starts a Java application.
Typical beginner usage:
java ClassNameExample:
java HelloJavaNotice the difference:
Compile:
javac HelloJava.java
Run:
java HelloJavaThis distinction is one of the first things every Java beginner should remember.
57. Prediction Moment#
Look at this program:
public class Demo {
public static void main(String[] args) {
System.out.println("A");
System.out.println("B");
}
}Before reading further, predict the output.
The result is:
A
BWhy?
Because each println() completes its line.
Now compare:
public class Demo {
public static void main(String[] args) {
System.out.print("A");
System.out.print("B");
}
}Output:
AB58. Passing Command-Line Arguments#
Remember:
String[] argsWe said the launcher can provide command-line arguments.
Consider:
public class Welcome {
public static void main(String[] args) {
System.out.println(args[0]);
}
}Compile:
javac Welcome.javaRun:
java Welcome DattatrayOutput:
DattatrayWhat happened?
Command:
java Welcome Dattatray
↓
args[0]
contains
"Dattatray"Important: this program assumes at least one argument exists.
If we run:
java Welcomethe program can fail at runtime because args[0] does not exist.
That introduces an important beginner lesson:
Code may compile successfully and still fail during execution.
59. Common Beginner Error: javac Not Recognized#
Suppose Windows shows something like:
'javac' is not recognized...Possible causes include:
- JDK not installed
- wrong PATH
- PATH not refreshed in the terminal
- incorrect JDK installation path
- environment configuration pointing somewhere else
Debugging sequence:
Is JDK installed?
↓
Locate JDK
↓
Check bin directory
↓
Check JAVA_HOME
↓
Check PATH
↓
Open new terminal
↓
javac -version60. Common Beginner Error: Wrong File Name#
Code:
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello");
}
}Saved as:
Demo.javaProblem:
public class HelloJavadoes not match:
Demo.javaPreferred:
HelloJava.java61. Common Beginner Error: Running the File Incorrectly#
After compilation, a beginner may write:
java HelloJava.classIn traditional class launching, this is incorrect.
Use:
java HelloJavaThink:
javac → source filename
java → class name62. Common Beginner Error: Wrong Capitalization#
Java is case-sensitive.
These identifiers are different:
HelloJava
hellojava
HELLOJAVASimilarly:
Systemis not the same as:
systemWrong:
system.out.println("Hello");Correct:
System.out.println("Hello");63. Common Beginner Error: String vs string#
Wrong:
public static void main(string[] args)Correct:
public static void main(String[] args)Java is case-sensitive, and:
Stringis the correct standard class name.
64. Common Beginner Error: Misspelling main#
Wrong:
public static void Main(String[] args)This declares a method named:
Mainnot:
mainFor the standard launch entry point, use:
public static void main(String[] args)65. Common Beginner Error: Missing static#
Suppose:
public class Demo {
public void main(String[] args) {
System.out.println("Hello");
}
}This is a method called main, but it does not match the standard launcher entry-point signature expected for normal execution.
Preferred:
public class Demo {
public static void main(String[] args) {
System.out.println("Hello");
}
}66. Common Beginner Error: Missing Quotes#
Wrong:
System.out.println(Hello);Unless a variable named Hello exists, the compiler does not know what Hello refers to.
Correct:
System.out.println("Hello");67. Common Beginner Error: Missing Semicolon#
Wrong:
System.out.println("Hello")Correct:
System.out.println("Hello");This normally becomes a compilation issue.
68. Common Beginner Error: Mismatched Braces#
Wrong:
public class Demo {
public static void main(String[] args) {
System.out.println("Hello");
}One closing brace is missing.
Preferred formatting:
public class Demo {
public static void main(String[] args) {
System.out.println("Hello");
}
}Indentation helps you see block structure.
69. Common Beginner Error: Compiling from the Wrong Directory#
Suppose:
HelloJava.javais located in:
C:\java-learningbut your terminal is currently in:
C:\Users\UserThen:
javac HelloJava.javamay fail because the compiler cannot find the file in the current directory.
First change directory:
cd C:\java-learningThen compile:
javac HelloJava.java70. Common Beginner Error: Confusing JDK with IDE#
Another common misconception is:
"I installed IntelliJ IDEA / Eclipse / VS Code, so Java must already be installed."
An IDE is a development environment.
Examples:
IntelliJ IDEA
Eclipse
VS CodeA JDK provides Java development/runtime tooling.
They are different things.
Conceptually:
IDE
↓
Helps you write/debug/manage code
JDK
↓
Provides Java compiler/runtime development toolsAn IDE can be configured to use an installed JDK.
71. IDE vs JDK vs JVM#
| Component | Role |
|---|---|
| IDE | Developer productivity environment |
| JDK | Java development toolkit |
| JVM | Bytecode execution engine |
A useful mental model:
You
↓
IDE / Editor
↓
Java Source Code
↓
JDK tools
↓
Bytecode
↓
JVM
↓
Running Program72. How Java Works — Complete Mental Model#
We can now connect everything.
Developer
↓
Writes Java source code
↓
Example.java
↓
javac
↓
Bytecode
↓
Example.class
↓
java launcher
↓
JVM
↓
Class loading + runtime processing
↓
Execution engine
↓
Native execution
↓
Operating system / hardwareThis diagram is the heart of Chapter 1.
73. Internal Working — Beginner Layer#
At the simplest level:
.java
↓
javac
↓
.class
↓
JVM
↓
outputIf you remember only one internal diagram today, remember this one.
74. Internal Working — Developer Layer#
A little deeper:
Java Source
↓
Compiler
↓
Bytecode
↓
JVM starts
↓
Required classes loaded
↓
Bytecode verified/prepared
↓
Execution engine executes
↓
Runtime services manage program75. Internal Working — More Advanced Preview#
A JVM commonly involves broad subsystems such as:
Class Loader Subsystem
↓
Runtime Data Areas
↓
Execution Engine
↓
Native Interfaces / Libraries where requiredRuntime memory areas include concepts such as:
- heap
- thread stacks
- method-related metadata areas
- program counters
- native method stacks
Do not attempt to memorize those now.
They belong in JVM architecture and memory-management topics.
For this chapter, understand only:
The JVM is a complete runtime system, not merely a command that prints output.
76. JIT Compilation#
We previously said bytecode is executed by the JVM.
But modern JVM execution is not simply:
Read one bytecode instruction
Execute it
Repeat foreverJVM implementations can optimize frequently executed code.
One important technique is JIT compilation.
Conceptually:
Bytecode
↓
Execution begins
↓
Frequently executed code detected
↓
JIT compiler
↓
Optimized native machine codeThis can dramatically improve long-running application performance.
77. JVM Startup vs Long-Running Performance#
This introduces an interesting production idea.
A managed runtime like the JVM may spend time:
- starting
- loading classes
- profiling code
- compiling hot code
- optimizing execution
Therefore, performance is not always best described by one simple statement such as:
"Java is fast."
or:
"Java is slow."
A better engineering answer is:
JVM performance depends on workload, runtime implementation, startup behavior, optimization, memory configuration, application design, I/O characteristics, and many other factors.
78. Java Source Is Platform Independent — Is That the Best Statement?#
You may hear:
"Java source code is platform independent."
That is incomplete.
The stronger idea is:
Java language source is portable when it avoids platform-specific assumptions, and compiled Java bytecode targets the JVM specification rather than one ordinary native operating-system executable format.
Platform independence is a system-level property involving:
Language rules
+
Bytecode
+
JVM implementations
+
Standard APIs
+
Portable application design79. Java Is Compiled or Interpreted?#
This is a famous interview question.
Many beginners answer either:
Java is compiled.
or:
Java is interpreted.
Both alone can be oversimplified.
A stronger answer is:
Java source code is compiled into bytecode by the Java compiler. The JVM then executes that bytecode, and modern JVMs may interpret code and/or JIT-compile frequently executed code into native machine code.
Simplified:
Source
↓ compilation
Bytecode
↓ JVM execution
Interpretation / JIT
↓
Machine execution80. Is Java 100% Object-Oriented?#
Another common interview trap.
Java is strongly object-oriented, but it includes primitive types such as:
int
long
double
boolean
charExample:
int age = 30;age is not itself an ordinary object.
Therefore, calling Java "purely object-oriented" requires qualification.
A safer interview answer:
Java is an object-oriented language, but it is not generally considered purely object-oriented because it includes primitive data types and other language constructs outside a strict everything-is-an-object model.
81. Is Java the Same as JavaScript?#
No.
Their names cause frequent beginner confusion.
Java
≠
JavaScriptThey are distinct programming languages with different:
- type systems
- runtimes
- syntax rules
- ecosystems
- typical execution environments
- historical origins
Do not assume that learning Java automatically means learning JavaScript.
82. Production Perspective#
Chapter 1 may look basic, but misunderstandings here can cause real production problems.
A production Java developer should understand several fundamentals.
Java Version Matters#
A project may target a specific Java version.
Using an API introduced in a newer Java version can break compilation or deployment against an older target.
Never assume:
Works on my machine
=
Works in productionJDK Distribution Matters Operationally#
Organizations may standardize on specific JDK distributions based on:
- support
- licensing
- security updates
- certification
- infrastructure compatibility
Environment Configuration Matters#
Incorrect:
JAVA_HOME
PATHcan cause build tools and IDEs to use different JDK versions.
This can create confusing failures.
Build and Runtime Versions Must Be Compatible#
Imagine:
Developer compiles using newer Java target
↓
Production has incompatible older runtime
↓
Application fails to startThis is why teams deliberately manage:
- compiler target
- runtime version
- build configuration
- CI/CD environment
- container image
83. Wrong vs Preferred: Hardcoding OS-Specific Paths#
Risky#
String file = "C:\\reports\\data.txt";Why risky?
Because the path assumes Windows conventions.
More Portable Thinking#
Applications often use platform-aware path APIs and configuration instead of hardcoding environment-specific filesystem assumptions.
A later Java I/O chapter will teach this properly.
The lesson here is:
Platform independence can be reduced by application-level choices.
84. Wrong vs Preferred: Assuming java -version Proves Everything#
Suppose:
java -versionworks.
A beginner may conclude:
"My Java development setup is complete."
Not necessarily.
Also check:
javac -versionbecause development requires compiler tooling.
85. Wrong vs Preferred: Memorizing JDK/JRE/JVM#
Weak Learning#
JDK = development
JRE = runtime
JVM = virtual machineYou may memorize this and still understand nothing.
Strong Understanding#
I write source code
↓
I need compiler/tools
↓
JDK
Compilation produces bytecode
↓
I need execution environment
↓
runtime capabilities
Bytecode must actually execute
↓
JVMUnderstanding relationships is more valuable than memorizing isolated definitions.
86. Important Edge Cases and Traps#
Trap 1 — Compilation Success Does Not Guarantee Runtime Success#
Example:
public class Demo {
public static void main(String[] args) {
System.out.println(args[0]);
}
}Compiles.
But:
java Demowith no argument may fail at runtime.
Trap 2 — Platform Independence Is Not Absolute#
Java bytecode portability does not neutralize every platform-specific dependency.
Trap 3 — JVM Is Not Bytecode#
Bytecode:
instructionsJVM:
runtime that executes those instructionsTrap 4 — JVM Is Not the JDK#
JVM:
executionJDK:
development toolkitTrap 5 — IDE Is Not Java#
An editor/IDE assists development but is not itself the Java language or JVM.
Trap 6 — .java Is Not .class#
.java
→ source
.class
→ compiled class/bytecode representation87. Decision Rules#
Use these rules during development and interviews.
Need to write and compile Java?
→ Use a JDK.
Need to compile source manually?
→ javac
Need to launch a compiled Java application?
→ java
Need to identify installed launcher/runtime version?
→ java -version
Need to identify compiler version?
→ javac -version
Need operating system to find Java commands?
→ PATH
Need tools to know the JDK installation root?
→ JAVA_HOME
Need portable Java execution model?
→ bytecode + compatible JVM88. Complete Revision#
You have now covered the complete foundation of this chapter.
Let us compress the chapter into a fast revision system.
One-Line Definitions#
Java: A general-purpose, class-based, object-oriented programming language and platform centered around the JVM ecosystem.
Source Code: Human-readable Java program stored in .java files.
Compiler: Software that converts Java source code into bytecode.
Bytecode: JVM-oriented intermediate instructions typically stored in .class files.
JVM: Runtime engine responsible for executing Java bytecode.
JRE: Conceptual/runtime environment required for Java application execution.
JDK: Java development toolkit containing compiler and development/runtime tooling.
javac: Java compiler command.
java: Java application launcher.
Platform Independence: Ability of compatible Java bytecode/application code to execute across supported platforms through appropriate JVM implementations.
WORA: Write Once, Run Anywhere.
PATH: Environment variable used by the operating system to locate executable commands.
JAVA_HOME: Common environment variable identifying the JDK installation root.
89. Core Syntax to Remember#
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello Java");
}
}Compile:
javac HelloJava.javaRun:
java HelloJava90. Complete Compilation and Execution Flow#
HelloJava.java
↓
javac
↓
HelloJava.class
↓
java HelloJava
↓
JVM
↓
Class loading
↓
Bytecode execution / runtime optimization
↓
Operating System / Hardware
↓
Output91. Important Comparisons#
.java vs .class#
.java | .class |
|---|---|
| Source code | Compiled representation |
| Written/read by developer | Primarily consumed by JVM/tooling |
| Input to compiler | Result of compilation |
| Human-friendly | Bytecode representation |
javac vs java#
javac | java |
|---|---|
| Compiler | Launcher |
| Compiles source | Starts application |
Common input: .java | Common input: class/module/JAR launch configuration |
| Produces class files | Executes application through runtime |
JDK vs JVM#
| JDK | JVM |
|---|---|
| Development toolkit | Execution engine/runtime abstraction |
| Contains developer tools | Executes bytecode |
Includes javac | Does not mean "Java compiler" |
| Used during development | Essential to Java execution model |
Compile-Time vs Runtime#
| Compile-Time | Runtime |
|---|---|
| Code is compiled | Application executes |
| Language/type errors may appear | Runtime exceptions/problems may appear |
| Before execution | During execution |
92. If You Remember Only 10 Things#
- Java source code is normally stored in
.javafiles. javaccompiles Java source.- Compilation produces JVM bytecode/class files.
- The JVM executes Java bytecode.
javalaunches Java applications.- The JDK provides Java development tooling.
- Java portability comes largely from bytecode plus platform-specific JVM implementations.
JAVA_HOMEusually identifies the JDK root;PATHhelps locate commands such asjavaandjavac.- Java is case-sensitive.
- Compilation success does not guarantee runtime success.
93. Memory Hooks#
JDK
→ Develop
JVM
→ Execute
javac
→ Compile
java
→ Launch
.java
→ Source
.class
→ Bytecode representation
PATH
→ Find commands
JAVA_HOME
→ Find JDK94. Final Knowledge Map#
Introduction to Java
│
├── Java Foundation
│ ├── What is Java?
│ ├── History
│ ├── Features
│ └── Applications
│
├── Java Editions
│ ├── Java SE
│ ├── Java EE / Jakarta EE
│ └── Java ME
│
├── Java Platform
│ │
│ ├── Source Code
│ │ └── .java
│ │
│ ├── Compiler
│ │ └── javac
│ │
│ ├── Bytecode
│ │ └── .class
│ │
│ ├── JVM
│ │ ├── Class Loading
│ │ ├── Runtime Execution
│ │ ├── Runtime Memory
│ │ ├── Garbage Collection
│ │ └── JIT Optimization
│ │
│ ├── JRE
│ │ └── Runtime Concept
│ │
│ └── JDK
│ ├── javac
│ ├── java
│ └── Development Tools
│
├── Platform Independence
│ ├── Bytecode
│ ├── Platform-specific JVM
│ └── Write Once, Run Anywhere
│
├── Development Process
│ ├── Write
│ ├── Compile
│ ├── Generate Bytecode
│ └── Execute
│
├── Environment Setup
│ ├── Install JDK
│ ├── java -version
│ ├── javac -version
│ ├── JAVA_HOME
│ └── PATH
│
├── First Program
│ ├── class
│ ├── main()
│ ├── System.out.println()
│ ├── Compile
│ └── Run
│
└── Debugging Foundation
├── Compile-Time Errors
├── Runtime Errors
├── Wrong File Name
├── Wrong Command
├── Case Sensitivity
├── PATH Problems
└── Version Problems