Saturday 13 July 2013

important theory questions with answers...(1st set)


Q1. Types of comments

Single Line-
//

Multi Line-
/* …

 …
              */

Documentation Comments – Which are displayed by the IDE. The are multiline
comments only given immediately before the function header.

Q2. What are tokens? Name the 5 types of tokens available in Java with an example each. 
The smallest individual unit in a program is known as a token. The five types of tokens
are- : 
a) Keywords:-  public, static, void, import etc. (Java’s own terms)
b) Identifiers:- (variables) alphabets, digits, under score, dollar sign etc.     


c) Literals:- (Constants) integer literals, floating literals, boolean literals, character literals, string
literal, the null literal. 

d) Punctuators (separators):- ()
{}
[]
;

 
e) Operators  =
 +
 -
 <
 >
Q3. What are escape sequences? Give any 5 escape sequences?

Codes for non-graphic or some special characters. 

‘\t’, ‘\n’, ‘\b’, ‘\\’, ‘\’’, ‘\”’, ‘\?’

Q4. ASCII codes?

A-Z = 65-90, a-z=97-122, ‘0’-‘9’=48-57


Q5. Prepare a chart showing all the data types with their size and range. 

See table with answer 12.

Q6. How can we declare a variable whose value cannot be changed in Java? 

If we write the final keyword before the variable name, then the value of that variable
cannot be changed later in the program. Any attempt of doing so will produce a compilation
error.
final int a=5;

Q7. Give the value (with reason) that the variable on the left hand side will hold in the following
statements
 
float a=(float)(21/2); 
int b=5 * 3/4 + 4/3 + 6; 
int c=100 + 10>10?10:20; 
float d= '1'+ '2'; 
int e= 20%7 / 2*3;


a) float a= (float) (21/2);
Output-: First integer division takes place= (float)(10). Then the answer is converted to floating type=10.0.

b) int b= 5*3/4+4/3+6; 
Output-:First multiplication takes place=15/4+4/3+6. Then
division=3+1+6.At last addition= 10. 

c) int c= 100+10>10?10:20; Output-:First addition takes place=110>10?10:20.Then ternary
operator works and returns the answer= 10.

d) float d= ‘1’+’2’;

Output-:The ASCII codes of these characters are added(49+50)
and converted into floating type=99.0.

e) int e= 20%7/2*3; 
Output-:First mod (6/2*3), then division(3*3) and at last
multiplication= 9. 

Q8.  Define (i)Precedence and Associativity  (ii) Mixed/Fixed(pure expr.) mode?
(i)
Precedence : Order of evaluation
(ii)
Associativity : Order of evaluation when precedence is the same.
(iii)
Mixed Mode or Impure Expressions – When operands are of different data types. 
(iv)
Fixed mode or pure expressions – When operands are of the same data type.

No comments:

Post a Comment