Computer Knowledge
Java Core Classes and Threads
1,935 Questions
Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.
String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules
Java Core Classes and Threads Questions
-
It sorts the element in ascending order.
-
It can have null key.
-
It can not have any null keys.
-
It extends AbstractMap class.
-
None of the above
B
Correct answer
Explanation
It does not allows any null key but can have multiple null values.
-
An applet can contain main method.
-
The code of the applet can be downloaded in a user's browser if the html page contain that applet.
-
The Graphics class is used to display the output of the applet.
-
An applet can be used to fetch an image.
-
None of the above
A
Correct answer
Explanation
No, applet does not allow main method.
-
Vector is not synchronized.
-
Vector can be resized the array as needed.
-
Vector gives costlier performance as compared to ArrayList.
-
Vector is also called dynamic array.
-
None of the above
A
Correct answer
Explanation
This is a false statement as Vector is synchronized and can be used for thread safe operation.
-
By using serialization process, the state of the variable can be represented as a sequence of bytes.
-
Serialization is a platform independent process.
-
ObjectInputStream class is used to serialize or deserialize the object.
-
All of the above are true
-
Only (1) and (3) are true
D
Correct answer
Explanation
Yes, all the above three statements determines the properties of the serialization process.
-
StringBuffer is a mutable class.
-
StringBuilder is faster than StringBuffer.
-
StringBuilder is a mutable class.
-
All of the above are true
-
None of the above
D
Correct answer
Explanation
Yes, all of the above three are true.
-
We can not force garbage collection mechanism in java.
-
JVM uses finalize() method before destroy the unused objects.
-
JVM uses system.gc() method to collect the unused memory objects.
-
All the above are true
-
Option (1) and (2) only
D
Correct answer
Explanation
Yes, all of the above three a statements determines the exact explanation of the garbage collection process in java.
-
Volatile
-
Assert
-
New
-
Native
-
None of the above
E
Correct answer
Explanation
All of the above are reserve words.
-
Instance
-
Static
-
Transient
-
Both 1 and 2
-
Both 2 and 3
E
Correct answer
Explanation
if a user does not want any field to be a part of object's state, then declare it either static or transient based on his need and it will not be included during Java serialization process.
-
StringBuffer
-
ArrayList
-
HashMap
-
StringBuilder
-
String
A
Correct answer
Explanation
StringBuffer is designed to be thread safe and all public methods in StringBuffer are synchronized.
-
PrintWriter class object defined in System class
-
Bufferwriter class defined in System class
-
System class object
-
PrintStream class defined in System class
-
BufferReader class object
D
Correct answer
Explanation
It is an object PrintStream class defined in System class. 'out' is declared as public, static and final.
-
Having multi threading feature
-
Not having low level programming support
-
Having robustness
-
Not having pointers
-
Not having struct data type
B
Correct answer
Explanation
Low-level programming cannot be done directly, unlike in C.
-
Catch statement can rethrow an exception in Java.
-
Empty catch block is accepted by Java.
-
Main is a daemon thread.
-
Garbage collector is a daemon thread.
-
Garbage collector can also run forcibly.
C
Correct answer
Explanation
Main is not a daemon thread, also any thread stem from main will be non daemon because daemon is derived from parent Thread class.
-
multiple catch statements
-
single catch with exception type as Exception
-
printQueueTrace();
-
printStackTrace();
-
printLinkedlistTrace();
D
Correct answer
Explanation
All exceptions inherit a method printStackTrace() from Throwable class. Its stores all the exceptions in stack manner and prints them out, when it is called.
-
java.io.Serializable
-
java.lang.Cloneable
-
java.util.EventListener
-
Java.util.stack
-
None of the above
D
Correct answer
Explanation
Stack is not a marker interface.
-
Return statement in catch block.
-
System.exit() present in catch block.
-
Exception occurred in finally block.
-
The death of thread occurs before completion of execution.
-
Break; statement in catch block.
A
Correct answer
Explanation
Once execution enters the try block, the code in that finally block will definitely be executed.