Java is a high-level, class-based, object-oriented programming language designed on the “Write Once, Run Anywhere” (WORA) philosophy enabled by the Java Virtual Machine (JVM). Mastering Java basics requires a solid understanding of its core runtime architecture comprising the JDK, JRE, and JVM alongside fundamental syntax rules, primitive data types, control flow structures, and object-oriented principles. From defining the standard main entry point method to handling arrays, strings, access modifiers, and basic exception handling, a firm grasp of Java fundamentals is essential for software development and technical coding assessments.
Java Basics MCQs for Developer Interviews & Certification
1 min read
Correct Answer: b) Java Virtual Machine
Explanation:
The Java Virtual Machine (JVM) executes Java bytecode and provides machine independence.
Correct Answer: c) String
Explanation:
String is a built-in reference class type, whereas int, boolean, and char are primitive types.
Correct Answer: d) No default value
Explanation:
Local variables do not receive a default value and must be explicitly initialized before use.
Correct Answer: a) public and default
Explanation:
Outer classes in Java can only have public or default (package-private) access modifiers.
Correct Answer: b) run()
Explanation:
The run() method contains the code executed by a thread and is required by the Runnable interface.
Correct Answer: b) 4 bytes
Explanation:
An int in Java is a 32-bit signed integer, occupying 4 bytes of memory.
Correct Answer: b) java.util
Explanation:
The Scanner class is located within the java.util package.
Correct Answer: b) extends
Explanation:
The extends keyword is used in class declarations to inherit from a superclass.
Correct Answer: b) int
Explanation:
The hashCode() method returns an integer hash code value for the object.
Correct Answer: b) ArithmeticException
Explanation:
Dividing an integer by zero triggers an unchecked ArithmeticException.
Correct Answer: c) do-while loop
Explanation:
A do-while loop evaluates its condition after executing the body, ensuring it runs at least once.
Correct Answer: c) Serializable
Explanation:
Serializable is a marker interface because it contains no methods and signals metadata to the JVM.
Correct Answer: a) Java Development Kit
Explanation:
JDK stands for Java Development Kit, which includes tools needed to develop and run Java programs.
Correct Answer: b) ==
Explanation:
The == operator is used to compare primitive values or object reference addresses for equality.
Correct Answer: b) Object
Explanation:
Every class in Java implicitly inherits from the java.lang.Object class.
Correct Answer: b) 30Hello
Explanation:
Java evaluates addition from left to right; 10 + 20 is calculated as 30, then concatenated with "Hello".
Correct Answer: b) final
Explanation:
Declaring a method as final ensures subclasses cannot override it.
Correct Answer: a) -128 to 127
Explanation:
A byte is an 8-bit signed integer, ranging from -128 to 127.
Correct Answer: c) ArrayList
Explanation:
ArrayList is an ordered list collection that permits duplicate elements.
Correct Answer: b) IOException
Explanation:
IOException is a checked exception that must be caught or declared in the method signature.
Correct Answer: c) // Comment
Explanation:
Single-line comments in Java start with double forward slashes (//).
Correct Answer: c) private
Explanation:
The private access modifier restricts visibility strictly to the enclosing class.
Correct Answer: b) false
Explanation:
Instance variables of type boolean are initialized to false by default.
Correct Answer: b) start()
Explanation:
Calling the start() method creates a new thread execution context and then calls the run() method.
Correct Answer: a) Character
Explanation:
Character is the wrapper class for the primitive char data type.
Correct Answer: a) Method overloading and method overriding
Explanation:
Polymorphism is realized via compile-time (overloading) and runtime (overriding) polymorphism.
Correct Answer: b) throw
Explanation:
The throw keyword is used to trigger an exception instance manually.
Correct Answer: a) Interfaces can contain method bodies by default (since Java 8).
Explanation:
Since Java 8, interfaces can contain default and static methods with method bodies.
Correct Answer: b) .class
Explanation:
The Java compiler compiles source files (.java) into bytecode files (.class).
Correct Answer: c) Map
Explanation:
A Map interface maps unique keys to corresponding values.
Correct Answer: a) 2
Explanation:
The signed right shift operator (>>) divides the number by 2 to the power of 1. 5 / 2 = 2 using integer division.
Correct Answer: b) equals()
Explanation:
The equals() method compares the actual character contents of two String objects.
Correct Answer: b) StringBuilder
Explanation:
StringBuilder provides a mutable sequence of characters.
Correct Answer: c) java.lang
Explanation:
The java.lang package contains fundamental classes and is imported implicitly by the compiler.
Correct Answer: b) The program terminates and prints a stack trace.
Explanation:
An uncaught exception causes the thread to terminate and print its stack trace to standard error.
Correct Answer: b) transient
Explanation:
The transient keyword instructs the JVM to skip a field during object serialization.
Correct Answer: b) 4 bytes
Explanation:
A float is a 32-bit single-precision floating-point number, occupying 4 bytes.
Correct Answer: b) this
Explanation:
The this keyword acts as a reference to the current object instance.
Correct Answer: a) Converting a primitive type to its corresponding wrapper class object automatically.
Explanation:
Autoboxing is the automatic conversion made by the Java compiler between primitives and wrapper objects.
Correct Answer: c) Natural sorting order
Explanation:
A TreeSet stores elements in sorted order according to their natural ordering or a custom Comparator.
Correct Answer: a) try-catch
Explanation:
The try-catch block structure is used to catch and handle runtime exceptions gracefully.
Correct Answer: c) null
Explanation:
Uninitialized instance and class reference variables default to null.
Correct Answer: c) Postfix increment/decrement (++ / --)
Explanation:
Postfix operators have very high precedence compared to binary arithmetic, logical, or assignment operators.
Correct Answer: a) To exit the loop or switch block entirely.
Explanation:
A break statement stops execution from falling through to subsequent case labels in a switch statement.
Correct Answer: b) FileWriter
Explanation:
FileWriter is a convenience class for writing character data to files.
Correct Answer: c) _myVar1
Explanation:
Identifiers can begin with letters, currency symbols, or underscores (_), but cannot start with digits or keywords.
Correct Answer: b) To automatically free memory occupied by unreferenced objects
Explanation:
The garbage collector handles dynamic memory management by reclaiming memory from unreachable objects.
Correct Answer: b) super
Explanation:
The super keyword is used to reference members of a direct superclass.
Correct Answer: a) Java Runtime Environment
Explanation:
JRE stands for Java Runtime Environment, which contains the JVM and core libraries.
Correct Answer: a) public static void main(String[] args)
Explanation:
The standard entry point for any standalone Java application is public static void main(String[] args).
Correct Answer: b) Constructors can return a value like int or void.
Explanation:
Constructors do not have a return type, not even void.
Correct Answer: b) ||
Explanation:
The double pipe (||) represents the conditional logical OR operator.
Correct Answer: b) 8 bytes
Explanation:
A long integer is 64 bits, taking 8 bytes of memory.
Correct Answer: c) List
Explanation:
ArrayList implements the java.util.List interface.
Correct Answer: c) final
Explanation:
The final keyword prevents a variable's value from being modified after initial assignment.
Correct Answer: b) A reference to the array object is passed by value.
Explanation:
Java passes all arguments by value, which means the reference pointing to the array object is copied.
Correct Answer: b) ArrayIndexOutOfBoundsException
Explanation:
Accessing an invalid array index triggers an ArrayIndexOutOfBoundsException.
Correct Answer: b) length field
Explanation:
Arrays in Java use a public final field named length to obtain their size.
Correct Answer: c) abstract
Explanation:
An abstract class is declared using the abstract keyword.
Correct Answer: a) Hiding internal data and exposing operations via methods
Explanation:
Encapsulation wraps data and code together, restricting direct external access to fields.
Correct Answer: b) BufferedReader
Explanation:
BufferedReader buffers input for efficient reading of characters, arrays, and lines.
Correct Answer: a) Integer.parseInt()
Explanation:
Integer.parseInt() parses string input and returns a primitive int.
Correct Answer: c) protected
Explanation:
Protected members are accessible within the same package and by subclasses in other packages.
Correct Answer: b) true
Explanation:
Numeric primitive comparisons promote operands, so 10 is equal to 10.0, evaluating to true.
Correct Answer: a) clone()
Explanation:
clone() is a protected method defined in Object.
Correct Answer: b) Methods with the same name but different parameter lists within the same class
Explanation:
Method overloading occurs when multiple methods share a name but differ in their parameters.
Correct Answer: b) To execute cleanup code regardless of whether an exception occurred
Explanation:
The finally block always executes after the try-catch block completes, making it ideal for resource cleanup.
Correct Answer: b) They are shared among all instances of a class.
Explanation:
Static fields belong to the class itself rather than any specific instance.
Correct Answer: a) Compilation
Explanation:
The core pillars of OOP are Encapsulation, Inheritance, Polymorphism, and Abstraction.
Correct Answer: a) Converting a wrapper object to its corresponding primitive type
Explanation:
Unboxing is the automatic extraction of a primitive value from a wrapper object.
Correct Answer: b) final
Explanation:
A final class cannot be extended by any subclass.
Correct Answer: b) 0.0f
Explanation:
Uninitialized float fields default to 0.0f.
Correct Answer: b) java.util
Explanation:
The Collections Framework classes reside in the java.util package.
Correct Answer: b) It is invoked automatically when an object is instantiated using new.
Explanation:
Constructors run automatically during object instantiation via the new keyword.
Correct Answer: c) break
Explanation:
The break statement exits the enclosing loop immediately.
Correct Answer: b) Skips the remaining statements in the current iteration and proceeds to the next iteration
Explanation:
Continue skips the rest of the current loop iteration and moves directly to the next iteration.
Correct Answer: b) List
Explanation:
The List interface maintains element order and allows access via integer indices.
Correct Answer: c) Both a and b
Explanation:
Both int arr[] and int[] arr are syntactically valid array declarations in Java.
Correct Answer: b) 3.0
Explanation:
Math.floor() returns the largest double value less than or equal to the argument.
Correct Answer: c) static final
Explanation:
Constants in Java are typically defined using static final.
Correct Answer: b) String is immutable, StringBuffer is mutable.
Explanation:
String objects cannot be changed after creation, whereas StringBuffer objects can be modified.
Correct Answer: b) Integer
Explanation:
Integer is the wrapper class for primitive int.
Correct Answer: c) 0 to 65535
Explanation:
A char in Java is 16 bits unsigned, representing Unicode characters from 0 to 65535.
Correct Answer: b) size()
Explanation:
The size() method returns the number of key-value mappings in a map.
Correct Answer: b) &
Explanation:
The single ampersand (&) is used for bitwise AND operations.
Correct Answer: a) Java Virtual Machine
Explanation:
JVM stands for Java Virtual Machine.
Correct Answer: c) StringBuffer
Explanation:
StringBuffer methods are synchronized, making it thread-safe, unlike StringBuilder.
Correct Answer: d) All of the above
Explanation:
Java accepts array brackets placement flexibility and varargs for the main method signature.
Correct Answer: b) boolean
Explanation:
The equals() method returns true if objects match content, and false otherwise.
Correct Answer: b) new
Explanation:
The new keyword allocates memory and invokes the constructor to create an object.
Correct Answer: a) double d = 45.50;
Explanation:
Literal floating-point numbers default to double type in Java.
Correct Answer: b) Runtime error: NoSuchMethodError: main
Explanation:
The compiler accepts classes without main, but the JVM throws a NoSuchMethodError when execution starts.
Correct Answer: b) super()
Explanation:
super() calls the constructor of the immediate superclass.
Correct Answer: a) java.util.concurrent
Explanation:
Advanced concurrency utilities are located in java.util.concurrent.
Correct Answer: a) Defining a method in a subclass with the same signature as in its superclass
Explanation:
Method overriding allows a subclass to provide a specific implementation of a method defined in its superclass.
Correct Answer: c) //
Explanation:
Double slashes (//) designate single-line comments.
Correct Answer: b) Stack
Explanation:
A Stack operates on a LIFO principle.
Correct Answer: b) To declare a method signature without a body, forcing subclasses to implement it
Explanation:
Abstract methods lack bodies and mandate implementation in non-abstract subclasses.
Correct Answer: a) final int MAX = 100;
Explanation:
The final keyword makes the integer variable unassignable after initial assignment.
Related Posts

C++ Variables & Data Types MCQs
Variables and data types form the core building blocks of any C++ application, defining how data is stored, represented, and…
October 19, 2026By MCQs Generator

Python Tuples & Sets MCQs
Python tuples and sets are fundamental built-in data structures used to store collections of items with distinct characteristics. Tuples are…
October 19, 2026By MCQs Generator

Java Exception Handling MCQs
Java exception handling is a powerful mechanism designed to manage runtime errors and maintain normal application flow. It relies on…
October 19, 2026By MCQs Generator
Related Categories

AI & Data Science MCQ
5 topics
By MCQs Generator

Arts & Humanities MCQ
4 topics
By MCQs Generator

Civil Engineering MCQ
4 topics
By MCQs Generator

Commerce & Business MCQ
4 topics
By MCQs Generator

Competitive Exams MCQ
5 topics
By MCQs Generator

Electrical & Electronics Engineering MCQ
3 topics
By MCQs Generator

General Knowledge MCQ
2 topics
By MCQs Generator

General Science MCQ
4 topics
By MCQs Generator

Law & Judiciary MCQ
3 topics
By MCQs Generator

Mechanical Engineering MCQ
4 topics
By MCQs Generator

Medical & Health Sciences MCQ
4 topics
By MCQs Generator

Modern Tech Fields MCQ
3 topics
By MCQs Generator