A Java program is a collection of tokens, comments and white spaces. There are five types of tokens included in java language. They are:
- Reserved keywords
Java Character Set:
Characters used to write java tokens are the smallest units of java language. These characters are defined by the uni-code character set, an emerging standard that tries to create characters for a large number of scripts world wide. The uni-code is a 16 bit character coding system.
Keywords implement specific features of the language. There are 60 reserved keywords defined in the java language. These keywords combined with the syntax of the operators and separators, from the definition of the java language. These keywords cannot be used as names for a variable, class or method.
Identifiers are used for class names, method names, and variable names. An identifier may beb any sequence of uppercase and lowercase letters,numbers, or the underscore and dollar-sign characters. They must not begin with a number.
Again java is case sensitive , so First is different from first. Some examples of valid identifiers are:
avg temp b5 count ptest this_is_fine
Invalid variable names include:
2count high-temp Not/fine
A constant value in java is created by using a literal representation of it. Literals can be digits, letters, and other characters. Major five types of literals in java are:
- Integer literals
- Floating-point literals
- Character literals
- String literals
- Boolean literals
Each of them has a type associated with it. The type describes how the values behave and how they are stored. Example of some literals are given below:
10098.6 ‘Y’ “This is an answer”
A literal can be used anywhere a value of it’s type is allowed.
In java, there are a few characters that are used as separators . Semicolon(;) is the most commonly used separator in java. It is used to terminate statements. The separators are shown below:
Java supports a rich set of operators.An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.Operators are used in programs to manipulate data and variables.They usually form a part of mathematical or logical expressions.Java operators can be classified into a number of related categories as given below:-
- Arithmetic Operators :- +,-,*,/,%
- Relational Operators:-<,<=,>,>=,= =,!=
- Logical Operators:- &&,||,!
- Assignment Operators:- =
- Increment & Decrement Operators:- ++,–
- Conditional Operators:- ?:
- Bitwise Operators:- &,!,^,~,<<,>>,>>>
- Special operators:- Instanceof,Dot Operator