Java Data types
Java Data types
10. How would you print characters like \, ' and " in Java?
Ans. We can print characters like \, ‘and “ in Java with the help of escape sequence.
Ans. Integer constants are values with whole numbers and floating constants can have decimal values.
For example: integer constants are -128, 127 and floating constants are – 1.5f, 1.5F.
16. Which integer and floating point data types take up the same number of bits in computer memory?
Ans. (i) int and float (ii) double and long
17. What is variable initialization in Java? What are the default values of the following type of
variables - short, int, long, float, double, and char?
Ans. Variable initialization is assigning value to a variable during declaration.
Type Default value
short 0
int 0
long 0L
float 0.0f
double 0.0d
char ‘\u0000’
18. Provide the declaration for two variables called xCoordinate and yCoordinate. Both variables are
of type int and both are to be initialised to zero in the declaration.
Ans. int xCoordinate = 0, yCoordinate = 0 ;
19. Write a Java assignment statement that will set the value of the variable interestAmount to the
value of the variable balanceAmount multiplied by the value of the variable rate. The variables are of
type double.
Ans. double interestAmount, rate, balanceAmount;
interestAmount = balanceAmount * rate;
20. Explain the statement, "a well-documented code is as important as the correctly working code".
Ans. Comments are important part of program and are actually added to give an overview of the code
www.bhuvantechs.com
and provide additional information that is not readily available in it. The primary purpose of comment is
to document the code so that even a layperson can understand the purpose of the written code.
Comments are ignored by the compiler and do not affect the program execution.
22. Write a Java constant declaration that gives the name TAX_RATE to the value 15%.
Ans. TAX_RATE=.15;
24. What are symbolic constants? How are they useful in writing programs?
Ans. Memory locations whose values cannot be changed within a program are called constants or
symbolic constants. When the program is compiled, each occurrence of a symbolic constant is replaced
by its corresponding character sequence.
25. What is the output produced by the following lines of program code?
char x, y;
x = 'y';
System.out.println(x);
y = 'z';
System.out.println(y);
x = y;
System.out.println(x);
Ans. Output:
y
z
z
www.bhuvantechs.com