Tokens
Tokens
class Simple
{
public static void main(String args[])
{
System.out.println("Hello Java");
}
}
o Keywords
o Identifiers
o Literals
o Operators
o Separators
Keywords:
01. abstract 02. boolean 03. byte 04. break 05. class
06. case 07. catch 08. char 09. continue 10. default
26. native 27. new 28. package 29. private 30. protected
31. public 32. return 33. short 34. static 35. super
36. switch 37. synchronized 38. this 39. thro 40. throws
41. transient 42. try 43. void 44. volatile 45. while
46. assert 47. const 48. enum 49. goto 50. strictfp
Identifier:
Identifiers are used to name a variable, constant, function, class, label, and array.
It usually defined by the user.
It uses letters, underscores, or a dollar sign as the first character.
Examples:
1. PhoneNumber
2. PRICE
3. phonenumber
4. $circumference
5. 12radius //invalid
Literals
literals are the constant values that appear directly in the program
It can be assigned directly to a variable.
The following figure represents a literal.
1. Integer Literal
2. Character Literal
3. Boolean Literal
4. String Literal
Integer Literals
Integer literals are sequences of digits.
There are four types of integer literals:
Decimal Integer
Octal Integer
Hexa-Decimal
Binary Integer
Decimal integer:
These are the set of numbers that consist of digits from 0 to 9. It may have a positive (+) or
negative (-).
For example, 5678, +657, -89, etc.
Octal Integer:
It is combinations of number have digits from 0 to 7 with a leading 0.
For example, 045, 026,
Hexa-Decimal:
Binary Integer:
Base 2, whose digits consists of the numbers 0 and 1.
Prefix 0b represents the Binary system.
Character Literals:
A character literal is expressed as a character or an escape sequence, enclosed in a single quote
('') mark.
Boolean Literals:
Boolean literals represent the logical value of either true or false.
Boolean literals can also use the values of “0” and “1.”
Examples:
boolean b = true;
boolean d = false;
String Literals:
String literals are sequences of characters enclosed between double quote ("") marks. These
characters can be alphanumeric, special characters, blank spaces, etc.
Operators:
Operators are special symbols that perform specific operations on one, two, or three operands,
and then return a result.
1. Arithmetic Operators
Arithmetic operators are used to perform arithmetic operations on variables and values.
Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
Modulo
Operation
%
(Remainder
after division)
2. Assignment Operators
Assignment operators are used in Java to assign values to variables.
= a = b; a = b;
+= a += b; a = a + b;
-= a -= b; a = a - b;
*= a *= b; a = a * b;
/= a /= b; a = a / b;
%= a %= b; a = a % b;
3. Relational Operators
Relational operators are used to check the relationship between two operands.
4. Logical Operators
Logical operators are used to check whether an expression is true or false.
&& (Logical expression1 && true only if both expression1 and expression2 are
AND) expression2 true
5.Unary Operators
Unary operators are used with only one operand.
Operator Meaning
+ Unary plus: not necessary to use since numbers are positive without using it
6. Bitwise Operators
Bitwise operators in Java are used to perform operations on individual bits.
Operator Description
~ Bitwise Complement
^ Bitwise exclusive OR
Separators:
Separators help us defining the structure of a program .