Java Tokens
What is Java Token-?
Java Token is the smallest element of a program that is identified by a compiler. Every java statement and expression are created using Tokens.
Tokens in Java:-
1. Keyword
2. Identifier
3. Operator
4. Separator
5. Literal
Example:-
Class A //class is keyword and (A is Identifier)
{
public static void main (string [ ]) //here public, static and void is keywords and (Main is identifier which is method name)
{
int a=10, b=20; //int is keyword and (a&b is identifier), here = is operator
int c=a+b; //int is keyword and (a&b is identifier) and + is operator
system.out.print (c);
}
}
//curly brackets in this program are separators, and values of identifier is literal.
Keywords:- int, static, void
Identifier:- variable, method, class-name
Operator:- +, -, *, /, %, etc...,
Separators:- Separate the statement by using (;, ., :, {})
Comment:- (//) the double slash in the bracket we use to write about the program to understand that what is the program about, so the reader can understand easily. Compiler will ignore this comment, but if we are not using (//) then compiler will will push a message of error.
What is keywords-?
Keywords are the reserved words whose meaning is already defined in the compiler called keyword.
The total number of keywords in java are 50 in that two keywords are unused they are (const and goto), it remain as future use.
Keywords are:-
1. abstract
2. assert
3. boolean
4. break
5. byte
6. case
7. catch
8. char
9. class
10. const
11. continue
12. default
13. do
14. double
15. else
16. enum
17. extends
18. final
19. finally
20. float
21. for
22. goto
23. if
24. implements
25. import
26. instanceof
27. int
28. interface
29. long
30. native
31. new
32. package
33. private
34. protected
35. public
36. return
37. short
38. static
39. strictfp
40. super
41. switch
42. synchronized
43. this
44. throw
45. throws
46. transient
47. try
48. void
49. volatile
50. while
In the above 50 keywords
✱ strictfp is the keyword which is added in version 1.2
✱ assert is the keyword which is added in the version 1.4
✱ enum is the keyword which is added in the version 5.0
true, false and null is also like keyword. but they are actually literals.
You can't use any of the keyword as identifier in your program, because already compiler has the meaning of the every keywords.
What is Identifier-?
In Java, an identifier is the name of a variable, method, class, packages, or interface, that is used for the purpose of identification, without identifier you cannot do any programming. you can create your own identifier.
Rule's for creating Identifier.
✱ Keyword can't be used as a identifier
✱ Identifier's are case-sensitive
✱ We can't use white space in between identifier. we can use ($ or underscore symbol _ )
✱ Identifier always starts with letters ($ or underscore symbol _ )
✱ All the variables, methods, class-names, packages names are identifier
What is Java Operators-?
Operator is a symbol that is used to perform operations according to users requirement. Variables and values can perform in operators.
Types of Operators:-
1. Arithmetic Operator:- This operators works for calculation process like add (+), Subtract (-), Multiply (*), divide, Percentage (%)
2. Relational Operators:- This operator is used to less then (<), greater then (>), less then equal to (<=), greater then equal to (>=), |=, = etc...,
3. Logical Operators:- &&, ::, !
4. Increment Decrement Operators:- These operator are of two types
Pre-Increment Operator:- ++esp
Post-Increment Operator:- esp++
Pre-Decrement Operator:- --esp
Post-Decrement Operator:- esp--
5. Assignment Operator:- These operators are of two types
Simple Assignment Operator:- =
Compaund Assignment operator:- +=, -=, *= etc...,
6. Ternary Operator:- To check condition case (?:)
7. Bitwise Operator:- (AND, xOR, Compliment)
✱ The above Increment and Decrement operator and Assignment operator are called Unary operator. Which works as single operand with single operand.
✱ Arithmetic operator, Relational operator, Logical operator, Ternary operator and Bitwise operator are Binary operator, which works with the 2 or more operand.
No comments:
Post a Comment