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
-
read(byte[ ] b)
-
mark(int limit)
-
read()
-
both 1 and 2
-
all of these
E
Correct answer
Explanation
All of the methods are defined in the InputStream class. So this is the correct choice.
-
flush()
-
write(byte[ ] b)
-
write(byte[ ] b, int offset, int len) :-
-
both 1 and 2
-
all of these
E
Correct answer
Explanation
This is the correct answer because all of the given methods are defined in the OutputStream class.
-
skip(long)
-
mark(int limit)
-
reset()
-
both 1 and 2
-
all of these
E
Correct answer
Explanation
All of the methods are defined in the Reader class. So this is the correct choice.
-
CharWriter
-
StringWriter
-
BufferedWriter
-
Both 1 and 2
-
Both 1 and 3
A
Correct answer
Explanation
This is the correct answer. There is no Subclass named CharWriter. The correct name is CharArrayWriter, which is used for writing to a char array. So this is the correct answer according to the question.
-
StringReader
-
PipeReader
-
InputReader
-
Both 1 and 2
-
Both 1 and 3
C
Correct answer
Explanation
There is no subclass of Reader class named InputReader. The correct name is InputStreamReader used for reading a character stream. So this is the correct answer according to the question.
-
getPath()
-
getName()
-
length()
-
both 1 and 2
-
all of these
E
Correct answer
Explanation
All of the given methods are defined in the File class. So this is the correct answer.
-
StrinBufferedInputStream
-
FilterInputStream
-
SequenceInputStream
-
Both 2 and 3
-
All of these
D
Correct answer
Explanation
Both the classes in option 2 and 3 are the only subclasses of InputStream class. So this is the correct answer.
-
GET
-
PUT
-
POST
-
None of these
C
Correct answer
Explanation
The POST method sends data in the HTTP request body, not the URL. This allows much larger data transfers (no theoretical limit, practically up to server's post_max_size setting, often 8MB+), making it suitable for file uploads and long forms.
-
hashCode()
-
hashNext()
-
Next()
-
AllRetain()
-
ensureCapacity()
A
Correct answer
Explanation
This is the correct answer.
-
IllegalArgumentException
-
NullPointerException
-
IOException
-
IndexOutOfBoundException
-
ArithmeticException
C
Correct answer
Explanation
IOException is not a subclass of RuntimeException class.
-
subList(int startindex, int endindex)
-
previousIndex()
-
nextIndex()
-
hasPrevious()
-
hasMiddle()
A
Correct answer
Explanation
This is the correct answer.
-
trimToSize()
-
setElement(index,Element)
-
Seach()
-
Empty()
-
Remove()
A
Correct answer
Explanation
This is the correct answer.
-
Element() method retrieves and removes the head of the queue and returns Null if the queue is empty.
-
Element() method retrieves, but doesn’t remove the head of the queue and returns Null if the queue is empty.
-
Element() method retrieves and removes the head of the queue and throws exception if the queue is empty.
-
Element() method retrieves, but doesn’t remove the head of the queue and throws exception if the queue is empty.
-
Element() method removes the head of the queue and throws exception if the queue is empty.
D
Correct answer
Explanation
This is the correct answer.
-
Poll() method retrieves and removes the head of the queue or returns Null if the queue is empty.
-
Remove() method retrieves and removes the head of the queue or returns Null if the queue is empty.
-
Poll() method retrieves and removes the head of the queue or throws an exception if the queue is empty.
-
Remove() method retrieves and removes the head of the queue, but doesn’t return anything if the queue is empty.
-
Poll() method retrieves the head of the queue or returns Null if the queue is empty.
A
Correct answer
Explanation
This is the correct choice.
-
Peek() method retrieves and removes the head of the queue and returns Null if the queue is empty.
-
Peek() method retrieves and removes the head of the queue and returns nothing if the queue is empty.
-
Peek() method retrieves, but doesn’t remove the head of the queue and returns Null if the queue is empty.
-
Peek() method retrieves and removes the head of the queue and throws an exception if the queue is empty.
-
Peek() method retrieves, but doesn’t remove the head of the queue and throws an exception if the queue is empty.
C
Correct answer
Explanation
This is the correct answer.