I am a beginner in JAVA and the difference between these tokens is not clear for me and where should I use them?
Tokens are the various Java program elements which are identified by the compiler.
Following are the tokens support by java:
Identifiers: (The term identifier is usually used for variable names). eg-sum,total
keywords: (A variable is a meaningful name of data storage location in computer memory. When using a variable you refer to memory address of computer). eg-int,for
Constant:(Constants are expressions with a fixed value). eg-height,sum
Strings:(Sequence of character). eg-“hello”, “deepak”
Special symbol: (Symbols other than the Alphabets and Digits and white-spaces). eg- @,$
Operators:(A symbol that represents a specific mathematical or non-mathematical action). eg- ++,*
[] is used to indicate that an array is being declared (or accessed).
example(array declaration): int[] arr = new int [100];
example(accessing elements): int x = arr[5] + arr[10];
{} is used to specify a block of code, example:
for(int i = 0 ; i < 100 ; i++)
{
if(i==10) break;
System.out.println(i);
}
{} can also be used to initialize the elements in an array:
int[] arr = {1,2,3,4,5};
() is used to indicate a method or a function. Within the paranthesis, there can be some (pssibly zero) parameters associated with the method. They are used while calling a method or while declaring one.
Example(calling): int len = str.length();
String s = str.substring(1,4);
Example(declaration):
void printarr(int[] arr)
{
for(int i = 0 ; i < a.length ; i++)
System.out.print(arr[i]+" ");
}