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. Comparator is present in java.Util package and Comparable is present in java.lang Package.

  2. Comparator consists of int Compare(Object o1, Object o2)and Comparable consists of int CompareTo(Object o).

  3. In case of Comparable Sorting, logic must be in the same class whose objects are to be sorted whereas in case of Comparator sorting, logic is in separate class.

  4. All of the above.

  5. None of these

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

All the statements are true.

Multiple choice
  1. ListIterator can iterate in backward direction whereas Iterator cannot.

  2. ListIterator can get index at any point while Iterator cannot.

  3. ListIterator can add a value at any point while Iterator cannot.

  4. All of the above

  5. None of these

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

All the three points are the differences between iterator and ListIterator.

Multiple choice
  1. Calling the SetPriority() method on a Thread object.

  2. Calling the wait() method on an object.

  3. Calling notify() method on an object.

  4. Calling read() method on an InputStream object.

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

Option 3 is correct. notify() - wakes up a single thread that is waiting on this object's monitor.

Multiple choice
  1. 1, 2, 4

  2. 2, 4, 5

  3. 1, 2, 6

  4. 2, 3, 4

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

(1), (2), and (6) are correct. They are all related to the list of threads waiting on the specified object. (3), (5), (7), and (8) are incorrect answers. The methods isInterrupted() andinterrupt() are instance methods of Thread. The methods sleep() and yield() are static methods of Thread. D is incorrect because synchronized is a keyword and the synchronized() construct is part of the Java language.

Multiple choice
  1. run();

  2. construct();

  3. start();

  4. register();

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

Option 3 is correct. The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread. Option 1 is wrong. The run() method of a thread is like the main() method to an application. Starting the thread causes the object's run method to be called in that separately executing thread. Option 2 is wrong. There is no construct() method in the Thread class. Option 4 is wrong. There is no register() method in the Thread class.

Multiple choice
  1. after line 5

  2. after line 6

  3. after line 7

  4. There is no way to be absolutely certain.

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

In Java, objects become eligible for garbage collection when they are no longer reachable through any reference chain. After line 5 (b = null), object B is not directly reachable. However, if the call a.s(b) on line 4 stored a reference to b inside object a, then B would still be reachable through a until line 6. Without seeing the code for class A and method s(), we cannot be certain whether B is referenced internally by A. Therefore, absolute certainty is impossible.

Multiple choice
  1. append(Printable painter, PageFormat page)

  2. getNumberOfPages()

  3. getPageFormat(int pageIndex)

  4. setPage(int pageIndex, Printable painter, PageFormat page)

  5. readPage(int PageIndex)

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

This is the correct choice because there is no method named readPage(int PageIndex) present in the book class.