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
-
Byte stream
-
Character stream
-
Both (1) and (2)
-
None of these
C
Correct answer
Explanation
Java supports both byte streams (InputStream/OutputStream) and character streams (Reader/Writer) for handling I/O operations.
-
Exception
-
Read Exception
-
IO Exception
-
None of these
C
Correct answer
Explanation
The read() method in the InputStream class is declared to throw an IOException because I/O operations are prone to failure.
-
File Reader
-
File Input Stream
-
File Read
-
None of these
B
Correct answer
Explanation
FileInputStream is a standard class used to read data from files in byte-oriented I/O.
-
Reader
-
Writer
-
Both (1) and (2)
-
None of these
C
Correct answer
Explanation
In Java, Reader and Writer are the abstract base classes for all character stream classes.
-
Random Access File class
-
File class
-
Output class
-
Both (1) and (3)
-
Random File
-
Random Access File
-
Acess File
-
None of these
B
Correct answer
Explanation
The class 'RandomAccessFile' in the java.io package provides the functionality to read and write to a file at random positions.
-
read()
-
readline()
-
write()
-
both (1) and (3)
B
Correct answer
Explanation
The BufferedReader class in Java provides the readLine() method to read a full line of text from an input stream, such as the keyboard (System.in). The read() method reads a single character, not a string.
-
Abstract
-
Boolean
-
Break
-
Count
D
Correct answer
Explanation
Abstract, Boolean, and Break are all reserved keywords in Java. Count is not a reserved keyword.
-
Yes
-
No
-
Both (1) and (2)
-
None of these
B
Correct answer
Explanation
Java objects are references to memory locations, not pointers in the C/C++ sense. Java does not allow direct pointer arithmetic.
-
SubList (int startindex, int endindex)
-
PreviousIndex()
-
NextIndex()
-
HasPrevious()
-
HasMiddle()
A
Correct answer
Explanation
This is the correct answer. SubList() method is present in the List Interface and it returns a sublist from the startindex to the endindex. So, this is the correct answer.
-
HashCode()
-
HasNext()
-
Next()
-
AllRetain()
-
EnsureCapacity()
A
Correct answer
Explanation
This is the correct answer. Hashcode() method is present in the Collection Interface. This function returns the hashcode for the collection. The hashcode of two objects must be same if the two objects are equal. So this is the correct answer.
-
TrimToSize()
-
SetElement(index,Element)
-
Seach()
-
Empty()
-
Remove()
A
Correct answer
Explanation
This is the correct answer. TrimToSize() method is present in the vector class and it trims the capacity of the vector to its size. So, this is the correct answer.
-
IllegalArgumentException
-
NullPointerException
-
IOException
-
IndexOutOfBoundException
-
ArithmeticException
C
Correct answer
Explanation
IOException is not a subclass of RuntimeException class; this class is a subclass of exception class. This exception is thrown when invalid input/output are given. So, this is the correct answer as this is not a subclass of RuntimeException class.
-
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 throw 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 because element() method retrieves, but doesn’t remove the head of the queue and throw exception if the queue is empty. So, this is correct choice.
-
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 because the poll() method present in the queue retrieves and removes the head of the queue or returns null if the queue is empty. So, this is correct answer.