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 technology programming languages
  1. Yes

  2. No

  3. May be

  4. I don't know

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

When a StackOverflowException occurs, the process is terminated immediately because the stack is corrupted. Unlike most exceptions, finally blocks do NOT execute for StackOverflowException. This is because there's no stack space left to execute the finally block - the runtime cannot safely continue execution.

Multiple choice technology web technology
  1. Validator

  2. Converters

  3. Exception handler

  4. Event listeners

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

JSF provides validators for input validation, converters for type conversion between strings and objects, and event listeners for handling component events. Exception handling in JSF is typically managed through error-page configuration and custom exception factory rather than being a first-class framework-provided component.

Multiple choice technology programming languages
  1. nothing happen, excution will continue.

  2. it will be handled by compiler, and excution stops.

  3. the exception will be rethrown

  4. terminate() function will be called and execution stops.

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

When an exception is thrown and not caught by any handler, C++ calls std::terminate(). This function typically calls std::abort(), which immediately stops program execution. This prevents undefined behavior from propagating.

Multiple choice technology programming languages
  1. Line 46 will compile if the enclosing method throws a TestException.

  2. Class A will not compile.

  3. Line 46 will compile if enclosed in a try block, where TestException is caught

  4. Line 45 can throw the unchecked exception TestException.

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

TestException is a checked exception (extends Exception). Line 46 calls a method that throws TestException, so it must either: (A) be in a method that declares throws TestException, or (C) be wrapped in a try-catch block. Option A is true - if the enclosing method throws TestException, line 46 compiles. Option C is true - try-catch handles it. Option D is false because TestException is checked, not unchecked.

Multiple choice technology programming languages
  1. Extend the java.lang.Throwable class

  2. Extend the java.lang.Thread class

  3. Extend the java.lang.Runnable

  4. Implement the Runnable interface

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

Threads in Java can be created by extending the Thread class and overriding its run() method, or by implementing the Runnable interface and passing an instance to a Thread constructor. Runnable is an interface (not a class), so you implement it, not extend it. Throwable is for exceptions, not threads.

Multiple choice technology programming languages
  1. Thread class

  2. Runnable Interface

  3. Applet

  4. Throwable

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

The run() method is defined as an abstract method in the java.lang.Runnable interface to represent a task's entry point. The java.lang.Thread class implements Runnable and provides a concrete implementation of run(). Neither Applet nor Throwable declares the run() method as part of their standard contracts.

Multiple choice technology programming languages
  1. A thread gets a default priority

  2. cause the currently running thread to move back to runnable so that a thread of the same priority can have a chance.

  3. Guaranteed to cause the current thread to stop executing for at least the specified sleep duration

  4. Guaranteed to cause the current thread to stop executing until the thread it joins with completes

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

join() makes the current thread wait until the specified thread completes execution. The other options describe priority behavior (A), yielding (B), and sleep behavior (C) - none match join()

Multiple choice technology programming languages
  1. A thread can acquire more than one lock

  2. Each object has just one lock.

  3. all methods in a class must be synchronized

  4. methods,variables can be synchronized,

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

In Java synchronization, a single thread can acquire multiple locks concurrently, and every object is associated with exactly one monitor lock. It is incorrect to claim that all class methods must be synchronized, as developers selectively synchronize code. Variables cannot be synchronized directly; only methods and blocks can use the synchronized keyword.

Multiple choice technology
  1. (a) Activity-End

  2. (b) End-Activity

  3. (c) Exit-Activity

  4. none of the above

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

The Exit-Activity method terminates the current activity and returns control to the calling activity or flow. This is the standard way to exit an activity programmatically. Activity-End and End-Activity are not valid method names in Process Commander's activity model. The Exit-Activity method properly manages the call stack and control transfer.

Multiple choice technology
  1. (a) Forward chaining

  2. (b) Backward chaining

  3. Goal Seek

  4. none of the above

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

Property-Seek-Value is the method used to invoke backward chaining in Process Commander. Backward chaining works from a goal or desired value backward to find the facts needed to satisfy that goal. When a property's value is sought using this method, the system triggers backward chaining to derive the value through dependency resolution. Forward chaining works in the opposite direction.

Multiple choice technology web technology
  1. public static void main(String[] args)

  2. public static void main()

  3. public void main(String[] args)

  4. public void static main(String[] args)

Reveal answer Fill a bubble to check yourself
A,B,C Correct answer
Explanation

Java main method must be static, but public is not strictly required (though runtime looks for public). Variations: A is standard, B is valid static main without args (compile-time valid, though JVM won't call it), C is valid non-public static main, D is invalid syntax (void must come before method name, not after).