[post-views]
In this lesson, you will learn.
In Java, tokens refer to the smallest units of a program that the compiler recognizes.
Java source code is made up of various types of tokens, which are the building blocks of the language. The basic types of tokens in Java include:

Rule to make identifiers in Java
The following are the rules for forming valid identifiers.
Examples: Valid identifiers
Mybooks, DATE_06_12, B1T019, AvgValue, result, $1_23_$a, _value, PRINTRESULT, _PRICE, _MY_JK_2, temp$, isAlphabet
Examples: Invalid identifiers
There are 50 keywords present in Java as shown in the below table.
| Keyword | Description |
|---|---|
| abstract | Indicates that a class or method is abstract. |
| assert | Used for debugging purposes to make an assertion. |
| boolean | Defines a variable to store the boolean value true or false. |
| break | Exits a loop or a switch statement. |
| byte | Defines a variable to store an 8-bit signed integer. |
| case | Defines a branch in a switch statement. |
| catch | Catches exceptions generated by try statements. |
| char | Defines a variable to store a 16-bit Unicode character. |
| class | Declares a class. |
| const | Not used. Reserved for future use. |
| continue | Skips the current iteration of a loop. |
| default | Specifies the default case in a switch statement. |
| do | Starts a do-while loop. |
| double | Defines a variable to store a double-precision 64-bit IEEE 754 floating point. |
| else | Specifies the block of code that runs if an if statement’s condition is false. |
| enum | Declares an enumerated type. |
| extends | Indicates that a class is derived from another class or interface. |
| final | Indicates that a value cannot be changed or a method cannot be overridden. |
| finally | Specifies a block of code that will always be executed in a try-catch structure. |
| float | Defines a variable to store a single-precision 32-bit IEEE 754 floating point. |
| for | Starts a for loop. |
| goto | Not used. Reserved for future use. |
| if | Starts an if statement. |
| implements | Indicates that a class implements an interface. |
| import | Imports other Java packages or classes. |
| instanceof | Tests whether an object is an instance of a specific class or implements an interface. |
| int | Defines a variable to store a 32-bit signed integer. |
| interface | Declares an interface. |
| long | Defines a variable to store a 64-bit signed integer. |
| native | Specifies that a method is implemented in native code using JNI. |
| new | Creates new objects. |
| null | Indicates that a reference does not refer to anything. |
| package | Defines a package, a namespace for organizing classes and interfaces. |
| private | Restricts access to a member (variable or method) to the defining class. |
| protected | Restricts access to a member to subclasses and classes in the same package. |
| public | Makes a class, method, or variable accessible from any other class. |
| return | Exits a method and optionally returns a value. |
| short | Defines a variable to store a 16-bit signed integer. |
| static | Indicates that a member (variable or method) belongs to the class, rather than instances of the class. |
| strictfp | Used to restrict the precision and rounding of floating point calculations to ensure portability. |
| super | Refers to superclass (parent) objects. |
| switch | Specifies a switch statement. |
| synchronized | Indicates that a method or block of code is synchronized for threading. |
| this | Refers to the current object in a method or constructor. |
| throw | Throws an exception. |
| throws | Indicates what exceptions a method can throw. |
| transient | Prevents serialization of a field. |
| try | Starts a block of code that will be tested for exceptions. |
| void | Indicates that a method does not return a value. |
| volatile | Indicates that a variable may be changed by threads other than the one that is executing. |
| while | Starts a while loop. |
Note: The keywords const and goto are reserved but not used.
Note: In addition to the keywords, Java reserves the true, false, and null. These are values defined by Java and can’t be used as names of variables, classes, and so on.
Literals represent constant values in Java code. The following are the Java literals.

Types of Integer Literals
1. Decimal(base 10)
2. Octal(base 8)
3. Hexadecimal(base 16)
0 through 9 represent values zero through nine, and the letters A through F (or a through f) represent values ten through fifteen.Example
The number 13 can be written either as 13(decimal), 015(octal), and 0XD(hexadecimal).
Floating-Point Literals may be written in one of the following two forms
1. Fractional Form
Example: A valid floating-point literals in fractional form
4.0, -34.05, 4.01234, 0.67567, -0.5674
Example: Invalid floating-point literals in fractional form
2. Exponent Form

Example: Floating Point Literals of Exponent Form
2.4 can be written as 0.24 x 101 = 0.24E01, where 0.24 is the mantissa part(before E) and exponent part is 1(after E).
Valid Real literals in exponent form
234E04, 2.34E09, 0.234E04, 120.0E05, 234E+4, -0.132E-3
Invalid Real Literals in the exponent form
These characters are represented by the escape sequence(, backslash) followed by one or more characters.
The following table shows the escape sequences.
| Escape Sequence | Non-graphic Character |
| b | Backspace |
| t | Horizontal Tab |
| v | Vertical Tab |
| f | Formfeed |
| n | Newline or Line feed |
| r | Carriage return |
| \ | Backslash |
| ’ | Single quote |
| ’’ | Double quote |
| a | Alert bell |
| ? | Question mark |
| ddd | Octal Number |
| uxxxx | Hexadecimal Number(Hn is Hexadecimal) |
Note: The true literal in Java does not equal 1, nor does the false literal equal 0.
Example: String Literals
“Hello” -> Its size is 10 bytes (Each character takes 2 bytes).
“abc” -> It size is 6 bytes(a is one character)
“amit’ class” -> Its size is 24 bytes(’ is one character)
{}, parentheses (), semicolons ;, commas ,, etc.The separators in Java are shown in the following table.
| Symbol | Name | Use |
| ( ) | Parentheses | Contains lists of parameters in method definition and invocation, used in typecasting, etc. |
| { } | Braces | Use to initialized arrays, define a block of code, for classes, methods, and local scopes. |
| [ ] | Brackets | Used to declare array types. |
| ; | Semicolon | Terminates statements. |
| , | Comma | Separates identifiers in a variable declaration. |
| . | Period | Used to separate package names from sub-packages and classes. |
| :: | Colons | Used to create a method or constructor reference. (Added by JDK 8.) |
Operators perform operations on variables and values.
Java provides many operators that are divided into the following groups.
The Java operators are described in detail in the upcoming lesson.
There are no reviews yet. Be the first one to write one.
You must be logged in to submit a review.