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

Multiple choice
  1. Peek() method retrieves and removes the head of the queue and returns null if the queue is empty.

  2. Peek() method retrieves and removes the head of the queue and returns nothing if the queue is empty.

  3. Peek() method retrieves but doesn’t remove the head of the queue and returns null if the queue is empty.

  4. Peek() method retrieves and removes the head of the queue and throws exception if the queue is empty.

  5. Peek() method retrieves but doesn’t remove the head of the queue and throws exception if the queue is empty.

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. WindowMoved()

  2. WindowClosing()

  3. WindowIconified()

  4. WindowActivated()

  5. WindowDeiconified()

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. The init() method can be called only once.

  2. The init() method can be overriden.

  3. The init() method can not throw any exception.

  4. The destroy() method ensures that the persistent state is synchronised.

  5. None of these

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The init() method throw servlet exception when the servlet container cannot place the servlet into the service.

Multiple choice
  1. 16

  2. 4

  3. 18

  4. 3

  5. 15

Reveal answer Fill a bubble to check yourself
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.