Your First Java Program
Here, you will learn how to write simple programs in Java.
To execute any Java program, you need Java SDK installed to compile and run Java programs.
Hello world program
Let us create the first Java program that prints Hello, world!
on the console output.
class YourFirstHelloWorldProgram {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Save the above code as YourFirstHelloWorldProgram.java
.
Run the program
To compile, run javac YourFirstHelloWorldProgram.java
, on the terminal, which compiles the above code to check for errors.
To run or print the output, you need to run java YourFirstHelloWorldProgram
on the terminal.
The output is displayed as Hello, world!
.