Computer Knowledge
Java Core Classes and Threads
1,473 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 (3)
-
All of the above
E
Correct answer
Explanation
As explained all of the methods are defined in the Input Stream class. So, this is the correct choice.
B
Correct answer
Explanation
This is the correct answer. There are 7 subclasses of the InputStream class.
These are:
- FileInputStream for reading bytes from a file.
- ObjectInputStream for readin objects and primitive data types from input stream.
- SequenceInputStream for readin from a sequence of streams.
- ByteArrayInputStream for Stream that reads a byte array.
- pipedInputStream for reading from a piped stream.
- FilterInputStream for filtering input from Existing Stream.
- StringBufferInputStream for reading from a string.
C
Correct answer
Explanation
There five subclasses of the OutputStream class are:
- FileOutputStream for writing bytes into file
- ObjectOutputStream for writing objects and primitive data types to output stream.
- ByteArrayOutputStream for output stream that writes byte into array.
- pipedOutputStream for writing into a piped stream.
- FilterOutputStream for filtering output into an existing stream.
So, this is the correct answer.
-
flush()
-
write(byte[ ] b)
-
write(byte[ ] b , int offset, int len)
-
Both (1) and (3)
-
All of the above
E
Correct answer
Explanation
This is the correct answer because as explained, all of the given methods are defined in the OutputStream class.
D
Correct answer
Explanation
This is the correct answer. Byte stream can be defined by using two class hierarchies.
These two classes are :
- InputStream
- OutputStream
C
Correct answer
Explanation
This is the correct answer. Character stream class is defined by using two class hierarchies.
These classes are:
- Reader class
- Writer class.
-
skip(long)
-
mark(int limit)
-
reset()
-
Both (1) and (3)
-
All of the above
E
Correct answer
Explanation
As explained, all of the methods are defined in the Reader class. So, this is the correct choice.
-
ObjectOutputStream
-
PipedOutputStream
-
ByteOutputStream
-
Both (1) and (2)
-
All of the above
D
Correct answer
Explanation
As explained, both options 1 and 2 are correct. 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.
-
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 the above
E
Correct answer
Explanation
As explained that all of the given methods are defined in the File class. So, this is the correct answer.
D
Correct answer
Explanation
There are 6 subclasses of reader Class in Java. These are:
- BufferedReader for buffering other readers
- ChararrayReader for reading from char array
- FilterReader for reading filter streams
- InputStreamReader for reading a character stream
- PipedReader for reading from pipe
- StringReader for reading from a string
So, this is the correct answer.
-
StrinBufferedInputStream
-
FilterInputStream
-
SequenceInputStream
-
Both (2) and (3)
-
All of the above
D
Correct answer
Explanation
As explained, both the classes in option 2 and 3 are the only subclasses of the InputStream class. So, this is the correct answer.
A
Correct answer
Explanation
There are 7 subclasses of the Writer class in Java.
These are:
- OutputStreamWrite for writing a character stream
- BufferedWriter for buffering other writers
- PrintWriter for writing formatted data
- PipedWriter for writing to a pipe
- CharArrayWriter for writing to a char array
- StringWriter for writing to a string
- FilterWriter for writing filtered streams.
So, this is the correct answer.
-
toLower()
-
trim()
-
split()
-
Both (1) and (3)
-
Both (2) and (3)
A
Correct answer
Explanation
This is the correct answer. Because there is no method defined in the String class named toLower(). So it cannot be invoked using the object of String class. The correct method is toLowerCase() which converts the characters to lowercase.