Learn Java · 1/15

Introduction to Java and Setup

7 min read

Introduction to Java and Setup ☕

Welcome to the wonderful world of Java! Before we dive into writing code, let's get a handle on what Java is and why it's a fantastic language to learn.

The "Why" Before the "How": Why Java?

Ever wondered why Java has remained so popular for decades? It's not just by chance. Java was designed with a philosophy of "Write Once, Run Anywhere" (WORA), which means a Java program can run on any device that has a Java Virtual Machine.

Key Advantages of Java:

  • Object-Oriented: Java is built around the concept of objects, which allows for modular programs and reusable code. This makes it easier to manage and scale large applications.
  • Platform Independent: This is the crown jewel of Java. You can write your code on a Windows machine, and it will run on a Mac, Linux, or any other platform that supports Java. This is made possible by the Java Virtual Machine (JVM).
  • Robust and Secure: Java has strong memory management, handles exceptions effectively, and has built-in security features that protect against malicious code. This makes it a reliable choice for building secure applications.
  • Rich API and Large Ecosystem: Java has a vast collection of pre-written code in its Application Programming Interface (API) and a massive ecosystem of open-source libraries and frameworks. This saves developers a lot of time and effort.
  • High Demand in the Job Market: Java developers are consistently in high demand across various industries like banking, e-commerce, and mobile app development. Learning Java can open up numerous career opportunities.

Interesting Fact: Java was originally named "Oak" after an oak tree that stood outside the office of its creator, James Gosling. It was later renamed to "Java" inspired by the coffee they drank. So, grab a cup of coffee, and let's get started! ☕


Understanding the Ecosystem: JDK, JRE, and JVM

Before you can start coding in Java, it's essential to understand the key components that make it work. Think of it as a three-layered system, each with a specific role.

  • JVM (Java Virtual Machine): This is the core component that executes Java bytecode. It acts as an abstract machine that provides a runtime environment. Each platform (Windows, macOS, Linux) has its own JVM implementation, which is what makes Java platform-independent.

  • JRE (Java Runtime Environment): The JRE includes the JVM, along with the necessary libraries and other files for running Java applications. If you only want to run Java programs, you just need the JRE.

  • JDK (Java Development Kit): The JDK is a full-featured software development kit for Java. It includes the JRE (which includes the JVM) plus development tools like a compiler (javac) and a debugger. As a developer, you'll need the JDK to write and compile your Java code.

In a nutshell:

  • You write code using the JDK.
  • You run code on the JRE.
  • The JVM is the engine that makes it all happen.

Imagine you're building with LEGOs.

  • The JDK is the entire LEGO factory, with all the tools and molds to create any LEGO piece you can imagine.
  • The JRE is a complete LEGO set with all the pieces and instructions you need to build a specific model.
  • The JVM is the set of physical laws that govern how the LEGO pieces connect and stay together.

Setting Up Your Development Environment (IDE selection)

Now for the hands-on part! To start coding in Java, you need to set up your development environment. This involves installing the JDK and choosing an Integrated Development Environment (IDE).

Step 1: Install the Java Development Kit (JDK)

First things first, you need to get the latest JDK. As of early 2026, it's a good practice to use a Long-Term Support (LTS) version for stability.

  1. Download the JDK: Head over to the official Oracle Java Downloads page or an OpenJDK distribution like Eclipse Temurin.
  2. Choose your Operating System: Select the installer that matches your operating system (Windows, macOS, or Linux).
  3. Run the Installer: Double-click the downloaded file and follow the on-screen instructions.
  4. Set Environment Variables: After installation, you need to tell your operating system where to find the JDK. This is a crucial step.
    • Windows: You'll need to set the JAVA_HOME environment variable to the JDK installation directory and add the bin folder to your Path variable.
    • macOS and Linux: This is often handled automatically, but you can configure it in your shell's startup file (e.g., .bash_profile, .zshrc).

To verify your installation, open a new terminal or command prompt and type:

bash
java -version

You should see the version of the JDK you just installed.

Step 2: Choose an Integrated Development Environment (IDE)

An IDE is a software application that provides comprehensive facilities to programmers for software development. Think of it as your coding command center. Here are some of the most popular Java IDEs in 2026:

  • IntelliJ IDEA: A powerful and popular IDE known for its intelligent code completion and developer-friendly features. It has a free Community edition which is great for beginners.
  • Eclipse: A long-standing, open-source IDE with a vast plugin ecosystem. It's highly customizable and widely used in the industry.
  • Visual Studio Code (VS Code): A lightweight and versatile code editor that can be turned into a powerful Java IDE with extensions. It's a great choice if you work with multiple programming languages.

For this guide, we'll use examples that are compatible with any of these IDEs. Pick the one that feels most comfortable for you!


Your First Java Program: "Hello World" and the main method

It's a tradition in programming to start with a "Hello, World!" program. This simple program will help you understand the basic structure of a Java application.

Let's break it down:

java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Creating and Running the Program:

  1. Open your chosen IDE and create a new Java project.
  2. Create a new Java class and name it HelloWorld.
  3. Copy and paste the code above into the HelloWorld.java file.
  4. Run the program. You should see "Hello, World!" printed to the console.

Understanding the Code:

  • public class HelloWorld: This line declares a class named HelloWorld. In Java, all code must reside inside a class. The file name must match the public class name.
  • public static void main(String[] args): This is the main method. It's the entry point for any standalone Java application. When you run your program, the JVM looks for this specific method to start execution.
    • public: This is an access modifier that means the method is accessible from anywhere.
    • static: This keyword allows the main method to be called without creating an instance of the class.
    • void: This indicates that the main method does not return any value.
    • String[] args: This is a parameter that accepts an array of strings, which are command-line arguments.
  • System.out.println("Hello, World!");: This line prints the text "Hello, World!" to the console.

Under the Hood: Source Code to Bytecode Compilation

Have you ever wondered what happens when you click that "run" button in your IDE? It's not magic, but a well-defined process.

  1. Writing Source Code: You write your Java code in .java files. This is the human-readable code you see in your editor.

  2. Compilation to Bytecode: The Java compiler, javac, takes your .java source file and compiles it into a .class file. This .class file contains Java bytecode, which is a platform-independent intermediate language. This bytecode is what makes the "Write Once, Run Anywhere" philosophy possible.

  3. Execution by the JVM: When you run your program, the Java Virtual Machine (JVM) loads the .class file. The JVM then interprets this bytecode and translates it into native machine code that your computer's processor can execute. Modern JVMs use a technique called Just-In-Time (JIT) compilation to improve performance by compiling frequently used bytecode into native machine code at runtime.

Real-world Analogy: Imagine you've written a recipe (your .java source code).

  • The javac compiler is like a translator who converts your recipe into a universally understood set of cooking symbols (the .class bytecode).
  • The JVM is like a chef in any kitchen around the world who can read these symbols and prepare the dish (execute the program) on their specific stove (the operating system).

And that's it for your introduction to the world of Java! You've learned why Java is a powerful language, understood its core components, set up your development environment, written your first program, and even peeked under the hood to see how it all works. You're now ready to embark on your Java programming journey! 🚀


📚 Additional Resources

Challenge

Write a complete Java program that introduces a user.

  1. Define a public class named UserProfile.
  2. Inside this class, create the main entry point method for a Java application. This method must be public, static, does not return any value, and accepts an array of strings as its only parameter.
  3. Within the main method, print the following three lines to the console, each on a new line:
    • Name: [Your Name] (Replace [Your Name] with a name of your choice).
    • Learning: Core Java Concepts
    • Status: Active

Expected result

Your code should be a complete, compilable Java class. The main method must have the correct signature (public static void main(String[] args)), and it must contain three System.out.println() statements to produce the required output.

java
public class UserProfile {
    public static void main(String[] args) {
        System.out.println("Name: Jane Doe");
        System.out.println("Learning: Core Java Concepts");
        System.out.println("Status: Active");
    }
}
java

Solve the challenge, then check it.

Ctrl+Enter

Course complete!

You've passed every challenge in this course.