Core Java MCQ - Top 100 Questions and Answers

Welcome to this comprehensive guide featuring 100 Multiple-Choice Questions (MCQs) on Core Java. Java remains one of the most popular, versatile, and widely-used programming languages in the world, and understanding its core concepts is essential for anyone aspiring to become proficient in it. Whether you are a beginner, an intermediate programmer, or even an expert looking for a quick refresher, this blog post is your go-to resource.

We've curated these questions to cover all the important Core Java topics such as variables, data types, operators, control statements, loops, arrays, methods, inheritance, polymorphism, interfaces, packages, exception handling, multithreading, and much more. This ensures a rounded understanding of Java’s fundamentals.

But we didn’t stop there! Each question is followed by the correct answer as well as an explanation. These explanations are designed to reinforce your knowledge and help clarify any doubts you may have.

Are you ready to level up your Java skills? Let's dive into the quiz!

1. Who developed the Java programming language?

a) Microsoft
b) Oracle
c) Sun Microsystems
d) Google

2. In which year was the first version of Java released?

a) 1991
b) 1995
c) 1998
d) 2000

3. What was the original name for Java?

a) C++++
b) Oak
c) Pine
d) Maple

4. What does JVM stand for?

a) Java Version Machine
b) Java Virtual Mechanism
c) Java Verified Module
d) Java Virtual Machine

5. Which of the following is responsible for converting bytecode into machine code?

a) JDK
b) JRE
c) JVM
d) Java Compiler

6. What does JDK include?

a) Only a compiler
b) Only a runtime environment
c) Both a compiler and a runtime environment
d) None of the above

7. Which of the following is NOT a part of the JRE?

a) Bytecode verifier
b) Classloader
c) Java Compiler
d) Java API classes

8. What is the primary function of JRE?

a) Compilation
b) Debugging
c) Execution
d) Development

9. Can you run a Java program without JRE?

a) Yes
b) No

10. Is JVM platform-independent?

a) Yes
b) No

11. Which operator is used to perform bitwise "AND" operation?

a) &&
b) &
c) |
d) ||

12. What does the == operator compare in Java objects?

a) Values
b) References
c) Hash codes
d) Fields

13. Which operator is used for logical "AND" operation?

a) &&
b) &
c) ||
d) |

14. Which of the following is a unary operator?

a) +
b) -
c) !
d) All of the above

15. Which operator has the highest precedence?

a) +
b) *
c) ()
d) &&

16. What is the output of the expression true || false?

a) true
b) false
c) null
d) 0

17. Which of the following is not a primitive data type in Java?

a) byte
b) String
c) double
d) short

18. What is the default value of the int data type?

a) 0
b) 1
c) null
d) Undefined

19. Which of the following data types can store a floating-point number?

a) int
b) byte
c) double
d) char

20. Which data type can store a single character?

a) String
b) byte
c) char
d) int

21. How many bits does the long data type use?

a) 8
b) 16
c) 32
d) 64

22. What's the main difference between int and Integer in Java?

a) No difference
b) Integer can store larger values than int
c) int is a primitive data type, while Integer is a class
d) int can be null, while Integer cannot

23. Which loop construct in Java is best suited when the number of iterations is known?

a) for loop
b) while loop
c) do-while loop
d) break statement

24. What is the purpose of the continue statement in a loop?

a) To exit the loop immediately
b) To skip the current iteration and move to the next iteration
c) To terminate the program
d) To execute a specific block of code

25. Which loop construct in Java is best suited when the number of iterations is unknown?

a) for loop
b) while loop
c) do-while loop
d) none

26. What is the key difference between a while loop and a do-while loop in Java?

a) The syntax used to define the loop
b) The number of iterations performed
c) The condition check timing
d) The ability to use the break statement

27. Which loop construct guarantees that the loop body is executed at least once?

a) for loop
b) while loop
c) do-while loop
d) continue statement

28. What is an infinite loop?

a) A loop that executes only once
b) A loop that never terminates naturally
c) A loop that contains an unreachable code block
d) A loop that uses the continue statement

29. Which statement is used to exit a loop prematurely?

a) return statement
b) continue statement
c) break statement
d) exit statement

30. Which loop construct is best suited for iterating over an array or a collection?

a) for loop
b) while loop
c) do-while loop
d) continue statement

31. How do you declare an array in Java?

a) int arrayName;
b) int[] arrayName;
c) int arrayName[];
d) Both b and c

32. Which method is used to get the length of an array in Java?

a) length()
b) size()
c) getLength()
d) length

33. How do you initialize an array in Java?

a) int[] arr = (1,2,3,4,5);
b) int arr = {1,2,3,4,5};
c) int[] arr = new int[]{1,2,3,4,5};
d) int arr = new int(5);

34. What happens when you try to access an array element with an index that is out of bounds?

a) It returns -1
b) It returns a null value
c) It throws an exception
d) It initializes a new array

35. How can you check if two arrays are equal in Java?

a) Use the == operator
b) Use the .equals() method
c) Use Arrays.equals() method
d) Compare each element one by one

36. How do you access the fourth element of an array named numbers?

a) numbers[4];
b) numbers(3);
c) numbers[3];
d) numbers.get(3);

37. Which of the following operators is used for concatenation of two strings?

a) +
b) *
c) &
d) +=

38. Which of the following creates a mutable string?

a) String
b) StringBuilder
c) StringChar
d) StringMutable

39. In Java, strings are:

a) Primitive data types
b) Immutable objects
c) Mutable objects
d) Arrays of characters

40. How do you find the length of a string named 'example'?

a) example.size()
b) example.length()
c) example.getLength()
d) example.len()

41. What is the result of the expression "Java" + "Programming"?

a) JavaProgramming
b) Java Programming
c) Java-Programming
d) JavaProgramming-

42. Which method is used to compare two strings for equality?

a) ==
b) equals()
c) compare()
d) isEqual()

43. Which class can create a string that is thread-safe?

a) String
b) StringBuffer
c) StringBuilder
d) StringSafe

44. What is the root class for all Java classes?

a) Object
b) Class
c) Superclass
d) Root

45. What is polymorphism?

a) Multiple forms
b) Single form
c) No form
d) Static form

46. What is encapsulation in Java?

a) The process of combining data and methods into a single unit
b) The process of hiding data and methods within a class
c) The process of creating multiple instances of a class
d) The process of reusing code from existing classes

47. What is inheritance in Java?

a) The process of creating multiple instances of a class
b) The process of hiding data and methods within a class
c) The process of reusing code from existing classes
d) The process of combining data and methods into a single unit

48. What is polymorphism in Java?

a) The ability of a class to inherit properties and behaviors from another class
b) The process of hiding data and methods within a class
c) The process of creating multiple instances of a class
d) The ability of an object to take on many forms

49. What are abstract classes in Java?

a) Classes that cannot be instantiated
b) Classes that can be used as blueprints for creating objects
c) Classes that only contain abstract methods
d) All of the above

50. What is the purpose of the "super" keyword in Java?

a) To refer to the current object
b) To invoke the superclass constructor or methods
c) To create multiple instances of a class
d) To hide data and methods within a class

51. What is the purpose of the "this" keyword in Java?

a) To refer to the superclass
b) To create multiple instances of a class
c) To hide data and methods within a class
d) To refer to the current object

52. What is the purpose of the "final" keyword in Java?

a) To prevent the inheritance of a class
b) To prevent overriding of a method
c) To prevent modification of a variable's value
d) All of the above

53. What is an interface in Java?

a) A class
b) A data type
c) A blueprint for a class
d) A data structure

54. Which keyword is used to implement an interface?

a) extends
b) new
c) interface
d) implements

55. Can an interface extend another interface in Java?

a) No
b) Yes

56. Can an interface have a constructor?

a) Yes
b) No

57. Which of the following access modifiers are implicitly applied to variables in an interface?

a) private
b) protected
c) public
d) default

58. Is it possible to create an instance of an interface?

a) Yes
b) No

59. How many interfaces can a Java class implement?

a) None
b) Only one
c) Two
d) As many as needed

60. Can an interface inherit from a class?

a) Yes
b) No

61. Can an interface method be declared as final?

a) Yes
b) No

62. In Java 9, which type of methods can be added to interfaces to share code between methods?

a) Static
b) Private
c) Final
d) Protected

63. An interface with no methods is known as?

a) Abstract Interface
b) Marker Interface
c) Empty Interface
d) Functional Interface

64. Which keyword is used to define a default method in an interface?

a) static
b) default
c) final
d) abstract

65. Are all methods in an interface abstract?

a) Yes
b) No
c)
d)

66. Which of these can be contained in an interface?

a) Abstract methods
b) Constants
c) Default and static methods
d) All of the above

67. Which Java feature helps achieve multiple inheritance?

a) Abstract classes
b) Static methods
c) Interfaces
d) Enums

68. What is the default access modifier of a method in an interface in Java?

a) private
b) protected
c) public
d) None of the above

69. Why were default methods introduced in Java 8 interfaces?

a) To provide multiple inheritance
b) To add utility functions
c) To provide backward compatibility with older interface versions
d) For better performance

70. Starting from which Java version can an interface contain method implementations?

a) Java 5
b) Java 7
c) Java 8
d) Java 9

71. What is the purpose of the instanceof operator?

a) Multiply instances
b) Compare two object references
c) Check if an object is an instance of a specific class or interface
d) To create a new instance of a class

72. Which keyword is used to declare a class variable?

a) volatile
b) transient
c) static
d) final

73. Which keyword is used to prevent a class from being inherited?

a) final
b) abstract
c) class
d) extends

74. Which keyword is used to create an instance of a class?

a) new
b) return
c) this
d) create

75. Which keyword is used to inherit the properties and methods from another class?

a) import
b) package
c) extends
d) implements

76. Which keyword is used to refer to the current instance of a class?

a) class
b) this
c) instance
d) object

77. Which keyword in Java is used for importing packages into a program?

a) import
b) package
c) include
d) requires

78. What does the transient keyword indicate in a Java class?

a) The variable can change over time
b) The variable cannot be serialized
c) The variable is thread-safe
d) The variable is volatile

79. Which of these is a checked exception?

a) NullPointerException
b) ArithmeticException
c) IOException
d) IndexOutOfBoundsException

80. Which of the following can be used to create a custom checked exception?

a) Extending the Exception class
b) Extending the Error class
c) Extending the RuntimeException class
d) None of the above

81. Which of these is an unchecked exception?

a) ClassNotFoundException
b) SQLException
c) IOException
d) ArithmeticException

82. Which keyword is used to manually throw an exception in Java?

a) new
b) throw
c) throws
d) Throwable

83. Which of these classes is the superclass of all Exception and Error classes?

a) Exception
b) Error
c) Throwable
d) Object

84. What does the finally block do?

a) Catches any exception
b) Executes whether an exception is thrown or not
c) Executes only when an exception is thrown
d) Executes only when an exception is not thrown

85. Which keyword in Java is used for constant variables?

a) const
b) static
c) constant
d) final

86. In Java, what is the primary purpose of the Thread class?

a) File handling
b) String operations
c) Network operations
d) Creating and executing threads

87. Which method is used to start the execution of a thread?

a) run()
b) start()
c) execute()
d) go()

88. What does the join() method do when called on a thread object?

a) Terminates the thread
b) Pauses the thread
c) Forces the current executing thread to wait until the thread it's called on completes
d) Checks the status of a thread

89. Which method can be used to momentarily pause the execution of the current thread?

a) sleep()
b) wait()
c) pause()
d) stop()

90. Which interface provides an alternative to extending the Thread class?

a) Runnable
b) Callable
c) Executor
d) Parallel

91. What is a daemon thread in Java?

a) A thread that monitors and logs other threads
b) A thread that runs continuously in the background
c) A thread that manages memory usage
d) A thread that is part of the Java virtual machine

92. Which interface represents a collection of objects in which duplicate values can be stored?

a) List
b) Set
c) Map
d) ListMap

93. What will be the initial capacity of an ArrayList if it is created with the no-argument constructor?

a) 0
b) 5
c) 10
d) 16

94. What does a Set guarantee?

a) Order
b) No duplicates
c) Both
d) None of the above

95. Which List implementation is synchronized?

a) ArrayList
b) Vector
c) LinkedList
d) None of the above

96. Which interface represents a key-value pair mechanism?

a) List
b) Set
c) Queue
d) Map

97. Which method is used to check if a Collection is empty?

a) isEmpty()
b) isNull()
c) checkEmpty()
d) hasElements()

98. What does the Collections class sort() method do?

a) Sorts elements in descending order
b) Sorts elements in ascending order
c) Randomizes the order of elements
d) Removes duplicates

99. What is the key difference between HashSet and TreeSet?

a) HashSet allows duplicates; TreeSet doesn't
b) HashSet is ordered; TreeSet is unordered
c) HashSet is unordered; TreeSet is ordered
d) HashSet is synchronized; TreeSet is not

100. Which Collection does not allow null values?

a) ArrayList
b) HashMap
c) Hashtable
d) LinkedList

101. Which method is used to insert an object at a specific position in a List?

a) put()
b) set()
c) insert()
d) add()

102. Which class provides a thread-safe implementation of the List interface?

a) ArrayList
b) Vector
c) HashMap
d) LinkedHashMap

103. Which interface provides methods to traverse through a collection?

a) Iterator
b) Enumerator
c) Traverser
d) Mover

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare