Introduction to Java
# CHAPTER 1
Introduction to Java
"Write once, run anywhere" was Sun Microsystems' promise for Java in 1995, and it is worth unpacking, because the mechanism behind that slogan explains most of the language's design.
A C program compiles to machine code for one specific processor and operating system; move it elsewhere and it must be recompiled. Java compiles instead to *bytecode*, an intermediate instruction set that no physical processor executes. A Java Virtual Machine on the target machine reads that bytecode and translates it to whatever the local hardware understands. Write the program once, and any machine with a JVM can run the identical compiled artefact.
That indirection cost Java some raw speed, bought back over the years by just-in-time compilation. What it purchased was portability, and portability is why Java became the default in places where software outlives hardware: banking systems, insurance platforms, telecoms, and the whole Android ecosystem. A large share of the enterprise systems quietly running the world are Java, and they are not being rewritten.
The language is also deliberately verbose. Java asks you to declare types, handle exceptions explicitly, and state your intentions in full. That is tedious on a small script and genuinely valuable on a two-million-line codebase maintained by two hundred people over fifteen years — which is the situation Java was designed for.
This chapter gets the JDK installed and the toolchain understood before any syntax, since "it compiles here but not there" is the single most common beginner obstacle.
1. What is Java?
Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible. It follows the famous principle:> "Write Once, Run Anywhere" (WORA)
This means Java code, once compiled, can run on any device that has a Java Virtual Machine (JVM) — whether it's Windows, macOS, Linux, or Android.
Real-World Analogy: Think of Java like a universal power adapter. You write your code once (the adapter), and it works in every country (every operating system) without modification.
2. History of Java
Java was created by James Gosling and his team at Sun Microsystems in 1995. It was originally called "Oak" (named after an oak tree outside Gosling's office) and later renamed to Java — inspired by Java coffee from Indonesia.| Year | Milestone |
|---|---|
| 1991 | Project "Green" started at Sun Microsystems |
| 1995 | Java 1.0 officially released |
| 2006 | Java becomes open-source |
| 2010 | Oracle acquires Sun Microsystems |
| 2014 | Java 8 released (Lambdas, Streams) |
| 2017 | Java 9 (Modules) — 6-month release cycle begins |
| 2021 | Java 17 LTS released |
| 2023 | Java 21 LTS released |
3. Key Features of Java
Java's popularity stems from its powerful set of features:- 1. Platform Independent: Java code compiles to bytecode, which runs on any JVM.
- 2. Object-Oriented: Everything in Java revolves around objects and classes.
- 3. Simple: Java removed complex features like pointers and multiple inheritance of classes (from C++).
- 4. Secure: Java has no explicit pointers, runs inside a virtual machine sandbox, and includes a built-in security manager.
- 5. Robust: Strong memory management, automatic garbage collection, and exception handling.
- 6. Multithreaded: Java natively supports concurrent execution of two or more threads.
- 7. High Performance: Just-In-Time (JIT) compilation makes Java fast despite being interpreted.
- 8. Distributed: Java was designed for the distributed environment of the internet with built-in networking support.
4. Understanding JVM, JRE, and JDK
This is the #1 interview question for Java beginners:
- JVM (Java Virtual Machine): The engine that actually runs your Java bytecode. It's what makes Java platform-independent.
- JRE (Java Runtime Environment): JVM + the core libraries needed to run Java programs. If you only want to *run* Java apps, you need the JRE.
-
JDK (Java Development Kit): JRE + development tools like the compiler (
javac). If you want to *write* Java code, you need the JDK.
5. Why is Java So Popular?
- Enterprise Dominance: The majority of Fortune 500 companies use Java for backend systems.
- Android Development: Android's native development used Java for over a decade.
- Job Market: Java consistently ranks in the top 3 most in-demand programming languages globally.
- Massive Ecosystem: Frameworks like Spring Boot, Hibernate, and Apache Kafka power modern microservices.
- Community: Millions of developers, thousands of libraries, and decades of documentation.
6. Real-World Applications of Java
| Application | Description |
|---|---|
| Android Apps | WhatsApp, Spotify, and Twitter were built with Java |
| Banking Systems | Most ATM software runs on Java |
| E-commerce | Amazon's backend uses Java extensively |
| Big Data | Apache Hadoop, Spark, and Kafka are written in Java |
| Scientific Computing | NASA uses Java for mission-critical applications |
| Enterprise Software | SAP, Oracle ERP systems |
7. Mini Project: Welcome Message Application
Let's write our very first Java program conceptually (we'll set up the environment in Chapter 2):Expected Output:
8. Common Mistakes
- Confusing Java with JavaScript: Despite the similar names, Java and JavaScript are completely different languages. Java is a compiled, statically-typed language for backend/Android. JavaScript is an interpreted, dynamically-typed language for web browsers.
- Thinking Java is outdated: Java evolves every 6 months with modern features like records, sealed classes, and pattern matching.
9. Best Practices
- Start with the JDK, not just the JRE: As a developer, always install the full JDK.
- Use the latest LTS version: Java 17 or Java 21 LTS are recommended for production.
10. Exercises
- 1. List five real-world applications that use Java.
- 2. Explain the difference between JVM, JRE, and JDK in your own words.
- 3. Why is Java called "platform-independent"?
- 4. Who created Java, and what was it originally named?
11. MCQ Quiz with Answers
Who created the Java programming language?
What does JVM stand for?
What is the "Write Once, Run Anywhere" principle?
Which of the following is NOT a feature of Java?
What was Java originally called?
What do you need to install to DEVELOP Java applications?
Java is primarily what type of programming language?
Which company currently owns and maintains Java?
Java bytecode is executed by which component?
Which of these is a real-world Java application?
12. Interview Questions
- Q: What is the difference between JDK, JRE, and JVM?
- Q: Why is Java considered platform-independent?
- Q: Is Java a compiled or interpreted language? (Trick question — it's both!)
- Q: Name three features that make Java secure.
- Q: Why do enterprises prefer Java over other languages?
13. FAQs
Q: Is Java still worth learning in 2025? A: Absolutely. Java remains one of the top 3 most demanded languages in the job market, especially for backend, enterprise, Android, and Big Data roles.Q: Is Java hard to learn? A: Java has a moderate learning curve. Its strict syntax enforces good habits, making it an excellent first language for computer science students.