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. Yes

  2. No

  3. Both (1) and (2)

  4. None of these

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

Multiple choice
  1. SubList (int startindex, int endindex)

  2. PreviousIndex()

  3. NextIndex()

  4. HasPrevious()

  5. HasMiddle()

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

Multiple choice
  1. HashCode()

  2. HasNext()

  3. Next()

  4. AllRetain()

  5. EnsureCapacity()

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

Multiple choice
  1. IllegalArgumentException

  2. NullPointerException

  3. IOException

  4. IndexOutOfBoundException

  5. ArithmeticException

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

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

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

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

  4. Element() method retrieves but doesn’t remove the head of the queue and throw exception if the queue is empty.

  5. Element() method removes the head of the queue and throws exception if the queue is empty.

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

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

  2. Remove() method retrieves and removes the head of the queue or returns null if the queue is empty

  3. Poll() method retrieves and removes the head of the queue or throws an exception if the queue is empty.

  4. Remove() method retrieves and removes the head of the queue, but doesn’t return anything if the queue is empty.

  5. Poll() method retrieves the head of the queue or returns null if the queue is empty.

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