Java Overview
What is Java?
Java is a high-level, object-oriented, and platform-independent programming language. It is designed to have as few implementation dependencies as possible, meaning you can write code once and run it anywhere. Java is widely used for building desktop, web, mobile, and enterprise applications.
It is known for being:
- Simple
- Secure
- Robust
- Portable
- Fast
History of Java
- 1991: Java started as a project called "Oak", initiated by James Gosling and his team at Sun Microsystems. Oak was aimed at programming home appliances.
- 1995: Oak was renamed to Java because "Oak" was already a trademark by another company. The name Java was inspired by coffee (Java coffee).
-
1995: Sun Microsystems officially launched Java with the slogan:
"Write Once, Run Anywhere." - 2009: Oracle Corporation acquired Sun Microsystems and took ownership of Java.
- Today: Java continues to be one of the most popular programming languages in the world.
Key Features of Java
Feature | Description |
---|---|
Simple | Easy to learn, clean syntax similar to C/C++, but without complex features like pointers. |
Object-Oriented | Everything is treated as an object, making programs easier to manage and extend. |
Platform-Independent | Java programs are compiled into bytecode, which can run on any system with a Java Virtual Machine (JVM). |
Secure | Provides a secure environment by avoiding explicit pointer use and running programs inside the JVM sandbox. |
Robust | Strong memory management, automatic garbage collection, and exception handling. |
Multithreaded | Supports multithreading, meaning multiple tasks can run at the same time. |
Portable | Java code can be easily moved from one platform to another without changes. |
High Performance | Though slower than C/C++, Java offers high performance using techniques like Just-In-Time (JIT) compilation. |
Distributed | Java supports networking and distributed computing easily with built-in APIs like RMI and EJB. |
Dynamic | Java programs carry a lot of runtime information that can be used to verify and resolve accesses to objects during runtime. |
How Java Works
When you write a Java program, it goes through a few important steps before running:
- Write Code → You create a .java file (your source code).
- Compile Code → The Java Compiler (javac) compiles the .java file into a .class file (bytecode).
- Run Code → The Java Virtual Machine (JVM) reads the .class file and executes it.
This whole process makes Java platform-independent — you can run the same .class file on Windows, Mac, Linux, etc., as long as there is a JVM installed.
Main Components in Java
Component | Full Form | Purpose |
---|---|---|
JVM | Java Virtual Machine | Executes Java bytecode (.class files). It makes Java platform-independent. |
JRE | Java Runtime Environment | Provides everything needed to run Java programs (JVM + libraries + other files). |
JDK | Java Development Kit | Provides everything to develop and run Java programs (JRE + compiler + tools). |
Simple Explanation of Each
-
JVM (Java Virtual Machine)
- Runs the compiled Java program (bytecode).
- Converts bytecode into machine code (CPU instructions).
- Provides memory management, security, garbage collection, etc.
- Each OS (Windows/Linux/Mac) has its own version of JVM.
-
JRE (Java Runtime Environment)
- Includes the JVM + Java class libraries (pre-built code to make programming easier) + support files.
- Needed only for running Java programs, not for developing them.
-
JDK (Java Development Kit)
- Includes the JRE + development tools like:
- Compiler (javac)
- Debugger
- JavaDoc generator
- Other command-line tools
- Needed to develop, compile, and run Java programs.
- Includes the JRE + development tools like:
Quick Diagram:
JDK = JRE + Development Tools
JRE = JVM + Libraries + Support Files
JVM = Executes Bytecode