Java Separators

In Java, there are a few characters that are used as separators. The most commonly used separator in Java is the semicolon (;). As you have seen, it is used to terminate the statements.

The separators are listed in the following table :

Symbol Name Description
( ) Parentheses Used to contain the lists of parameters in method definition and invocation. Also used for defining the precedence in expressions, containing expressions in control statements, and surrounding cast types.
{ } Braces Used to contains the values of automatically initialized arrays. Also used to define a block of code, for classes, methods, and local scopes.
[ ] Brackets Used to declare array types. Also used when dereferencing array values.
; Semicolon Terminates the statements
, Comma Separates consecutive identifiers in a variable declarations. Also used to chain statements together inside a for statement
. Period Used to separate packages names from subpackages and classes. Also used to separate a variable or method from a reference variable.
:: Colons Used to create a method or constructor reference (Added by JDK 8)

Separators Example

Following Java program contains some separators :

/* Java Program Example - Java Separators
 * This program contains some Separators
 */

class JavaProgram
{
    public static void main(String args[])
    {
        
        int i, j=10, k=11;    // uses comma or , separator
        
        for(i=0; i<j; i++)   // uses parentheses or () separator
        {                     // uses braces or {} separator
            System.out.println("I am " + i);
        }
        System.out.println(k + " is biggest here.");
        
    }
}

The sample run of the above Java program is shown here :

java separators

Java Online Test


« Previous Tutorial Next Tutorial »