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

Multiple choice
  1. ClassNotFoundException

  2. ClassNotSupportedException

  3. InstantiationException

  4. UnsupportedOperationException

  5. NoSuchMethodException

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

This is the correct answer. This is an unchecked exception. This occurs when an unsupported action gets encountered.

Multiple choice
  1. It is sometimes good practice to throw an AssertionError explicitly.

  2. Private getter() and setter() methods should not use assertions to verify arguments.

  3. If an AssertionError is thrown in a try-catch block, the finally block will be bypassed.

  4. It is proper to handle assertion statement failures using a catch (AssertionException ae) block.

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

Option 1 is correct because it is sometimes advisable to thrown an assertion error even if assertions have been disabled. Option 2 is incorrect because it is considered appropriate to check argument values in private methods using assertions. Option 3 is incorrect; finally is never bypassed. Option 4 is incorrect because AssertionErrors should never be handled.

Multiple choice
  1. new Runnable(MyRunnable).start();

  2. new Thread(MyRunnable).run();

  3. new Thread(new MyRunnable()).start();

  4. new MyRunnable().start();

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

Because the class implements Runnable, an instance of it has to be passed to theThread constructor, and then the instance of the Thread has to be started. 1 is incorrect. There is no constructor like this for Runnable because Runnable is an interface, and it is illegal to pass a class or interface name to any constructor. 2 is incorrect for the same reason; you can't pass a class or interface name to any constructor. 4 is incorrect because MyRunnable doesn't have a start() method, and the onlystart() method that can start a thread of execution is the start() in the Threadclass.