1. What is meant by token ? Name
the tokens available in Java.
Ans.
Token
can be defined as each individual component of a java program in such a way
that it carries some meaning and takes part in effective execution of the
program. The various type of tokens available in java are :
Literals, Identifiers, Assignments, Punctuators , Separators ,Operators and
Keyword.
2. What are the keywords ? Can
keywords be used as identifiers ?
Ans.
Keywords
have special meaning to the Java compiler. They help in identifying a data type
name or program construct name. E.g. continue
, new, switch.
No,
keywords can never be used as identifiers.
3. What is an identifier ? What is
the identifier forming rule of Java?
Ans.
In
Java programming language, an identifier is a name given to a variable, class
or method. Identifiers start with a letter, underscore(_) or dollar sign ($).
The following characters can be digits. Identifiers are case sensitive and have
no maximum length.
The
following are valid Identifiers : identifier, userName, user_name, _sys_var1, $change.
4. An identifier can start with the
underscore “_”. True or False ? Ans. True.
5. Is Java case sensitive ? What is
meant by the term ‘case sensitive’?
Ans.
Yes, Java is a case-sensitive language, which means that the upper or lower
case of letters in Java programs matter.
Case
sensitivity enforces capital or lower case in text. For
example, if a password field is case sensitive, then you must enter each letter
case as you did when the password was created.
6.
An identifier in Java can begin with a digit or letter. True Or False ?
Ans. False
7.
All special characters are allowed in Java identifiers. True Or False ?
Ans. False
8. Which of the following are valid
identifiers and why / why not : Data_rec, _data, 1 data , data 1, my.file, asm,
switch, goto, break ?
Ans.
Valid- Data_rec , _data, asm. Cause identifiers start with a letter,
underscore(_) or dollar sign ($).Invalid-
1 data , data 1, my.file , switch , goto, break .Cause my.file-contains special character, Switch, goto, break are reserved keywords, 1 data & data 1-
contain space.
9. What are the literals ? How many
types of integer literals are available in Java?
Ans.
Literals are data items that are fixed data values. Java allows several : i)
integer-literal , ii)floating-literals , iii) Boolean literals , iv) character
–literal v) string-literal vi) the null literal.
Java
allows three types of integer literals i) Decimal (base 10) ,ii) Octal (base 8)
iii) Hexadecimal (base 16).
10. What is an integer constant ?
Write integer forming rule of Java.
Ans.
Integer constants are whole numbers without any decimal part. The rule for
forming an integer constants is: An integer constant must have at least one
digit and cannot contain a decimal point. It may contains + or – sign. A number
with no sign is interpreted to be positive.
11. How many types of integer
constants are allowed in Java ? How are they written ?
Ans.
Java allows three types of integer constants: Octal (base 8), Decimal (base
10), and Hexadecimal (base 16). An Octal integer must be started with a zero
’0′, a Hexadecimal integer starts with a ’0X’, all others are treated as
decimal integer constant.
12. What kind of program elements
are the following : 13, ‘a’, 4.38925, “a”, main() ?
Ans.
13 =Decimal
integer constant ‘a’ = Character constant
4.38925
= Floating constant “a” = String literals
main()
= Function
13. What kind of constants are the
following: 14, 011, 0X2A, 17, 014, 0XBC1 ?
Ans.
14 = Decimal integer constant 011 = Octal integer constant
0X2A =
Hexadecimal integer constant 17 = Decimal integer constant
014 = Octal integer
constant 0XBC1 = Hexadecimal integer constant
14. What is character constant in
Java? How are nongraphic characters represented in Java ?
Ans.
A character constant in Java must contain one character and must be enclosed in
single quotation marks, as in ‘Z’.
Nongraphic
characters are those characters that cannot be typed directly from keyboard
e.g. backspace, tab, carriage return etc.
15. Why are characters \, “ ,” and
? typed using escape sequences ?
Ans.
Java have certain nongraphic characters (nongraphic characters are those
characters that cannot be typed directly from keyboard e.g. backspace, tab,
carriage return etc.) Those nongraphic character can be represented by escape
sequence. An escape sequence is represented by backslash followed by one or
more character. The few escape sequence characters are: \n for new line, \t for
Horizontal Tab, \v for Vertical Tab, \b for Backspace, \” for Double Quotes
etc.
16. Which escape sequences
represent the newline character and null character ?
Ans.
\n for new line , \0 for null character.
17. What is meant by a floating
constant in Java ? How many ways can a floating constant be represented into ?
Ans.
Floating
constants are numbers having fractional parts. These may be written in one of
the two forms called fractional form or the exponent form.