Wednesday, 9 March 2011

Java Tokens

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
  • Identifiers
  • Literals
  • Operators
  • Seperators
Java Character Set:
Characters used to write java tokens are the smallest units of java language. These characters are defined by the unicode character set, an emerging standard that tries to create characters for a large number of scripts world wide. The unicode is a 16  bit character coding system.

Keywords:
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.

Java Reserved Keywords
 Identifiers:
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

Literals:
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.

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

Separators:
In java, there are a few characters that are used as seperators . Semicolon(;) is the most commonly used seperator in java. It is used to terminate statements. The seperators are shown below:


Java Seperators


No comments:

Post a Comment