java hello world how to

By tradition, when learning a new programming language you start with a “Hello World!” program. Here’s how to do it in Java!

The code:

public class Main {

public static void main(String[] args) {
System.out.println(“Hello World!”);


The breakdown of the code:

Line 1: public class Main {

Defines a public class called Main, meaning that all other classes may access this main class. Remember, in Java every executable code must be inside of a class.

Line 2: public static void main(String[] args) {

This is the line that enters the executable part of our code. Public again allows anything to access it, static means that this method can be used without creating an instance of Main, the void means that this method returns nothing, and within the parenthesis are arguments for the method.

Line 3: System.out.println(“Hello World!”);

This line prints the string “Hello World!”. Out simply means that you are outputting and println simply prints onto the line.

Publisher: adam

Share this post