Who developed the Java programming language?
- A
James Gosling
- B
Dennis Ritchie
- C
Bjarne Stroustrup
- D
Guido van Rossum
Master Java programming with 120+ curated MCQs covering OOP, collections, multithreading, streams, and more. Perfect for exams, interviews, and placement preparation.
Who developed the Java programming language?
James Gosling
Dennis Ritchie
Bjarne Stroustrup
Guido van Rossum
In which year was Java first released?
1991
1995
1997
2000
What is the original name of Java?
Oak
Green
Java
Coffee
Which company originally developed Java?
Microsoft
IBM
Sun Microsystems
Oracle
What is the latest LTS version of Java as of 2026?
Java 17
Java 21
Java 22
Java 23
What is the extension of Java bytecode files?
.java
.class
.jar
.jvm
Which of the following is not a primitive data type in Java?
int
float
String
boolean
What is the size of an int in Java?
8 bits
16 bits
32 bits
64 bits
Which data type is used for single characters in Java?
char
String
Character
byte
What is the default value of a boolean in Java?
true
false
null
0
Which keyword is used to define a constant in Java?
const
final
static
constant
What is the range of the short data type in Java?
-128 to 127
-32768 to 32767
-2147483648 to 2147483647
0 to 65535
What is the result of 5 % 2 in Java?
2
1
0
2.5
Which operator is used for logical AND in Java?
&
&&
|
||
What is the output of: System.out.println(10 / 3);
3.33
3
3.0
4
Which operator is used for type comparison in Java?
instanceof
typeof
getClass
is
What is the associativity of the assignment operator (=) in Java?
Left to right
Right to left
Both
None
What does the 'instanceof' operator check?
Whether an object is an instance of a specific class
The size of an object
The memory address of an object
The class name of an object
Which statement is used to exit a loop prematurely in Java?
break
continue
return
exit
What is the output of: int x = 10; if(x > 10) System.out.println('Yes'); else System.out.println('No');
Yes
No
Error
None
Which loop is guaranteed to execute at least once in Java?
for
while
do-while
All of these
What is the use of the 'switch' statement in Java?
To implement multi-way branching
To loop until a condition is met
To define a method
To declare variables
Can the 'switch' statement in Java use String values?
Yes, from Java 7 onwards
No
Only in Java 8
Only with numbers
What is the output of: for(int i=0;i<3;i++) System.out.print(i);
012
0123
123
No output
What is encapsulation in Java?
Wrapping data and methods into a single unit
Creating multiple methods with the same name
Inheriting properties from parent class
Hiding implementation details
Which keyword is used to inherit a class in Java?
extends
implements
inherits
super
What is polymorphism in Java?
Ability to take many forms
Creating multiple objects
Defining multiple constructors
Using interfaces
Which keyword is used to access parent class members in Java?
super
this
parent
base
What is method overloading in Java?
Multiple methods with same name but different parameters
Multiple methods with same name and same parameters
Methods in different classes
Methods with different return types
What is method overriding in Java?
Redefining a method in child class
Defining multiple methods
Calling a method from parent
Using abstract methods
What is an abstract class in Java?
A class that cannot be instantiated
A class with only static methods
A class with private constructors
A class without any methods
What is an interface in Java?
A blueprint for classes that defines abstract methods
A concrete class
A method signature
A package
Which index is used to access the first element of an array in Java?
1
0
-1
Any
What is the correct syntax to declare an array in Java?
int[] arr;
int arr[];
Both A and B
array int arr;
What is the output of: int[] arr = {1,2,3}; System.out.println(arr[2]);
1
2
3
Error
How do you get the length of an array in Java?
arr.length
arr.size()
arr.length()
len(arr)
Which of the following correctly declares a 2D array in Java?
int[][] arr = new int[3][4];
int arr[][] = new int[3][4];
Both A and B
int arr[3][4];
What happens when you try to access arr[5] in int[] arr = new int[5];
Returns null
Throws ArrayIndexOutOfBoundsException
Returns 0
Compilation error
Are strings mutable in Java?
Yes
No
Only if using StringBuilder
Only in Java 8
Which class is used to create mutable strings in Java?
String
StringBuilder
StringBuffer
Both B and C
What is the output of: 'Hello'.concat('World');
HelloWorld
Hello World
Hello
World
How do you get the length of a String in Java?
str.length
str.length()
str.size()
len(str)
What is the difference between String and StringBuilder?
String is immutable, StringBuilder is mutable
String is mutable, StringBuilder is immutable
Both are immutable
Both are mutable
Which method is used to compare strings ignoring case in Java?
equalsIgnoreCase()
compareToIgnoreCase()
Both A and B
equals()
Which interface is the root of the Java Collection Framework?
List
Set
Collection
Map
Which collection allows duplicate elements?
Set
List
Map
Queue
What is the difference between ArrayList and LinkedList?
ArrayList is faster for random access, LinkedList for insertion/deletion
LinkedList is faster for random access
ArrayList is faster for insertion/deletion
No difference
Which collection does not allow null values?
ArrayList
HashSet
TreeSet
LinkedList
What is the difference between HashMap and TreeMap?
HashMap is unsorted, TreeMap is sorted
TreeMap is unsorted, HashMap is sorted
Both are sorted
Both are unsorted
Which interface represents a key-value pair collection?
List
Set
Map
Queue
Which keyword is used to handle exceptions in Java?
try
catch
finally
All of these
What is the parent class of all exceptions in Java?
Exception
Throwable
Error
RuntimeException
What is the difference between checked and unchecked exceptions?
Checked exceptions are checked at compile time, unchecked at runtime
Unchecked exceptions are checked at compile time
Both are checked at compile time
Both are checked at runtime
Which keyword is used to throw an exception explicitly?
throw
throws
try
catch
What is the purpose of the 'finally' block?
To execute code regardless of exception
To catch exceptions
To throw exceptions
To handle exceptions
Which of the following is a checked exception?
NullPointerException
ArrayIndexOutOfBoundsException
IOException
ArithmeticException
Which keyword is used for synchronization in Java?
synchronized
volatile
atomic
lock
How can you create a thread in Java?
Extend Thread class
Implement Runnable interface
Both A and B
Use ThreadFactory
What is the difference between sleep() and wait() in Java?
sleep() is for Thread, wait() is for Object
sleep() releases lock, wait() doesn't
Both release lock
Both are for Thread
Which method is used to start a thread in Java?
run()
start()
execute()
begin()
What is the 'volatile' keyword used for in Java?
To ensure visibility of changes to variables across threads
To make a variable read-only
To declare a static variable
To initialize a variable
What is a deadlock in Java?
Two or more threads are waiting forever for each other to release resources
A thread is waiting for its own lock
Threads are executing simultaneously
Threads are paused
Which package contains file I/O classes in Java?
java.io
java.nio
java.file
Both A and B
Which class is used to read text files in Java?
FileReader
BufferedReader
Both A and B
FileInputStream
Which class is used to write text files in Java?
FileWriter
BufferedWriter
Both A and B
FileOutputStream
What is the difference between FileReader and FileInputStream?
FileReader reads character data, FileInputStream reads byte data
FileReader reads byte data, FileInputStream reads character data
Both read character data
Both read byte data
Which method is used to read a line from a file in Java?
readLine()
read()
getLine()
nextLine()
What is the purpose of the 'try-with-resources' statement?
To automatically close resources
To handle exceptions
To define resources
To open files
Which Java version introduced Lambda expressions?
Java 7
Java 8
Java 9
Java 11
What is the syntax of a lambda expression?
(parameters) -> expression
(parameters) => expression
parameters -> expression
function(parameters) -> expression
What is a functional interface in Java?
An interface with a single abstract method
An interface with multiple abstract methods
An interface with no methods
An interface with default methods
What is the purpose of the Stream API in Java?
To perform functional operations on collections
To create new collections
To iterate over arrays
To write to files
What is the difference between map() and flatMap() in streams?
map() returns a stream, flatMap() flattens nested streams
flatMap() returns a stream, map() flattens nested streams
Both flatten nested streams
Both return streams
Which annotation is used to mark a functional interface?
@FunctionalInterface
@Functional
@Interface
@Lambda
What does JDBC stand for?
Java Database Connectivity
Java Database Connection
Java Data Base Connection
Java Database Controller
Which class is used to load a JDBC driver?
Class.forName()
DriverManager.getDriver()
Driver.load()
JDBC.load()
Which interface is used to execute SQL queries in JDBC?
Statement
PreparedStatement
CallableStatement
All of these
What is the difference between Statement and PreparedStatement?
PreparedStatement prevents SQL injection
Statement prevents SQL injection
Both prevent SQL injection
Neither prevents SQL injection
Which method is used to execute a SELECT query in JDBC?
executeQuery()
executeUpdate()
execute()
runQuery()
What is the purpose of the ResultSet interface?
To store and navigate query results
To execute queries
To connect to databases
To close connections
What is the purpose of generics in Java?
To provide compile-time type safety
To improve performance
To reduce code
To create objects
What is the syntax for a generic class?
class MyClass<T>
class MyClass[T]
class MyClass(T)
generic class MyClass<T>
What is a bounded type parameter in generics?
A type parameter that extends a specific class
A type parameter with no bounds
A type parameter for primitive types
A type parameter for arrays
What is the wildcard in generics?
An unknown type represented by ?
A specific type
A primitive type
A void type
Can you create a generic array in Java?
No, due to type erasure
Yes, using T[]
Yes, using generic arrays
Only with ArrayList
What is type erasure in Java?
Removing generic type information at compile time
Removing class information
Removing method information
Removing variable information
What is the purpose of annotations in Java?
To provide metadata about the code
To execute code
To create objects
To declare variables
Which annotation is used to override a method?
@Override
@OverrideMethod
@Overrides
@Super
Which annotation is used to indicate that a method is deprecated?
@Deprecated
@DeprecatedMethod
@Obsolete
@Old
What is a marker annotation in Java?
An annotation with no elements
An annotation with one element
An annotation with multiple elements
An annotation that is not used
What is the '@FunctionalInterface' annotation used for?
To mark an interface with a single abstract method
To mark a class as functional
To mark a method as functional
To create lambda expressions
What is a meta-annotation in Java?
An annotation applied to other annotations
An annotation applied to classes
An annotation applied to methods
An annotation applied to fields
What does JVM stand for?
Java Virtual Machine
Java Variable Manager
Java Version Manager
Java Visual Machine
What is garbage collection in Java?
Automatic memory management
Manual memory management
Memory allocation
Memory deallocation
Which method is called by garbage collector before reclaiming an object?
finalize()
dispose()
destroy()
clean()
What is the heap in Java?
Memory area for objects
Memory area for stack frames
Memory area for method area
Memory area for native methods
What is the stack in Java?
Memory area for method frames and local variables
Memory area for objects
Memory area for classes
Memory area for threads
What is the purpose of the 'new' keyword in Java?
To create objects
To create arrays
To allocate memory
All of these
What is reflection in Java?
Inspecting and modifying classes at runtime
Creating objects at runtime
Executing methods at runtime
All of these
What is a module in Java?
A group of related packages
A single class
A method
An interface
Which Java version introduced the module system?
Java 8
Java 9
Java 10
Java 11
What is the purpose of the 'var' keyword in Java?
Local variable type inference
Variable declaration
Constant declaration
Method declaration
What is a sealed class in Java?
A class with restricted subclasses
A class that cannot be instantiated
A class with private methods
A class with no methods
What is a record in Java?
A transparent data carrier class
A database record
A file record
A method record
What is the difference between JDK and JRE?
JDK includes development tools, JRE only runs programs
JRE includes development tools, JDK only runs programs
Both include development tools
Both only run programs
What is the wrapper class for int?
Integer
Int
int
IntWrapper
What is the output of: System.out.println(10 % 3);
3
1
0
2
Which statement is used to skip the current iteration and continue to the next?
continue
break
return
goto
What is the difference between final, finally, and finalize?
final is for constants, finally is for exception handling, finalize is for garbage collection
All are the same
final is for methods, finally is for variables
finalize is for inheritance
What is the default value for elements in an int array?
0
null
undefined
garbage value
Which method is used to convert a string to uppercase?
toUpperCase()
toUpper()
upperCase()
toUppercase()
What is the difference between HashSet and LinkedHashSet?
LinkedHashSet maintains insertion order, HashSet doesn't
HashSet maintains insertion order, LinkedHashSet doesn't
Both maintain insertion order
Neither maintains insertion order
Can we have multiple catch blocks for a single try block?
Yes
No
Only in Java 8
Only in Java 11
What is the difference between synchronized method and synchronized block?
Synchronized method locks the entire method, synchronized block locks only specified code
Synchronized block locks the entire method
Both are the same
Neither provides synchronization
What is the purpose of the 'serializable' interface?
To allow object serialization
To allow object cloning
To allow object comparison
To allow object creation
What is a terminal operation in streams?
An operation that produces a result
An operation that transforms data
An operation that filters data
An operation that sorts data
Which method is used to create a statement in JDBC?
createStatement()
getStatement()
prepareStatement()
getPreparedStatement()
What is the purpose of the 'extends' keyword in generics?
To set upper bound for type parameter
To set lower bound for type parameter
To define an interface
To create a class
What is the '@SuppressWarnings' annotation used for?
To suppress compiler warnings
To suppress runtime errors
To suppress exceptions
To suppress methods
What is the difference between heap and stack memory?
Heap stores objects, stack stores method frames and local variables
Stack stores objects, heap stores method frames
Both store objects
Neither stores objects