JAVA TUTORIAL

Java Intro Java Features Java vs C++ Java Simple Program Java Applet vs Application JVM,JDK or JRE Java Keywords Java Variables Java Literals Java Separators Java Datatypes Java Operators Java Statements Java Array Java String

CONTROL STATEMENTS

Java If-else Java While Loop Java Do-While Loop Java For Loop Java For-each Loop Java Switch Java Break/Continue

JAVA METHODS

Java Method Java Overloading Java Overriding

JAVA CLASSES

Java OOPs Java Classes/Objects Java Inheritance Java Polymorphism Java Encapsulation Java Abstraction Java Modifiers Java Constructors Java Interface Java static keyword Java this keyword

Java Separators

In this page let's discuss what is a separator in java and how many types of separators available in java. So let's get started.

A separator is a symbol that is used to separate a group of code from one another is called as separators in java.

In java, there are few characters that are used as a separator. The most commonly used separator is a semicolon. As we have seen it is used to terminate the statement.

Separators help define the structure of a program. The separators used in HelloWorld are parentheses, ( ), braces, { }, the period, ., and the semicolon, ;.

In simple word separators are symbol used to indicate where a group of code are divided and arranged.

Types of Separators

There are six types of separators used in java. They are:

1. Parentheses ()

2. Braces {}

3. Brackets []

4. Semicolon ;

5. Comma ,

6. Period .

What it is use for:

1) Parentheses ()

Used to enclose parameters in the method definition and invocation. Also used for defining the expression in control statements.

2) Braces {}

Used to define a block of code for classes and methods. Also used to contain the values of arrays.

3) Brackets []

Used to declare an array type and also used for dereferencing array values.

4) Semicolon ;

It is used to separate or terminate the statement.

5) Comma ,

Used to separate consecutive identifiers (or) Variable declarations. Also used to chain statements together inside a for a statement.

6) Period .

Used to separate package names from sub-packages and classes. Also used to separate a variable or method from a reference variable.

Sample java program for separator:

Java Example

class Separator
{ //uses braces {} separator
    public static void main(String args[]) //uses bracket [] separator
{
int x = 2, y = 5; // uses comma , separator
int z = x*y; //uses semicolon ; separaotor
System.out.println(z); // uses paranthesis () separator
}
}

Output:

10