Java Tokens

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
  • Seprators

 

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:

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:

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.

 

Separators:

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:

 

 

Operators:

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

  1. Arithmetic Operators :- +,-,*,/,%
  2. Relational Operators:-<,<=,>,>=,= =,!=
  3. Logical Operators:- &&,||,!
  4. Assignment Operators:- =
  5. Increment & Decrement Operators:- ++,–
  6. Conditional Operators:- ?:
  7. Bitwise Operators:- &,!,^,~,<<,>>,>>>
  8. Special operators:- Instanceof,Dot Operator
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s