Java Syntax and Program

In the article we learned about the java syntax using the Main.java file, the below code to print “Hello world” to the screen.

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}

OUTPUT

Hello World

Let’s understand the above code.

class keyword is used to declare a class in Java

public keyword is and access modifier 

static keyword used to declare any method as static. It’s also known as a static method. We discussed the static keyword further.

void is a return type of method which indicates that it doesn’t return any value.

main keyword the starting point of the program which is automatically called by JVM.

String[] args or String args[] is used for command line arguments. We learned it further.

System.out.println() is used to print statements.

  • System is a class.
  • out is an object of the PrintStream class.
  • println() is a method of the PrintStream class.

We will discuss the internal working of System.out.println() statement in further articles.