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
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 |
Article Tags :