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:
- Identifiers
- Keywords
- Literals/Constants
- Data Types
- 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:
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-
- Arithmetic Operators
- Unary Operators
- Assignment Operator
- Relational Operators
- Logical Operators
- Ternary Operator
- Bitwise Operators
- Shift Operators
- instance of operator
- Precedence and Associativity.
Comments
Post a Comment