Last Updated : 06 Aug, 2025
Java is one of the most popular and widely used programming languages and platforms. In this article, we will learn how to write a simple Java Program. This article will guide you on how to write, compile, and run your first Java program. With the help of Java, we can develop web and mobile applications.
In this article, we will learn:
Implementation of Java Hello World
The below-given program is the most simple program of Java printing "Hello World" to the screen. Let us try to understand every bit of code step by step.
Java
// Simple Java program
// FileName: "HelloWorld.java"
public class HelloWorld {
// Your program begins with a call to main().
// Prints "Hello, World" to the terminal window.
public static void main(String[] args)
{
System.out.println("Hello, World");
}
}
Understanding the Java Hello World Program
1. Class Definition
Every Java program must have at least one class. Here, the class is defined using the class keyword:
public class HelloWorld {
// Statements go here
}
Note: If the class is public, the filename must match the class name HelloWorld.java
2. main Method
In the Java programming language, every application must contain a main method as it is the entry point of the application:
public static void main(String[] args)
3. System.out.println()
This prints output to the console.
System.out.println("Hello, World");
Java is a platform-independent language that follows a two-step execution process:
Java source code (.java files) is compiled by the Java Compiler (javac) into Bytecode, stored in .class files. This bytecode is platform-independent and ready to run on any system with a JVM.
The .class files are executed by the Java Virtual Machine (JVM), which includes the following stages:
a. Class Loader
Loads the main class and other dependencies into memory.
Class r = loadClass(String className, boolean resolveIt);
b. Bytecode Verifier
Checks that the loaded bytecode is safe to execute. It ensures:
c. Just-In-Time (JIT) Compiler
Converts bytecode into native machine code at runtime for faster execution.
Just In Time (JIT) Java Compilation & Execution Example Java
// Java Program to Illustrate Compilation and Execution
class GFG {
public static void main(String[] args) {
System.out.print("Hello, World");
}
}
Steps:
1. Create file: Save above code as GFG.java
2. Open terminal and navigate to file location
3. Compile the program:
javac HelloWorld.java
4. Run the compiled file:
java HelloWorld
Output
Welcome to Geeks
1. In Windows
Shell2. In Linux
ShellNote: If you get ClassNotFoundException, ensure the .class file is in the correct directory or check your CLASSPATH.
They can either be multiline or single-line comments.
// Simple Java program
// FileName: "HelloWorld.java"
This is a single-line comment. This type of comment must begin with // as in C/C++. For multiline comments, they must begin from /* and end with */.
/*
This is a
multi-line comment
*/
Beginning Java programming with Hello World Example
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4