A Guide to Writing Your First Java Program: Get Started with Hello World
Meta Description (155 characters):
The first "Hello, World!" in Java Learn how to write, compile (javac) and run (java) your program step by step. Understand the JVM and main structure.
🎯 What Will You Learn in This Guide?
This guide teaches you how to write your first program in Java, a language known for its cross-platform compatibility and high performance.
“Hello, World!” With this example, you will learn Java's class structure, function of the main method and compile-running process.
Purpose: To successfully create your first code running on the Java Virtual Machine (JVM).
⚙️ Preparing the Java Development Environment
Unlike languages like Java, PHP or Python, it is not directly interpreted; compiles first, then runs.
Required tools:
- JDK (Java Development Kit) – Includes the
javaccompiler and JRE. (Must be version 11 or above) - Terminal or Command Line – To run commands.
- Text Editor or IDE – Initially
nanoorVS Codeis sufficient.
💡 Tip: Using an IDE (e.g. Eclipse, IntelliJ) reduces errors, but a simple editor is more practical for the first program.
🚀 Writing and Running the First Program
The most common difficulty for beginners is getting bogged down in theory before understanding the complex structure.
That's why we start directly by writing code.
1️⃣ Create Project Directory
Open terminal and create a new folder:
mkdir ilk-program
cd ilk-program
➡️ Description: Creates a directory named first-program for the project and enters it.
2️⃣ Write Java Source Code
Create a source file (.java):
nano Hello.java
Write the following code in the file:
public class Hello {
public static void main(String[] args) {
System.out.println("Merhaba, Dünya!");
}
}
➡️ Description: This program supports the console Hello, World! writes the message. The file name (Hello.java) must be the same as the class name (Hello) in it.
3️⃣ Compile the Code
After saving, compile your code:
javac Hello.java
➡️ Description: javac analyzes and optimizes the source code, creating the bytecode file named Hello.class.
4️⃣ Execute the Program
You can now run the compiled code:
java Hello
➡️ Description: java runs the compiled Hello.class file on the JVM. Extension (.java, .class) is not added.
Expected Output:
Merhaba, Dünya!
🎉 Congratulations! You have successfully compiled and run your first Java program.
🔬 Understanding Code Fundamentals
A Java program consists of at least two basic components:
Class
main Method
🧱 1. Class Structure (public class Hello)
Java is an object-oriented (OOP) language. All your code should be inside a class.
public class Hello { ... }
public: Accessible from anywhere.
class: Defines a class.
: Determines the scope of the class.
📌 Rule: The file name (Hello.java) must be the same as the class name.
⚙️ 2nd Entry Point (main method)
The starting point of the program is:
public static void main(String[] args)
public: Accessible from anywhere.
static: Can be called without creating an object.
void: Does not return a value.
String[] args: Retrieves parameters from the command line.
🧾 3. Output Command (System.out.println)
It is used to print text on the console.
System.out.println("Merhaba, Dünya!");
System: It is Java's core class.
.out: Represents the console output stream.
.println(): Writes the text in parentheses and moves to the end of the line.
;: Mandatory at the end of every statement.
🔁 Compilation and Execution Mechanism
🧩 Compilation (javac Hello.java)
Syntax check is performed.
The source code is optimized.
Output: Hello.class → Bytecode that the JVM understands.
▶️ Execution (java Hello)
JVM is started.
The hello.class file is loaded.
main() method is called.
The output is printed to the screen.
The program ends successfully.
💡 JVM provides cross-platform portability as it works independently of the operating system.
🙋♂️ Frequently Asked Questions (FAQ)
- Why do we compile Java code?
Java first translates the source code into optimized bytecode. In this way, performance increases and the possibility of errors decreases.
- Why is static needed in the main method?
The main() call must be static because no object has been created yet when the program starts.
- What is the difference between .java and .class?
.java → It is a human-readable source file.
.class → Compiled bytecode; JVM runs this.
- What is the difference between System.out.print and System.out.println?
print() continues on the same line, println() moves to the end of the line.
- Is it mandatory to use IDE?
No. You can also learn Java with simple terminal commands.
🏁 Conclusion
Now you know the basic building blocks of Java:
Class structure
main method
Compilation and execution process
This information creates a solid foundation for future complex projects. The most effective method is to learn by changing the code and getting errors.
💡 You can start developing your own Java projects by doing your experiments on the GenixNode Platform. 🚀

