/Data Types, Variables & Operators
Concept Detail

Data Types, Variables & Operators

Difficulty: easy

Overview


Java has 8 primitives: byte (8-bit, -128 to 127), short (16-bit), int (32-bit), long (64-bit), float (32-bit), double (64-bit), char (16-bit Unicode), boolean. Default instance values: numeric = 0, boolean = false, reference = null. Auto-boxing converts primitives to wrapper types (int → Integer). Integer division truncates. Operator precedence: *, /, % before +, -.

Practice Linked Questions


easy

Q1. What is the default value of an instance variable of type int in Java?


Select one answer before revealing.

easy

Q2. What is the size of the char data type in Java?


Select one answer before revealing.

easy

Q3. Which of the following is NOT a primitive data type in Java?


Select one answer before revealing.

medium

Q4. What is the result of: int x = 7 / 2; in Java?


Select one answer before revealing.

hard

Q5. What is the output of: System.out.println(5 + 3 + "Java");


Select one answer before revealing.

hard

Q6. What is auto-boxing in Java?


Select one answer before revealing.

medium

Q7. What is the result of: 2 + 3 * 4 in Java?


Select one answer before revealing.

easy

Q8. What is the valid range of a byte data type in Java?


Select one answer before revealing.

easy

Q9. What is the output of the following code? int x = 10; System.out.println(x++); System.out.println(x);


Select one answer before revealing.

hard

Q10. What is the output of the following code? int a = 5; int b = a++ + ++a; System.out.println(a + " " + b);


Select one answer before revealing.

hard

Q11. What is the output of the following code? Integer a = 127; Integer b = 127; Integer c = 128; Integer d = 128; System.out.println(a == b); System.out.println(c == d); System.out.println(a.equals(b));


Select one answer before revealing.

medium

Q12. What is the output of the following code? int x = 2; switch (x) { case 1: System.out.println("One"); case 2: System.out.println("Two"); case 3: System.out.println("Three"); break; case 4: System.out.println("Four"); }


Select one answer before revealing.

hard

Q13. What is the output of the following code? int x = 5; double result = (x > 3) ? 1 : 2.0; System.out.println(result);


Select one answer before revealing.

hard

Q14. What is the output of the following code? char c = 'A'; c += 1; System.out.println(c); System.out.println((int) c);


Select one answer before revealing.

easy

Q15. What is the output of the following code? int x = 10; String result = (x > 5) ? "Greater" : "Lesser"; System.out.println(result);


Select one answer before revealing.

medium

Q16. What is the output of the following code? System.out.println(Integer.parseInt("42")); System.out.println(Integer.toBinaryString(10)); System.out.println(Integer.MAX_VALUE);


Select one answer before revealing.

medium

Q17. What is the output of the following code? System.out.println((int) 9.99); System.out.println((int) -9.99);


Select one answer before revealing.

easy

Q18. What is the output of the following code? int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) break; result += i; } System.out.println(result);


Select one answer before revealing.