1
(a) Which of the following are valid comments ?
- (a)/*comment*/
- (b)/*comment
- (c)//comment
- (d)*/comment*/
Show SolutionHide Solution↓
The valid comments are:
Option 1 — /*comment*/
Option 3 — //comment
(b) What is meant by a package ? Name any two java Application Programming Interface packages.
A package is a named collection of Java classes that are grouped on the basis of their functionality. Two java Application Programming Interface packages are:
- java.util
- java.io
(c) Name the primitive data type in Java that is:
- a 64-bit integer and is used when you need a range of values wider than those provided by int.
- a single 16-bit Unicode character whose default value is '\u0000'.
- long
- char
(d) State one difference between the floating point literals float and double.
| float literals | double literals |
|---|---|
| float literals have a size of 32 bits so they can store a fractional number with around 6-7 total digits of precision. | double literals have a size of 64 bits so they can store a fractional number with 15-16 total digits of precision. |
(e) Find the errors in the given program segment and re-write the statements correctly to assign values to an integer array.
int a = new int (5); for (int i=0; i<=5; i++) a[i]=i;
Corrected Code:
int a[] = new int[5];
for (int i = 0; i < 5; i++)
a[i] = i;