Java Tokens | Overview of Java Language

Java Tokens

The smallest individual units in a program are known as TOKEN.
A java program is a collection of tokens, comments and white spaces.
Java language includes five types of tokens

They are:
1) Reserved Keyword
2) Identifiders
3) Literals
4) Operator
5) Separators

Reserved Keyword
Keywords have specific meaning and implement specific features of the language.
Java language has reserved 60 words as keywords.

Identifiers
Identifiers are programmer-designed tokens. They are used for naming class,
methods, variables, objects, labels, packages, and interface in a program.

Literals
Literal is a programming language term that essentially means that what you type is what you get. Numbers, characters, and strings are all examples of literals.

Therefore literals
1) Are constants having no identifier?
2) Have their value specified within the program’s source code?
3) Can only appear on the right side of an assignment operator (=) or within an expression?
4) Have a data type associated with them?

Java program has five major types of literals:
1) Integer Literals
2) Floating type literals
3) Character literals
4) String literals
5) Boolean Literals

Integer literals
1. Represent an integer value
2. Can be expressed in decimal (the default), octal (base 8, or hexadecimal (base 16)
3. Are not enclosed in any special characters
4. Are automatically int (32 bits) unless the suffix ‘L’ is appended to make it long (64 bits)

Floating-point literals
1. Represent a real number (having a decimal point)
2. Can be expressed as a standard decimal value or in scientific notation
3. Are not enclosed in any special characters
4. Are automatically double (64 bits) unless the suffix ‘F’ is appended to make it float (32 bits)

char literals
1. Represent a single Unicode character (16 bits)
2. Must be enclosed within single quotes (apostrophes)
3. Are often associated with a single key stroke
4. Can represent special characters (“escape sequences”) used for device control

String literals
1. Represent a string of characters, such as “Java is fun”
2. Must be enclosed in double quotes
3. Are automatically stored as String class objects by the compiler. They will be covered later.

boolean literals
1. Can only have the value true or false
2. Can only be assigned to boolean variables

Constants
1. Are similar to variables but, once initialized, their contents may NOT be changed?
2. Are declared with the keyword final?
3. By convention, have all capital letters in their identifier. This makes them easier to see within the code.

Operators
An operator is a symbols that takes one or more arguments and operates on them to produce a result.

Separators
Separators are symbols used to indicate where groups of code are divided and arranged. They are basically define the shape and function of our code.
Ex: {}, [], ; , . , () etc.