Friday 23 March 2018

Tokens

In a Java program, all characters are grouped into symbols called tokens.
Java language features are built from the first five categories of tokens.
(a) Keyword
(b) Identifier
(c) Literal / constant
(d) Operator
(e) Punctual latter / Separator

(a) Keyword:

Keywords are the reserved words for a language, which express the language
features. Keywords cannot be used to name variables, constants, or classes. Java is a casesensitive
language and the keywords should be written in lowercase only. The keywords with
all or some letters in uppercase can be treated as a variable name but that should be avoided.
Listed java keywords.
Finally, assert was recently added (in Java 1.4) to the original 48 keywords in Java.

(b) Identifier:  

Identifiers are used by programmers to name things in Java: - things such as
variables, methods, fields, classes, interfaces, exceptions, packages, etc.
Identifiers: - be meaningful and unique
ex:- bsic_sal
amt_ valid
gros_sal
(1) It is combination of alphabets, digits or underscore (_).it means digits cannot be used
of identifiers
ex:- salary
balary valid
Basic _salary
5.year invalid
Ex:-basic_Sal
Amt gross_Sal
Interest _sxear
(2) First character of identifier most be an alphabet or under _score (_).it minus digits
Character of identifier
ex :- salary valid
basic_salary
(3) Number special symbols can be used except (_) underscore
ex:-basic_sal
principal_sal valid
loan& salary invalid
my*salry
(4) No keyword: - are used as identifier
ex:- int
float invalid identifier
double
(5) Identifier: - doesn’t contain any white space
Ex:-basic sal invalid
Price amt
Pascal basic_sal valid
Prince _amt prince_amt
(6) Identifier:-can have maximum 31 or 32 character is signification
Ex:-Student roll errors both are some
Student marks

(c) Literal / constant: 

Literals are the values to be stored in variables and constants. A literal
contains a sequence of characters, such as digits, alphabets, or any other symbol that
represents the value to be stored. The various types of literals in Java.
Two types of literal/ constant in java
(a) Numeric
(1) integer-literal
(2) floating-point-literal
(3) Boolean-literal
(b) Non_ Numeric

(a) Numeric literal: - 

it is a work on number or numeric values.

(1) Integer-literal:- 

Are numeric type values. The numerical values can be represented
in octal and hexadecimal notation. The octal notation of a number is prefixed by
zero and hexadecimal numbers are prefixed by 0x.
For example, n=0123is integer literal in
octal notation, n=0x456 is integer literal in hexadecimal notation,
and n=2is decimal notation for an integer literal.
non-zero-digit = 1|2|3|4|5|6|7|8|9
digit = 0 | non-zero-digit
digits = digit{digit}
decimal-numeral = 0 | non-zero-digit[digits]
integer-literal = decimal-numeral
octal-numeral
hexadecimal-numeral
(1) character-literal
(2) string-literal
(3) null-literal
(2) Floating-point-literal:- Are numeric values with fractional part. For example,
x=7.9is a floating point literal.
Exponent-indicator = e | E
exponent-part = exponent-indicator [+|-] digits
floating-point-literal = digits exponent-part
digits.[digits] [exponent-part]
.digits[exponent-part]
...........................................................................................................................................................
(3) Boolean-literal: - Are the literals having value, true or false. For example,
x=false is a boolean literal.
Literals of the primitive type Boolean represent on/off, yes/no, present/absent
data. There are only two values of this primitive type, so its ENBF rule is trivially
written as
Boolean-literal = true | false
…………………………………………………………………………………………………………
(b) Non_ Numeric:- A literal /constant which is related two charter is called non numeric
Constant .it is of two type.
(1) Character-literal: - Are represented in single quotation marks.
For example, x=‘k’| 'graphic' | 'space' | 'escape-sequence' is a character literal.
(2) String-literal: - Are enclosed in double quotation marks. For example, x="James”
|”niraj kumar Sharma”| "{graphic | space | escape-sequence}" is a string
literal.

No comments:

Post a Comment