Sunday, November 17, 2024
Google search engine
HomeLanguagesJavaSeparators in Java

Separators in Java

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 Lazyroar 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 Lazyroar 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.

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments