Java Syntax

Java Syntax

We will understand syntax of Java with the help of an example.

#Java sample program-

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

Explanation of above example-

Every line of code that runs in Java must be inside a class. In our example, we named the class T it is user defined . A class should always start with an uppercase first letter.

Java is Case sensitive hence class name T & t has a different meaning.

Any code inside the main() method will be executed, we will discuss the keywords before and after as follows-

If the class is created with the public access level then it is mandatory to save the program with class name. Java otherwise your program will not compile.

If the main() method in a program is not Static then the program will compile, but can not execute. We nee static main method so that JVM can access main() method without creating object.

In java main() method must have return type “Void” otherwise program will compile but no execution.

main() method must be in small case otherwise program will compile but no execution.

  • Now we are done with the prefix now we will discuss the suffix part of main method

Command line arguments-

Java is a command line argument language we can pass one, or more string values to the JAVA program at the time of program execution that is why main() method of java have a string array as a parameter.

# Java System.out.println() is used to print an argument that is passed to it. The statement can be broken into 3 parts which can be understood separately as:

  • Where system is a abstract class and  it is declared as final found in
  • out - out is a Object of printstreem class and static member of system class.
  • println() - Method of print stream class.