Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 2.55 KB

TOKENS.md

File metadata and controls

30 lines (24 loc) · 2.55 KB

Tokens :- These are the smallest individual unit in a program. Java provides us with the following tokens:

  • Keywords- these are the reserved words that has a special significance to the compiler and can't be used anywhere else.The keywords const and goto are reserved,even though are not currently used.

  • Identifiers- these are the names of variables,methods,classes,packages and interfaces.

    • while using identifiers the following set of rules are to be kept in mind- (i) It can have any alphabet, digits, underscore and dollar sign characters. (ii) It should not begin with digits or should not contain any special character. for eg.2dh,a#b,dj@ are invalid. (iii)It cannot have any space between them. (iv) It must not be a keyword. (v) It can be of any length. Eventhough Java provides flexibility but try to keep the length minimal.

*Literals -It is used to represent whole numbers.It may be a positive,negative number without point(.) or comma(,). | Integer literal

  • There are 3 types of integer literals that can be represented in Java.
    1. Decimal(base 10) Integer Literal, which uses digits from 0 to 9 to represent a number. It should not be prefixed with 0.+ or - may be used to represent positive or negative numbers respectively. for eg. -13.8,+3
    2. Octal(base 8) Integer Literal ,which uses digits from 0 to 7 to represent a number.It should be prefixed with 0. Similarly + or - may be used to represent positive or negative numbers respectively. for eg. -035,076, or +57
    3. Hexadecimal(base 16) Integer Literal which uses digits from 0 to 9 and A to F to represent a number.It should be prefixed with 0x or 0X. Here also we can also use + or - . for eg. 0X67 or +0A7F3

| Floating point literal are used to represent fractional numbers i.e, number with a point. for eg. 14.6 | Boolean literal can be used in two states true or false | character literal is a character enclosed in single quotations.for eg. 'a' and 'B' are valid. | String literal a group of characters enclosed with double quotes can be considered to be String Literal .for eg. "hello", "BHAGAT SINGH". | Null literal - null represents nothing .It can be used as a value for any reference type variable. for eg. String name= null; | Class literal - It is an expression consisting of the name of a class , interface, array , or primitive type followed by a dot(',') and the token class.

  • Punctuators - can also be referred as separators.There are 9 separators in Java. They are: () {} [] ; , .

*Operators - They are special symbols used to evaluate an expression.