Java Introduction Tutorial for Beginners: Complete Guide
Introduction
Java is a high-level, class-based, object-oriented programming language widely used for building web applications, enterprise software, backend systems, cloud applications, desktop applications, Android applications, and distributed systems.
Java was designed around the idea of "Write Once, Run Anywhere" (WORA). Java source code is compiled into bytecode, and compatible Java Virtual Machines (JVMs) execute that bytecode on different operating systems.
Whether you want to become a Java Developer, Backend Developer, Software Engineer, Android Developer, or prepare for programming interviews, Java provides a strong foundation for learning modern software development.
In this tutorial, you will learn:
- What Java is
- History of Java
- Features of Java
- Applications of Java
- Java editions
- Java versions and LTS releases
- Java architecture
- JDK, JRE, and JVM
- Platform independence
- WORA
- How to install Java
- How to set up a Java development environment
- How to write your first Java program
- How to compile and run Java code
Table of Contents
- What Is Java?
- History of Java
- Why Learn Java?
- Features of Java
- Applications of Java
- Java Editions
- Java Version History
- Java Architecture
- JDK, JRE, and JVM
- How Java Works
- Platform Independence
- Write Once, Run Anywhere
- Installing the JDK
- Setting Up VS Code for Java
- Setting Up IntelliJ IDEA for Java
- Writing Your First Java Program
- Compiling and Running a Java Program
- Common Java Commands
- Java Advantages and Limitations
- Summary
- Practice Exercises
- Frequently Asked Questions
What Is Java?
Java is a high-level, class-based, object-oriented programming language originally developed at Sun Microsystems.
Java was designed to provide portability, reliability, security, and automatic memory management while supporting large-scale software development.
Unlike languages that compile directly to platform-specific machine code, Java source code is normally compiled into Java bytecode.
The bytecode is stored in .class files and executed by the JVM.
Simple Java execution model
1Java Source Code 2 │ 3 ▼ 4 javac 5 │ 6 ▼ 7Java Bytecode 8 (.class) 9 │ 10 ▼ 11 JVM 12 │ 13 ▼ 14Machine Code 15 │ 16 ▼ 17 Operating System
Because JVM implementations exist for different operating systems, the same Java bytecode can generally run across Windows, Linux, macOS, and other supported platforms.
History of Java
Java began as a project at Sun Microsystems in 1991. The original project was known as the Oak project and was led by James Gosling and his team.
The language was later renamed Java and publicly released in 1995.
Java history timeline
| Year | Event |
|---|---|
| 1991 | Oak project started at Sun Microsystems |
| 1995 | Java was publicly introduced |
| 1996 | JDK 1.0 released |
| 2004 | Java 5 introduced generics, annotations, and enhanced for-loops |
| 2010 | Oracle completed acquisition of Sun Microsystems |
| 2014 | Java 8 introduced lambda expressions and the Streams API |
| 2017 | Java 9 introduced the Java Platform Module System |
| 2018 | Java 11 released as an LTS version |
| 2021 | Java 17 released as an LTS version |
| 2023 | Java 21 released as an LTS version |
| 2025 | Java 25 released as an LTS version |
Java continues to evolve through the OpenJDK project and Java ecosystem.
Why Learn Java?
Java remains an important programming language because it is widely used in backend development, enterprise software, Android development, cloud applications, and large-scale systems.
Learning Java can help you understand important programming concepts such as:
- Object-oriented programming
- Classes and objects
- Inheritance
- Polymorphism
- Exception handling
- Collections
- Generics
- Multithreading
- File handling
- Networking
- Database connectivity
- API development
Java is also commonly used with frameworks such as Spring Boot, making it an important language for backend and enterprise application development.
Features of Java
Java provides several features that make it suitable for developing reliable and scalable applications.
1. Simple
Java was designed with a relatively clean syntax and removes several low-level features associated with languages such as C and C++.
It does not provide direct pointer arithmetic, which reduces several categories of memory-related programming errors.
2. Object-Oriented
Java is a class-based object-oriented language.
Its object-oriented programming model includes:
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
These concepts help developers organize large applications into reusable and maintainable components.
3. Platform Independent
Java source code is compiled into platform-independent bytecode.
A compatible JVM on each operating system executes that bytecode.
1Java Source Code 2 │ 3 ▼ 4 javac 5 │ 6 ▼ 7 Bytecode 8 │ 9 ┌─────┼─────┐ 10 ▼ ▼ ▼ 11JVM JVM JVM 12Win Linux macOS
4. Secure
Java provides several mechanisms that contribute to application security, including:
- Bytecode verification
- Type safety
- Memory safety
- Controlled class loading
- No direct pointer arithmetic
Note that the old Java Security Manager mechanism is deprecated and should not be presented as a modern security feature.
5. Robust
Java provides features that help developers create reliable applications.
These include:
- Strong type checking
- Exception handling
- Automatic memory management
- Garbage collection
6. Multithreaded
Java provides built-in support for concurrent programming.
Applications can use multiple threads to perform different tasks concurrently.
Examples include:
- Network servers
- Background processing
- Streaming applications
- Web applications
- Real-time services
Modern Java also provides virtual threads, which make certain high-concurrency applications easier to build.
7. High Performance
Java applications are executed by modern JVMs that use techniques such as:
- Just-In-Time (JIT) compilation
- Runtime optimization
- Adaptive optimization
- Efficient garbage collectors
As a result, Java can provide high performance for many server-side and enterprise workloads.
8. Portable
Java bytecode uses a standardized format that can be executed by compatible JVM implementations on different platforms.
9. Distributed
Java provides networking and distributed-computing APIs that can be used to build applications communicating across networks.
10. Dynamic
Java supports dynamic class loading and runtime linking.
Classes can be loaded when they are needed during program execution.
Applications of Java
Java is used across many areas of software development.
Web and Backend Applications
Java is widely used for server-side applications and backend systems.
Popular technologies include:
- Spring
- Spring Boot
- Jakarta EE
- Hibernate
Enterprise Applications
Large organizations use Java for systems such as:
- Banking applications
- Enterprise resource planning
- Customer relationship management
- Payment systems
- Business management platforms
Android Applications
Java has historically been one of the major programming languages used for Android development.
Today, Android development primarily uses Kotlin, but Java remains supported and widely used in existing Android applications and libraries.
Cloud Applications
Java is widely used to build:
- REST APIs
- Microservices
- Cloud services
- Distributed systems
- Backend applications
Big Data
Java is used in several big-data technologies and ecosystems.
Examples include:
- Apache Hadoop
- Apache Spark
- Apache Kafka
Desktop Applications
Java can be used to build desktop applications using technologies such as:
- JavaFX
- Swing
Embedded and IoT Applications
Java and related JVM technologies can be used in certain embedded and IoT environments.
Java Editions
Java has historically been organized into different editions for different development requirements.
Java SE
Java Standard Edition (Java SE) provides the core Java platform.
It includes APIs and features for:
- Core programming
- Collections
- Input and output
- Networking
- Multithreading
- Concurrency
- Date and time
- File handling
Java SE is the foundation for learning Java programming.
Jakarta EE
Jakarta EE is the enterprise Java platform maintained by the Eclipse Foundation.
It provides specifications and APIs for developing enterprise applications, including technologies for:
- Web applications
- REST services
- Dependency injection
- Persistence
- Messaging
- Enterprise services
Jakarta EE evolved from the platform previously known as Java EE.
Java ME
Java Micro Edition (Java ME) was designed for constrained devices and embedded environments.
Its relevance depends on the particular embedded platform and application requirements.
Java Version History
Java has received regular feature releases, with selected versions designated as Long-Term Support (LTS) releases by the relevant JDK vendors.
| Java Version | Release Year | Important Features |
|---|---|---|
| Java 1.0 | 1996 | Initial Java release |
| Java 5 | 2004 | Generics, annotations, enhanced for-loop |
| Java 8 | 2014 | Lambda expressions, Streams API |
| Java 9 | 2017 | Java Platform Module System |
| Java 11 | 2018 | LTS release |
| Java 17 | 2021 | LTS release, modern language improvements |
| Java 21 | 2023 | LTS release, virtual threads and other features |
| Java 25 | 2025 | LTS release |
For learning Java, Java 21 or Java 25 are good modern choices when your course, framework, or project supports them.
Java Architecture
Java development involves several important components.
1 Java Source Code 2 │ 3 ▼ 4 Java Compiler 5 javac 6 │ 7 ▼ 8 Java Bytecode 9 (.class) 10 │ 11 ▼ 12 JVM 13 ┌───────────┼───────────┐ 14 │ │ │ 15 Class Loader Runtime Execution Engine 16 Memory 17 │ 18 ▼ 19 Operating System 20 │ 21 ▼ 22 Hardware
The main components are described below.
Java Development Kit (JDK)
The JDK is the software development kit used to develop Java applications.
It provides:
- Java compiler
- Java launcher
- Java debugging and diagnostic tools
- Packaging tools
- Documentation tools
- Java libraries and runtime components
Modern JDK distributions are the standard way to install a complete Java development environment.
Java Runtime Environment (JRE)
The term JRE historically referred to a runtime package containing the JVM and Java runtime libraries.
Modern JDK distributions generally do not provide a separate downloadable JRE in the same way older Java versions did.
For modern Java development, you normally install a JDK, which provides the components needed to develop and run Java applications.
Java Virtual Machine (JVM)
The JVM is the runtime engine responsible for executing Java bytecode.
Major JVM responsibilities include:
- Loading classes
- Linking classes
- Bytecode verification
- Managing runtime memory
- Executing bytecode
- JIT compilation
- Garbage collection
- Thread management
How Java Works
When you write a Java program, it normally passes through several stages.
Step 1: Write Java Source Code
You create a file such as:
1HelloWorld.java
Step 2: Compile the Source Code
The Java compiler is used:
1javac HelloWorld.java
The compiler produces bytecode:
1HelloWorld.class
Step 3: Start the JVM
You run the program using:
1java HelloWorld
Step 4: Class Loading
The JVM loads the required classes using its class-loading mechanism.
Step 5: Verification and Linking
The JVM performs required linking and verification operations before execution.
Step 6: Execution
The JVM execution engine interprets bytecode and may compile frequently executed code into native machine code using JIT compilation.
Complete Process
1HelloWorld.java 2 │ 3 ▼ 4 javac 5 │ 6 ▼ 7HelloWorld.class 8 │ 9 ▼ 10 JVM 11 │ 12 ├── Class Loading 13 ├── Linking 14 ├── Verification 15 └── Execution 16 │ 17 ▼ 18 Machine Code 19 │ 20 ▼ 21 Output
Platform Independence
One of Java's most important characteristics is platform independence.
In traditional native compilation, a program may need to be compiled specifically for a particular operating system and processor architecture.
Java takes a different approach.
1 Java Source 2 │ 3 ▼ 4 javac 5 │ 6 ▼ 7 Java Bytecode 8 │ 9 ┌──────────┼──────────┐ 10 ▼ ▼ ▼ 11 Windows Linux macOS 12 │ │ │ 13 JVM JVM JVM 14 │ │ │ 15 ▼ ▼ ▼ 16 Execute Execute Execute
The bytecode remains the same while the JVM implementation is platform-specific.
Therefore, Java provides portability across supported platforms.
Write Once, Run Anywhere (WORA)
WORA stands for Write Once, Run Anywhere.
The basic idea is:
- Write Java source code.
- Compile it into Java bytecode.
- Run the bytecode using a compatible JVM.
For example:
1javac HelloWorld.java
produces:
1HelloWorld.class
The resulting class can potentially be used on another operating system with a compatible Java runtime and required dependencies.
WORA does not mean that every Java application is automatically identical on every platform. Applications may still depend on operating-system features, native libraries, file paths, graphics systems, or external dependencies.
Installing the JDK
To develop Java applications, install a JDK from a trusted JDK provider.
Common choices include:
- Oracle JDK
- OpenJDK
- Eclipse Temurin
- Amazon Corretto
- Microsoft Build of OpenJDK
Choose a version compatible with the frameworks and projects you plan to use.
Verify Java Installation
Open a terminal and run:
1java -version
Then check the Java compiler:
1javac -version
Example:
1java version "21.x.x" 2javac 21.x.x
The exact version displayed depends on the installed JDK.
JAVA_HOME Environment Variable
JAVA_HOME is an environment variable commonly used by Java development tools to locate the JDK installation.
For example:
Windows
1JAVA_HOME=C:\Program Files\Java\jdk-21
Linux
1export JAVA_HOME=/path/to/jdk-21
macOS
1export JAVA_HOME=/path/to/jdk-21
Tools such as Maven and Gradle commonly use JAVA_HOME when locating a JDK.
Setting Up VS Code for Java
Visual Studio Code can be used as a lightweight Java development environment.
Steps
- Install the JDK.
- Install Visual Studio Code.
- Open the Extensions section.
- Install the Extension Pack for Java.
- Create or open a Java project.
- Select the appropriate JDK if requested.
- Create a Java source file.
- Compile and run the program.
VS Code is useful when you want a lightweight editor with Java development features.
Setting Up IntelliJ IDEA for Java
IntelliJ IDEA is a popular IDE for Java development.
Steps
- Install a JDK.
- Install IntelliJ IDEA.
- Create a new Java project.
- Select the installed JDK.
- Create a Java class.
- Write your Java code.
- Run the application using the IDE.
IntelliJ IDEA provides features such as code completion, debugging, refactoring, project management, and testing support.
Writing Your First Java Program
Create a file named:
1HelloWorld.java
Add the following code:
1public class HelloWorld { 2 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 7}
Understanding the Program
The following statement declares a class:
1public class HelloWorld
The program starts from the main() method:
1public static void main(String[] args)
The following statement prints text to the console:
1System.out.println("Hello, World!");
Output
1Hello, World!
Compile a Java Program
Open a terminal in the directory containing HelloWorld.java.
Run:
1javac HelloWorld.java
If compilation succeeds, Java generates:
1HelloWorld.class
The .class file contains Java bytecode.
Run a Java Program
Run the compiled class with:
1java HelloWorld
The output is:
1Hello, World!
When using the traditional class-name form, do not write:
1java HelloWorld.class
Use:
1java HelloWorld
Common Java Commands
Check Java Version
1java -version
Check Compiler Version
1javac -version
Compile a Java File
1javac HelloWorld.java
Run a Java Class
1java HelloWorld
Display Java Command Help
1java --help
Display Compiler Help
1javac --help
Check Java Location on Windows
1where java
Check Java Location on Linux and macOS
1which java
These commands are useful when troubleshooting Java installation and PATH configuration problems.
Advantages of Java
Java provides several advantages for software development.
- Platform portability
- Object-oriented programming
- Automatic memory management
- Large standard library
- Strong ecosystem
- Large developer community
- Mature development tools
- Extensive enterprise adoption
- Multithreading and concurrency support
- Strong framework ecosystem
- Long-term support releases
Limitations of Java
Java also has some limitations.
- More verbose than some modern programming languages
- JVM startup can add overhead for certain applications
- Garbage collection requires runtime management
- Higher memory usage than some lower-level languages
- Not ideal for every low-level or systems-programming task
- Some applications require additional framework configuration
Choosing Java depends on the requirements of the project.
Java vs Other Programming Languages
Java is one of many programming languages available to developers.
| Language | Common Uses |
|---|---|
| Java | Backend, enterprise, Android, cloud |
| Python | AI, data science, automation, backend |
| C | Systems programming, embedded systems |
| C++ | Games, systems, high-performance applications |
| JavaScript | Web development, frontend, backend |
| Go | Cloud services, networking, infrastructure |
| Rust | Systems programming, performance-critical software |
Java is particularly strong for large backend applications, enterprise systems, and applications requiring a mature ecosystem.
Summary
In this Java introduction tutorial, you learned:
- What Java is
- Why Java is widely used
- The history of Java
- Important Java features
- Applications of Java
- Java SE and Jakarta EE
- Java version history
- LTS versions
- Java architecture
- JDK, JRE, and JVM
- How Java source code becomes bytecode
- How the JVM executes Java programs
- Platform independence
- The WORA principle
- How to install a JDK
- How to configure
JAVA_HOME - How to set up VS Code
- How to set up IntelliJ IDEA
- How to write your first Java program
- How to compile Java source code
- How to run a Java class
- Common Java commands
You now have the foundation required to start learning Java variables, data types, operators, conditional statements, loops, arrays, methods, classes, objects, inheritance, polymorphism, exception handling, collections, and multithreading.
Practice Exercises
Beginner Exercises
- Install a current LTS JDK.
- Verify the installation using:
1java -version
- Check the Java compiler:
1javac -version
- Create a file named
HelloWorld.java. - Print your name using
System.out.println(). - Compile the program using
javac. - Run the program using
java. - Find the location of the Java executable using
where javaorwhich java. - Set the
JAVA_HOMEenvironment variable. - Explain the difference between JDK, JRE, and JVM.
Intermediate Exercises
- Create a Java program that prints your name, age, and city.
- Create a program that performs addition, subtraction, multiplication, and division.
- Compile the program from the command line.
- Run the program using the
javacommand. - Explain the complete process from
.javasource code to program execution. - Draw a diagram showing the relationship between the JDK, JVM, bytecode, and operating system.
Frequently Asked Questions
What is Java?
Java is a high-level, class-based, object-oriented programming language used to build applications ranging from backend services to enterprise software and desktop applications.
Why is Java platform independent?
Java source code is compiled into bytecode, which can be executed by a compatible JVM on different operating systems.
What is JVM?
JVM stands for Java Virtual Machine. It is the runtime environment that executes Java bytecode.
What is JDK?
JDK stands for Java Development Kit. It provides the tools and components required to develop and run Java applications.
What is JRE?
JRE historically referred to the runtime environment containing the JVM and Java runtime libraries. With modern Java distributions, developers generally install a JDK rather than a separate JRE.
Is Java difficult to learn?
Java has a structured syntax and a large ecosystem. Beginners can start with basic syntax and gradually learn object-oriented programming, collections, exceptions, concurrency, and frameworks.
Which Java version should beginners learn?
For a new project or learning environment, a current LTS JDK such as Java 21 or Java 25 is a sensible choice, provided it is supported by the tools and frameworks being used.
Is Java still used?
Yes. Java remains widely used for backend development, enterprise applications, cloud services, distributed systems, Android applications, and many large-scale software systems.