Java Tokens

Java Tokens

A token is the smallest element of a program that is meaningful to the compiler. Tokens can be classified as follows:

  1. Identifiers
  2. Keywords
  3. Literals/Constants
  4. Data Types
  5. Operators

 

 1.Identifiers:-

Identifier is a word and it is used to identify variable, method,class, interface, package, .. etc.,

It can be a variable name, method name, class name, interface name, package name, .. etc.,

Rules to declare an identifier:

1) It can be formed by using alphabets(A to Z & a to z), digits (0 to 9), underscore symbol(_) and dollar symbol($).
2) It must begins with alphabet, underscore & dollar symbol.
3) The length of the identifier is not limited.
4) It should not contain special symbols other than underscore symbol or dollar symbol.
5) It should not contain whitespace characters(Space bar, tab & enter keys). 
2.Keywords:-

A set of words reserved by language itself and those words are called keywords.There are 50 keywords at present in Java language including strictfp, assert & enum.All keywords must be written in lowercase letters only. 

Note 1: const & goto keywords presently not in use.

Note 2: Keyword cannot be used as an identifier.

 Some Keywords:-

abstract , assert, boolean, break , byte ,case ,catch,char, class ,      const ,continue , default  , do  , double  , else  ,enum  ,exports , extends,final ,finally ,float  ,for , goto , if ,implements, import  ,instanceof ,  int ,interface,  long  ,module, native, new,  open,  opens , package,        private,  protected,   provides,    public,   requires ,   return ,  short ,       static, strictfp,   super,  switch , synchronized ,this,   throw,   throws   ,to  transient ,    transitive ,    try ,   uses ,   void    ,volatile  ,   while ,   with

3. Literals/Constants:-

A literal is a source code representation of a fixed value.

In Java, literals are divided into 6 categories:

1) Integer Literals:

5, 92, 4342, 0, -3, -45, -343, .. etc.,

2) Floating Point Literals:

5.2, 432.09, 0.093, -2.334, .. etc.,

3) Character Literals:

'a', 'b', 'z', 'X', .. etc.,

4) String Literals:

"Hi", "hello", "Welcome", .. etc.,

5) Boolean Literals:      true, false

6) Object Literals:  null

Note1: true, false & null are not keywords.

Note2: true,false & null are also cannot be used as an identifier.

4 .Data Types:-

A date type that determines what value variable can hold and what are the operations can be performed on variables.

In Java, data types are divided into 2 categories:

1) Primitive Data Types:

2) Reference Data Types:

Primitive Data Types:

All primitive data types are predefined data types. There are 8 primitive data types and these are named by keywords.

1) byte 2) short 3) int 4) long 5) float 6) double 7) char 8) boolean

Reference Data Types:

Arrays, Strings, Classes, Interfaces, .. etc

 5.Operators :-

Java provides many types of operators which can be used according to the need. They are classified based on the functionality they provide. Some of the types are-

  1. Arithmetic Operators
  2. Unary Operators
  3. Assignment Operator
  4. Relational Operators
  5. Logical Operators
  6. Ternary Operator
  7. Bitwise Operators
  8. Shift Operators
  9. instance of operator
  10. Precedence and Associativity.  

 



 

 


 

 

 

 

 
 
 

 


Comments

Popular posts from this blog

Inheritance in Java

Type Conversions

Life cycle of a Thread and creating thread class