Primitive Types and Literals in Java - Quiz

Total: 12 questions

1. 

Which integer literals do exist in Java?

Octal (base 8),

decimal (base 10),

hexadecimal (base 16),

binary (base 2) - starting from Java 7.

2. Suffix of long literals?
They end with characters L or l.
3. How octal integers are written in Java?
Digits 0-7 are used and the number starts with a zero.
4. 

How hexadecimal numbers are constructed in Java?

They use 16 distinct symbols: 0 - 9 and a - f. Lowercase or capital letters are accepted. Hexadecimal number starts with prefix 0x or 0X.

5. 

How many digits are allowed in a hexadecimal literal?

It is allowed up to 16 digits in a hexadecimal number, not including the prefix 0x or the optional suffix extension L.

6. 

How to specify a binary literal?

To specify a binary literal, a prefix 0b or 0B should be added to the number.

7. 

Format of writing float literals?

They end with characters F or f.

8. 

Form of writing double literals?

They end with a digit or character D or character d.

9. 

Where it is prohibited to put underscores in numeric literals?

It is prohibited to put underscores in the following places:

  • At the beginning or end of a number
  • Adjacent to a decimal point in a floating point literal
  • Before an F or L suffix
  • In positions where a string of digits is expected
10. 

What will happen?

int var1 = 1;
if (var1) { }

Compiler error.

11. How to write a double quote character?
char c = '\"';
12. How to write a newline character?
char d = '\n';
Page 1 of 1