Welcome to the next step in your Java journey! In our previous lesson, we took a detailed look at the fundamental blueprint of a Java program, dissecting the roles of the class and the main method. You learned the "grammar" of a basic Java application. Today, we're moving from theory to practice.
This lesson is all about bringing that blueprint to life. You will write your very first line of executable code and run your first program, the classic "Hello, World!". This is a milestone for every programmer, where you make the computer display a message you've instructed it to. By the end of this session, you'll have used your IntelliJ IDEA environment to create, compile, and run a simple program that prints output to the console.
The "Hello, World!" Program
In programming tradition, the first program you write in a new language is one that simply displays the text "Hello, World!" on the screen. It's a simple task, but it proves that your entire development environment is set up correctly and that you understand the basic workflow.
Let's look at the complete code for this program. You'll recognize the class and main method structure from our last lesson. The new piece is the single instruction inside the main method.
public class HelloWorld {
public static void main(String[] args) {
// This line prints the text to the console
System.out.println("Hello, World!");
}
}
The key line here is System.out.println("Hello, World!");. This command instructs the system to print a line of text to the standard output, which is the console window in your IDE.
To get a formal breakdown of this code, let's consult a clear, concise article from DataCamp.
First Java Program: Hello World - DataCamp
This article provides a simple, direct explanation of the "Hello, World!" program.
Please read the sections "Explanation of the Code". Focus on understanding the role of each of the three main lines of code: the class declaration, the main method signature, and the System.out.println statement.
Writing and Running Your First Program in IntelliJ IDEA
Now it's time for the main event: creating and running this program yourself. You have IntelliJ IDEA installed and ready to go. The following video from the creators of IntelliJ IDEA provides a perfect walkthrough of the entire process. We'll go through it step-by-step.
Creating your first Java application with IntelliJ IDEA
This official tutorial demonstrates how to create and run a "Hello, World!" application using IntelliJ IDEA, which is the IDE you have installed.
Please watch the following segments carefully: Project Setup (watch here): Follow along to create a new Java project. You can name it HelloWorld as shown in the video. Creating the Class (watch here): This part shows how to create a new Java class file and use a handy shortcut (main + Enter) to generate the main method. Name your class HelloWorld. Writing the Code (watch here): Type the System.out.println("Hello, World!"); line inside the main method's curly braces {}. Notice how the IDE helps you with autocompletion. Running the Program (watch here): Click the green "run" arrow next to your main method and observe the output in the console window at the bottom of the screen.
After following these steps, your screen should look something like this, with your code in the editor and the "Hello, World!" message printed in the console pane.

Congratulations! You have successfully written and executed your first Java program.
Under the Hood: Create, Compile, Execute
When you clicked the green "run" button in IntelliJ IDEA, the IDE performed a sequence of three crucial steps for you automatically. While using the IDE is convenient, understanding this underlying process is fundamental to grasping how Java works.
- Create: You wrote the human-readable source code and saved it in a
.javafile (e.g.,HelloWorld.java). - Compile: The IDE invoked the Java compiler (
javac), which translated your source code into an intermediate language called Java bytecode. This bytecode was saved in a new file,HelloWorld.class. This is the language the Java Virtual Machine (JVM) understands. - Execute: The IDE then instructed the JVM to run the program (
java HelloWorld). The JVM loaded your.classfile, found themainmethod, and executed the bytecode instructions within it.
The following resource from Princeton's computer science department provides a great summary of this three-step process.
This article explains the traditional command-line workflow for running a Java program, which helps clarify what your IDE is doing for you.
Focus on the section "Programming in Java" which outlines the three steps. Then, read through the descriptions of creating, compiling, and executing the program. You don't need to perform these steps on the command line, but you should understand the purpose of javac and java.
Practice Time
Now, let's solidify what you've learned. A great way to practice is to modify your existing program to do something slightly different.
Your task: Modify your program to print "Hello, World!" ten times.
Hint: You don't need any new commands. You can simply copy and paste the System.out.println("Hello, World!"); line nine more times within the main method's curly braces. Run the program again to see the result. This exercise reinforces the concept that the computer executes commands sequentially from top to bottom.
Conclusion
In this lesson, you took a significant step from theory to application. You have now experienced the complete workflow of a Java programmer: writing code, compiling it, and running it to see a result. This cycle is the foundation of all software development.
Here are the key takeaways from today's session:
- The traditional "Hello, World!" program is the first step in learning a new programming language.
- The
System.out.println()command is used to print a line of text to the console. - An IDE like IntelliJ IDEA automates the create, compile, and run cycle with a single click.
- Under the hood, the
javaccompiler creates a.classfile (bytecode) from your.javafile, and thejavacommand tells the JVM to execute that bytecode.
You've successfully created a working program and instructed the computer to follow your commands. In our next lesson, we will learn how to add comments to our code. Comments are notes for human readers that the compiler ignores, and they are essential for writing code that is easy to understand and maintain.