Comprehensive Java Multiple Choice Questions (MCQs)
Concepts and Fundamentals
1. What generation is Java considered?
A) 1st Generation B) 2nd Generation C) 3rd Generation D) 4th Generation
2. Who were the original developers of Java?
A) Mark Zuckerberg
B) James Gosling, Mike Sheridan, Patrick Naughton
C) Bill Gates, Paul Allen, Steve Ballmer
D) Linus Torvalds, Richard Stallman, Dennis Ritchie
3. In what year was Java officially released?
A) 1991 B) 1994 C) 1995 D) 1996
4. What was the original name of Java?
A) Python B) Oak C) Ruby D) Kotlin
5. Java is a platform-independent language because of:
A) Compiler C) JDK (Java Development Kit)
B) JVM (Java Virtual Machine) D) API
6. Which of the following is NOT a Java feature?
A) Platform Independence C) Write Once, Run Anywhere
B) Object-Oriented D) Machine-level coding
7. Which statement is true about Java’s compilation?
A) Java code is compiled into machine code.
B) Java code is interpreted directly by the operating system.
C) Java code is compiled into bytecode that is interpreted by the JVM.
D) Java does not require compilation.
8. What does JVM stand for?
A) Java Virtual Method C) Java Virtual Machine
B) Java Volatile Machine D) Java Variable Model
9. What is a token in Java?
A) Smallest individual unit in a program C) The final output of a program
B) A large block of code D) An error in Java
10. Which of the following is NOT a Java keyword?
A) for B) void C) main D) static
11. Which of the following is a valid identifier in Java?
A) 123Var B) $myVar C) if D) var@
12. What is the size of an `int` in Java?
A) 8 bits B) 16 bits C) 32 bits D) 64 bits
13. What is a literal in Java?
A) A block of code C) A type of class
B) A fixed value written in the code D) A keyword
14. Which data type is used for true/false values?
A) int B) char C) boolean D) float
15. What is the correct syntax for the ternary operator?
A) condition? value1: value2 C) condition: value1? value2
B) value1? condition: value2 D) value1: condition? value2
16. Which of the following is NOT an operator in Java?
A) + B) ? C) # D) %
17. Which operator is used for logical AND in Java?
A) && B) || C) ! D) &
18. Which of the following represents a multi-line statement in Java?
A) Single semicolon-separated statement C) Single-line comments
B) Code enclosed in curly braces D) String literals
19. The method System.out.println("Hello, World!"); is an example of:
A) Declaration statement C) Expression statement
B) Assignment statement D) Control flow statement
20. Which of the following statements about the switch statement in Java is correct?
A) It can only handle integer values. C) It does not require break statements.
B) It cannot handle boolean values. D) It is used to exit loops.
21. What does “Write Once, Run Anywhere” mean in Java?
A) Java code can only run on one platform.
B) Java programs are platform-independent and can run on any device with a JVM.
C) Java programs must be rewritten for each platform.
D) Java does not require a virtual machine to run.
22. Which of the following features makes Java more secure?
A) Platform dependency C) Lack of error handling
B) Bytecode verification D) Absence of type checking
23. Which of the following is an example of an escape sequence in Java?
A) \a B) \n C) \c D) \e
24. What type of operator is `++` in Java?
A) Arithmetic C) Increment/Decrement
B) Logical D) Bitwise
25. Which of the following is a relational operator in Java?
A) && B) < C) == D) %
26. Which keyword is used to declare a class in Java?
A) void B) static C) class D) import
27. How are character literals defined in Java?
A) Enclosed in double quotation marks C) Enclosed in curly braces
B) Enclosed in single quotation marks D) Enclosed in parentheses
28. What does the `new` keyword do in Java?
A) It creates a new package. C) It creates a new object.
B) It declares a new method. D) It imports a new library.
29. Which of the following is a valid floating-point literal in Java?
A) 42 B) 42.0 C) '42' D) true
30. What is the role of the JVM in executing Java programs?
A) It translates Java code directly into machine code.
B) It compiles Java code into bytecode.
C) It interprets and executes Java bytecode on different platforms.
D) It converts Java into high-level languages.
31. What happens if the `break` statement is omitted in a `switch` case?
A) The program will terminate.
B) The next case will execute regardless of its value.
C) An error will occur.
D) The `default` case will always run.
32. What is an identifier in Java?
A) A reserved keyword
B) A name given to program elements like variables, methods, or classes
C) A type of operator
D) An object reference
33. Which of the following is NOT an escape sequence in Java?
A) \n B) \t C) \r D) \y
34. What is the primary use of the `static` keyword in Java
A) To declare instance variables
B) To create objects
C) To indicate that a member belongs to the class itself rather than an instance
D) To handle exceptions
35. Which of the following is a primitive data type in Java?
A) int B) String C) Array D) Object
36. What is the size of a char data type in Java?
A) 8 bits B) 16 bits C) 32 bits D) 64 bits
37. Which of the following is NOT a control flow statement in Java?
A) if-else B) switch C) break D) new
38. Which of the following is an example of a bitwise operator?
A) ~ B) && C) || D) +
39. Which access modifier allows visibility within the same class and its subclasses?
A) public B) private C) protected D) default
40. Which statement about Java's platform independence is correct?
A) Java programs need to be rewritten for each platform.
B) Java programs run the same on any platform using the JVM.
C) Java programs are only platform-independent for Windows.
D) Java does not support platform independence.
41. Which of the following is a feature of Java?
A) Case Insensitive C) Dynamically Typed
B) Strongly Typed D) Interpreted Only
42. Which of the following operators is used for comparison in Java?
A) == B) = C) ## D) **
43. What is the primary purpose of the static keyword in Java?
A) To make a variable global
B) To declare a variable unchangeable
C) To define class-level methods and variables
D) To make a class non-extendable
44. In Java, which of the following is considered a token?
A) Operators B) Classes C) Methods D) Strings
45. Which of the following is an example of a valid character literal in Java?
A) "A" B) A C) 'A' D) 'Hello'
46. What is the correct escape sequence to create a new line in Java?
A) \r B) \n C) \t D) \\
47. Which Java operator is used for modulus (remainder) operation?
A) + B) % C) / D) *
48. Which of the following is an example of a boolean literal?
A) 1 B) True C) "true" D) true
49. How many primitive data types are there in Java?
A) 6 B) 7 C) 8 D) 9
50. What does the escape sequence \t represent in Java?
A) Tab space B) New line C) Backslash D) Carriage return
51. What will be the result of the following code: int x = 5; int y = ++x; ?
A) y = 6, x = 5 B) y = 6, x = 6 C) y = 5, x = 6 D) y = 5, x = 5
52. What type of operator is the && operator in Java?
A) Arithmetic B) Logical C) Relational D) Assignment
53. Which of the following statements best defines the term 'literal' in Java?
A) A keyword used to declare variables
B) A fixed value that appears directly in the source code
C) An operator used in expressions
D) A data type
54. Which data type in Java is used to store decimal numbers?
A) int B) double C) boolean D) char
55. What is the output of the following code snippet?
String str = "Java\nProgramming";
System.out.print(str);
A) Java Programming C) Java Programming
B) Java\nProgramming D) Error
56. Which of the following is true about the void keyword?
A) It specifies a method will not return any value.
B) It specifies a variable cannot be changed.
C) It specifies a class cannot be extended.
D) It specifies a method will return an integer.
57. Which symbol is used to denote an object instantiation in Java?
A) new B) class C) create D) instant
58. Which keyword in Java is used to prevent inheritance of a class?
A) static B) private C) final D) void
59. Which operator is used to perform bitwise AND in Java?
A) & B) && C) |j D) ||
60. Which keyword in Java is used to define a class
A) new B) static C) class D) public
61. What does \b represent in Java’s escape sequences?
A) New line B) Backspace C) Tab D) Carriage return
62. Which of the following is NOT a primitive data type in Java?
A) int B) boolean C) float D) String
63. Which of the following is true about Java’s strongly typed nature?
A) It automatically converts data types.
B) It prevents data type mixing without explicit conversion.
C) It allows mixing data types freely.
D) It doesn't require variable declarations.
64. Which of the following is a correct declaration of a byte variable in Java?
A) byte b = 256; B) byte b = 128; C) byte b = 127; D) byte b = -129;
65. What will be the output of the following code?
int a = 10;
int b = a++;
System.out.println(b);
A) 10 B) 11 C) 9 D) 0
66. Which operator in Java is used for bitwise OR operation?
A) & B) | C) ^ D) %
67. What is the range of a short data type in Java?
A) [-128 to 127] C) [-2,147,483,648 to 2,147,483,647]
B) [-32,768 to 32,767] D) [0 to 65,535]
68. In Java, the break statement is mainly used in:
A) Loops B) Classes C) Methods D) Arrays
69. What is the result of the following comparison? 5 > 4 && 6 > 7
A) true B) false C) 1 D) 0
70. Which keyword is used to import other Java packages into a program?
A) import B) package C) include D) static
71. Which of the following is NOT an example of an arithmetic operator in Java?
A) + B) - C) * D) &
72. Which of the following literals represents an octal number in Java?
A) 08 B) 052 C) 0x52 D) 0b101
73. Which of the following is the correct syntax to declare a constant in Java?
A) constant int x = 10; B) final int x = 10; C) static int x = 10; D) const int x = 10;
74. What is the output of the following code?
boolean b = true;
System.out.println(!b);
A) true B) false C) 0 D) 1
75. Which symbol is used to terminate a statement in Java?
A) Colon (:) B) Semicolon (;) C) Comma (,) D) None of the above
76. Which of the following is NOT a feature of the switch statement in Java?
A) Can be used with int, char, String
B) Requires a break statement to prevent fall-through
C) Can handle floating-point types
D) Can have a default case
77. Which of the following is true about the continue statement?
A) It terminates the entire loop.
B) It skips the remaining code in the current loop iteration.
C) It ends the program execution.
D) It exits the method.
78. Which of the following is a ternary operator in Java?
A) + B) && C) ? D) :
79. What will be the result of the following code?
int a = 5;
int b = 3;
System.out.println(a > b ? a : b);
A) 3 B) 5 C) true D) false
80. The default value for an uninitialized boolean variable is:
A) true B) false C) 0 D) null
81. Which access modifier in Java allows a member to be accessed within its own class and
subclasses?
A) public B) private C) protected D) static
82. In Java, when a variable is declared as final, it means:
A) The variable can be changed within the same class.
B) The variable cannot be changed once initialized.
C) The variable can be accessed from any class.
D) The variable is initialized dynamically.
83. Which of the following is an invalid floating-point literal in Java?
A) 3.14 B) 6.022e23 C) 5.0 D) 0.02F
84. Which of the following operators is used for integer division in Java?
A) / B) // C) % D) ^
85. What is the result of the following logical expression? !(true && false)
A) true B) false C) 0 D) 1
86. What will be printed by the following code?
char c = 'A';
System.out.println((int)c);
A) 65 B) 'A' C) '65' D) 0
87. Which of the following operators is used to shift bits to the right in Java?
A) << B) >> C) ~ D) &
88. What is the size of a long data type in Java?
A) 8 bits B) 16 bits C) 32 bits D) 64 bits
89. Which of the following statements about the char data type in Java is true?
A) It is 8 bits long.
B) It can store multiple characters.
C) It stores characters in the Unicode format.
D) It has no default value.
90. Which symbol is used for the bitwise XOR operation in Java?
A) ^ B) & C) | D) ~
91. What is the default value of a char variable in Java?
A) 0 B) '\u0000' C) null D) ' '
92. What is the result of the following relational expression? 5 >= 5
A) true B) false C) 1 D) 0
93. Which keyword in Java is used to define a package?
A) class B) package C) import D) static
94. Which of the following statements correctly defines a method that does not return any value?
A) void myMethod() { ... } C) final myMethod() { ... }
B) static myMethod() { ... } D) return myMethod() { ... }
95. In Java, which of the following is used to terminate a loop prematurely?
A) break B) continue C) exit D) return
96. Which statement about the switch statement is true?
A) It can be used with boolean types.
B) It allows multiple case labels to be executed without a break.
C) It can only be used with integers.
D) It must always include a default case.
97. Which of the following is a valid array declaration in Java?
A) int arr[] = new int[5]; C) arr[5] = int new[];
B) int arr[5] = new int[]; D) new int[] arr[5];
98. In Java, what is the default value of an int variable that is not initialized?
A) 0 B) null C) -1 D) undefined
99. Which loop is guaranteed to execute at least once in Java?
A) for loop C) do-while loop
B) while loop D) None of the above
100. Which of the following is a non-primitive data type in Java?
A) int B) boolean C) float D) String
Practice Makes Perfect!
These Java Multiple Choice Questions (MCQs) are meant to help you understand the key concepts of
Java programming. By solving them, you'll get a better grasp of how Java works, including its syntax,
operators, and much more.
Remember, programming is a skill that improves with practice. So, take your time, solve these
questions, and don't hesitate to ask questions in class if something is unclear. Keep learning and
coding!