Separators in Java - Explained

 Separators in Java - Explained

By Naomi A.

Hello reader - Here, I am sharing the characters that are used as separators in Java, and explaining them for better understanding.

 __________________________________________________________________________________

What is a separator?

- A separator is a character or a sequence of characters that separates tokens in a program.

What is a token? 

- A token is a sequence of characters that are used to represent various elements of the code in a Java program - keywords, identifiers, literals, and punctuation.

Whitespace Is not considered a separator:

- Because Java is a free-form language, you don't need to abide by any indentation or spacing rules. Whitespace includes; spaces, tabs, and newline characters. 

- This improves readability for the developer but is ignored by the compiler.

 __________________________________________________________________________________

Separators in Java:

Comma: 
The comma (,) is used to separate items in a list. For example: elements of an array or the arguments of a method.   
 
Semicolon: 
The semicolon (;) marks the end of a statement. 
 
Colon: 
The colon separator is used to create a constructor reference or method. 
 
Period:
The period (.) is used to access members of an object or class, such as fields and methods. 
Example: System.out.println("Hello World!")  
 
Forward Slash:
The forward slash (/) is used as the division operator and to create comments in Java code.
  
Curly Braces: 
Braces ({ and }) are used to enclose blocks of code, such as the body of a method or a loop.   
 
Square Brackets: 
Brackets ([ and ]) are used to access array elements and to specify the bounds of an array when declaring it.   It's important to use these separators correctly in your Java code, as they play a vital role in the structure and syntax of the language. 
 
Parentheses: 
Parentheses (() and ) are used to enclose the arguments of a method or the conditions of a loop or decision statement. They are also used to enclose expressions in certain contexts, such as when using the ternary operator or when casting a value.   
 

  __________________________________________________________________________________

Thanks for reading!

Separators play a vital role in the structure and syntax of the language. Stay tuned techies; for more posts on Java.

Comments

Popular posts from this blog

Creating a Webpage - A Beginner's Guide (HTML, CSS, JavaScript)

Teaching Computers to Play Tic Tac Toe: A Reinforcement Learning Approach

Run Queries in SQL Server Using Python!