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
-
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.
-
Char
-
String
-
Int
-
Both the options 1 and 2
-
All of above
D
Correct answer
Explanation
Both char and string can be passed as the first parameter to the lastIndexOf() method. So, this is the correct answer.
-
Next()
-
nextLine()
-
nextInt()
-
nextChar()
-
nextLong()
D
Correct answer
Explanation
There is no function defined in Scanner class to take character input. So, there is no function named nextChar(), hence this is the correct answer.
-
Wait()
-
Destroy()
-
Dead()
-
Both the options 1 and 3
-
Both the options 1 and 2
D
Correct answer
Explanation
So, this option is correct.