Wednesday, July 3, 2024
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.neveropen.co.za or mail your article to review-team@neveropen.co.za. 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.

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments