Professional Documents
Culture Documents
TUTORIALS EXAMPLES
A "Hello, World!" is a simple program that outputs Hello, World! on the screen. Since it's a very simple program, it's
often used to introduce a new programming language to a newbie.
Contents
https://www.programiz.com/java-programming/hello-world 1/7
9/9/2019 Java Hello World - Your First Java Program
If you want to run this program in your computer, make sure that Java is properly installed. Also, you need an IDE (or
a text editor) to write and edit Java code. For that, check How to run Java on your computer?
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
If you have copied the exact code, you need save the le name as HelloWorld.java . It's because the name of the
class and lename should match in Java. Visit this page to learn: Why are lenames in Java the same as the class
name?
Contents
https://www.programiz.com/java-programming/hello-world 2/7
9/9/2019 Java Hello World - Your First Java Program
Hello, World!
In Java, any line starting with // is a comment. Comments are intended for person reading the code to better
understand the intent and functionality of the program. It is completely ignored the Java compiler (application that
translates Java program to Java bytecode that computer can execute). To learn more, visit Java comments.
2. class HelloWorld { ... }
In Java, every application begins with a class de nition. In the program, HelloWorld is the name of the class, and
the class de nition is:
class HelloWorld {
... .. ...
}
For now, just remember that, every Java application has a class de nition, and the name of class should match the
lename in Java.
3. public static void main(String[] args) { ... }
This is the main method. Every application in Java must contain a main method. The Java compiler starts executing
the code from the main method. Contents
https://www.programiz.com/java-programming/hello-world 3/7
9/9/2019 Java Hello World - Your First Java Program
How does it work? Good question. However, we will not discuss it in this article. After all, it's a basic program to
introduce Java programming language to a newbie. We will learn the meaning of public , static , void , and how
methods works? in later chapters.
For now, just remember that main function is the entry point of your Java application, and it's mandatory in a Java
program. The signature of main method in Java is:
4. System.out.println("Hello, World!");
The following code prints the string inside quotation marks Hello, World! to standard output (your screen). Notice,
this statement is inside the main function, which is inside the class de nition.
Every valid Java Application must have a class de nition (that matches the lename).
The main method must be inside the class de nition.
The compiler executes the codes starting from the main function.
https://www.programiz.com/java-programming/hello-world 4/7
9/9/2019 Java Hello World - Your First Java Program
Don't worry if you don't understand the meaning of class , static , methods, and so on for now. We will discuss it in
detail in later chapters.
Java Tutorial
Java Introduction
Java Operators
Contents
Java Input and Output
https://www.programiz.com/java-programming/hello-world 5/7
9/9/2019 Java Hello World - Your First Java Program
Java Comment
Subscribe
TUTORIALS
Python Tutorials
C Tutorials
Java Tutorials
Kotlin Tutorials
C++ Tutorials
Swift Tutorials
R Tutorials
DSA Contents
https://www.programiz.com/java-programming/hello-world 6/7
9/9/2019 Java Hello World - Your First Java Program
EXAMPLES
Python Examples
C Examples
Java Examples
Kotlin Examples
C++ Examples
R Examples
COMPANY
About
Advertising
Contact
LEGAL
Privacy Policy
Contents
https://www.programiz.com/java-programming/hello-world 7/7