Java Hello World
Java Hello World
Home Whiteboard AI Assistant Online Compilers Jobs Tools Articles Corporate Training Teach with us
Chapters Categories
SQL HTML CSS Javascript Python Java C C++ PHP Scala C# Tailwind CSS Node.js MySQL Mongo
Printing "Hello World" on the output screen (console) is the first program in Java and other programming languages. This tutorial will
teach you how you can write your first program (print "Hello World" program) in Java programming.
Open Compiler
Advertisement
-
Open a command prompt window and go to the directory where you saved the class. Assume it's C:\.
Type 'javac MyFirstJavaProgram.java' and press enter to compile your code. If there is no error in your code, the command
prompt will take you to the next line (Assumption The path variable is set. Learn: Java Envionment Setup).
https://www.tutorialspoint.com/java/java_hello_world.htm 1/4
10/04/2025 22:56 Java Hello World
Output
This line is creating a new class MyFirstJavaProgram and being public, this class is to be defined in the same name file as
MyFirstJavaProgram.java. This convention helps Java compiler to identify the name of public class to be created before reading the file
content.
2. Comment Section
These lines being in /* */ block are not considered by Java compiler and are comments. A comment helps to understand program in a
better way and makes code readable and understandable.
This line represents the main method that JVM calls when this program is loaded into memory. This method is used to execute the
program. Once this method is finished, program is finished in single threaded environment.
4. Keywords Used
public − defines the scope of the main method. Being public, this method can be called by external program like JVM.
static − defines the state of the main method. Being static, this method can be called by external program like JVM without
first creating the object of the class.
void − defines the return type of the main method. Being void, this method is not returning any value.
String []args − arguments passed on command line while executing the java command.
5. System.out.println() Method
System.out represents the primary console and its println() method is taking "Hello World" as input and it prints the same to the
console output.
TOP TUTORIALS
Python Tutorial
Java Tutorial
https://www.tutorialspoint.com/java/java_hello_world.htm 2/4
10/04/2025 22:56 Java Hello World
C++ Tutorial
C Programming Tutorial
C# Tutorial
PHP Tutorial
R Tutorial
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
SQL Tutorial
TRENDING TECHNOLOGIES
Git Tutorial
Ethical Hacking Tutorial
Docker Tutorial
Kubernetes Tutorial
DSA Tutorial
Spring Boot Tutorial
SDLC Tutorial
Unix Tutorial
CERTIFICATIONS
Online C Compiler
Online C++ Compiler
Online C# Compiler
ABOUT US | OUR TEAM | CAREERS | JOBS | CONTACT US | TERMS OF USE | PRIVACY POLICY | REFUND POLICY |
https://www.tutorialspoint.com/java/java_hello_world.htm 3/4
10/04/2025 22:56 Java Hello World
Tutorials Point is a leading Ed Tech company striving to provide the best learning material on technical and non-technical subjects.
https://www.tutorialspoint.com/java/java_hello_world.htm 4/4