Java Basic Syntax

For Java programmer, it is very important to keep in mind about the following points.

Java Basic Syntax Example

Following is Java's simplest program, prints Hello World on the screen.

/* Java Program Example - Java Basic Syntax */

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

When the above Java program is compile and executed, it will produce the following output:

java basic syntax

Identifiers in Java

In Java, an identifiers are used to name things, such as classes, variables, and methods.

An identifier may be any sequence of uppercase and lowercase letters, number or the underscore and dollar-sign characters. As you know, Java is case-sensitive, therefore, VALUE is a different identifier than Value.

Following are the rules to declare Identifiers in Java:

Whitespaces in Java

A line containing only whitespace, possibly with comment, is known as blank line, and Java compiler totally ignores it.

Comments in Java

There are the three types of comments defined by Java. You have already seen two: single-line and multiline comments. The third type is a documentation comment. This type of comment is used to produce an HTML file that documents your program. The documentation comment begins with /** and ends with */.

All characters available inside any comment are ignored by Java compiler. Her is an example.

/* Java Program Example - Java Basic Syntax */

public class JavaProgram
{
    
    /* 
   This is a simple Java program.
   It will print 'Hello World' on the output screen
   It is an example of multi-line comments or block comments.
    */
   
    public static void main(String args[])
    {
        
        // It is an example of single line comment
   /* It is also an example of single line comment. */
      
   System.out.println("Hello World"); 
        
    }
}

When the above Java program is compile and run, it will produce the following output:

comments in java

Java Online Test


« Previous Tutorial Next Tutorial »