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
-
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.
-
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 exception if the queue is empty.
-
Peek() method retrieves but doesn’t remove the head of the queue and throws exception if the queue is empty.
C
Correct answer
Explanation
This is the correct answer because peek() method retrieves but doesn’t remove the head of the queue and returns null if the queue is empty. So, this is the correct answer.
-
WindowMoved()
-
WindowClosing()
-
WindowIconified()
-
WindowActivated()
-
WindowDeiconified()
A
Correct answer
Explanation
If a class implements an interface then it is necessary for that class to define body to all the methods defined in the interface it is implementing. But windowMoved() method is not present in WindowListener interface. So, when a class will implement this interface, this method need not be defined in the class. So this option is correct.
-
IndexOf(Element : e)
-
Set(index,element)
-
Get(index)
-
Remove(index)
-
None of these
E
Correct answer
Explanation
As all the methods are present in the List interface, so this is the correct answer.
-
RetainAll(collection c)
-
ToArray()
-
ContainsAll()
-
AddAll(Collection c)
-
First()
E
Correct answer
Explanation
First() method is present in sortedSet interface and not in collection interface. So this is the correct choice as this method is not present in the collection interface.
-
This method accepts only a single argument.
-
This method can accept multiple arguments.
-
It returns the an array of integers containing all the values for the parameter.
-
It provides thread-safety to the applications.
-
This method is used to set the bean's values.
-
public void resetBuffer()
-
public void rest()
-
public void getBuffer()
-
public void setBufferSize()
-
None of these
B
Correct answer
Explanation
This method is used to clear the buffer content, status code and headers.
-
public java.util.Enumeration getLocales()
-
public java.util.Locale getLocale()
-
Both (1) and (2)
-
public java.util.Locales getLocale()
-
None of these
A
Correct answer
Explanation
This method returns the preferred locale for the content that the client will accept.
-
The init() method can be called only once.
-
The init() method can be overriden.
-
The init() method can not throw any exception.
-
The destroy() method ensures that the persistent state is synchronised.
-
None of these
C
Correct answer
Explanation
The init() method throw servlet exception when the servlet container cannot place the servlet into the service.
-
replace(char, char)
-
replaceAll(String, String)
-
append(String)
-
Both the options 1 and 2
-
All of these
A
Correct answer
Explanation
The correct answer is 16. When stringbuffer object is created the default capacity of the object is always 16. If the number of characters in the string increases the capacity will increase with the following formula-
2 * (previous capacity + 1). In this case hello has 5 characters, so default capacity will not change.
-
isDigit()
-
isLetter()
-
isLetterOrDigit()
-
All of these
-
None of these
D
Correct answer
Explanation
Yes, it is correct answer.
-
valueOf()
-
toCharArray()
-
toIntArray()
-
Both the options 1 and 2
-
Both the options 1 and 3
D
Correct answer
Explanation
This is the correct answer.