Javatpoint Logo
Javatpoint Logo

Separators In Java

In Java, separators are characters that separate different parts of a code statement or expression. They play an important role in defining the language's syntax and help to organize and structure code in a readable and understandable way.

Java has several types of separators, each with a specific use. The most commonly used separators include the semicolon (;), comma (,), dot (.), and colon (:).

Understanding and properly using separators is important in writing clear and efficient Java code. It allows for a consistent and organized structure, making it easier for other developers to understand and work with the code.




a is greater than b
I like apple
I like banana
I like orange
1 2 
3 4

Table to show different types of separators

Symbol Name Description Example
( ) Parentheses Parentheses are an important part of Java programming, used for grouping expressions and controlling the order of operations. They can also be used to specify method parameters and enclose conditional expressions. Proper use of parentheses can ensure the correct code behaviour and improve its readability. System.out.println("Hello, world!");
{ } Braces In Java programming, braces define code blocks, such as loops, conditional statements, and methods. They help group related code statements and ensure they are executed as a single unit. Proper use of braces is essential for writing clear and maintainable code. public void myMethod() { int x = 5; }
[ ] Brackets In Java programming, brackets are used to access elements of arrays or collections. They are placed after the name of the array or collection and contain an index or key value that specifies which element to access. Allowing you to retrieve and modify specific values within these data structures. int[] myArray = {1, 2, 3, 4, 5};
; Semicolon In Java programming, the semicolon is used to terminate statements. It tells the compiler that a statement has ended and that it should move on to the next one. int x = 5; System.out.println("Hello, world!");
, Comma In Java programming, the comma is used to separate values or expressions. It is commonly used to list parameters in method calls and to initialize arrays. Commas are also used for loops to separate the initialization, condition, and increment statements. doSomething(x, y, z);
. Period In Java programming, the period is used to access member variables and methods of objects. It is placed after the object name and followed by the name of the member variable or method. The period is essential for working with objects in Java, allowing you to access and modify their properties and behaviour. String myString = "Hello, world!"; int length = myString.length();
: Colon Method references are made using colons. It is also used to reference the constructor. After labels, colons are frequently used. for (String str : myList) { doSomething(str); }

Example Including all Separators in Java

The below example includes all the separators like parathesis, braces, brackets, semicolons, commas, periods, and colons.



Sum: 20Sum is greater than 10
Second number: 2
Z: 3
Name: John, Age: 30, City: New York
Pi: 3.14
Message: Hello, world!

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA