Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Separators in Java

  • Difficulty Level : Basic
  • Last Updated : 25 Sep, 2021

Be it a programmer who is unaware of this concept but is indulging in every program. Separators help us defining the structure of a program. In Java, There are few characters used as separators. The most commonly used separator in java is a semicolon(;). Let us explore more with the help of an illustration with the “Hello World” program to put more emphasis on separators.

Illustration: Hello World

Java




// Java Program to Illustrate Separators in Java
 
// Main class
class GFG {
 
    // Main driver method
    public static void main(String[] args)
    {
 
        // Print statement
        System.out.println("Hello World");
    }
}


Observations drawn are as follows:

  • In line 3, ‘{‘ is used to define starting of block class GFG
  • In line 6, ‘{‘ is used to define starting of block main method
  • In line 10, ‘;’ is used to terminate the sentence
  • In line 11, ‘}’ is used to define the ending of the block main method
  • In line 12, ‘}’ is used to define the ending of block class GFG

These separators are pictorially depicted below as follows: 

Symbol Name  Purpose 
( ) Parentheses used to contain a list of parameters in method definition and invocation. also used for defining precedence in expressions in control statements and surrounding cast types  
{ } Braces Used to define a block of code, for classes, methods and local scopes Used to contain the value of automatically initialised array 
[ ] Brackets declares array types and also used when dereferencing array values 
; Semicolon Terminates statements
, Comma Used to separates package names from sub-package and class names and also selects a field or method from an object
. Period separates consecutive identifiers in variable declarations also used to chains statements in the test, expression of a for loop
: Colon Used after labels

This article is contributed by Swati Jha. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!