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. It is an instance method of Object class.

  2. It is a static method of the Object class

  3. It is an instance method of Thread class.

  4. The Thread must have a lock on the object on which the wait() method is to be invoked

  5. An object can have only one Thread in a waiting state at a time

  6. It must be called in a synchronized code

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

wait() is an instance method of Object class (A), must be called in synchronized context (F), and requires the calling thread to hold the object's lock (D). It's not static (B), not in Thread class (C), and multiple threads can wait on the same object (E). Three options are correct.

Multiple choice technology programming languages
  1. Static methods cannot be synchronized

  2. Synchronized methods cannot make calls to non-synchronized methods

  3. A synchronized method can be overridden to be non-synchronized and vice versa

  4. When a thread is executing a synchronized method, other threads can freely access non-synchronized methods of the same object

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

In Java, synchronized methods can be overridden to be non-synchronized (and vice versa) because synchronization is a property of the implementation, not the method signature. Additionally, while a thread holds a lock on a synchronized method, other threads can freely access non-synchronized methods.

Multiple choice technology programming languages
  1. Null Pointer Exception at client side

  2. Client will receive warning message

  3. ConnectException is thrown

  4. Compilation Error

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

When a client attempts to connect to a server that is not running, Java throws a ConnectException. This is a runtime exception indicating the connection was refused because no server is listening at the specified host and port.

Multiple choice technology programming languages
  1. final

  2. transient

  3. public

  4. private

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

The transient modifier in Java tells the JVM to skip that field during serialization - it won't be written to the persistent stream. This is useful for fields that can be recalculated, are derived from other data, contain sensitive information, or reference non-serializable objects.

Multiple choice technology programming languages
  1. Its return type is String

  2. It reads the password from the console

  3. It has echoing disabled

  4. It takes a single argument

  5. None of them

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

Console.readPassword() reads password input from the console with echoing disabled (characters don't appear on screen). It returns char[] not String for security (can be cleared from memory).

Multiple choice technology platforms and products
  1. Object Handle

  2. Size of the buffer assigned to hold the message

  3. Length of application data in message

  4. Connection Handle

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

MQGET API requires input parameters: Object Handle (Hobj), Buffer (to receive message), Buffer Length (size of buffer), and Connection Handle (Hconn). The 'Length of application data in message' is an OUTPUT parameter (returned in the DataLength field) that tells you how much data was actually retrieved, not an input you provide.

Multiple choice technology platforms and products
  1. Connection Handle

  2. Object Handle

  3. Reason Code

  4. Completion Code

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

MQCMIT API commits all operations within the current unit of work. Its parameters are: Connection Handle (Hconn), Completion Code (CompCode), and Reason Code (Reason). Object Handle (Hobj) is NOT a parameter for MQCMIT because commit operations work at the connection/transaction level, not on individual queue objects.

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

  2. public static void main(String heyhey[])

  3. public static int main(String[] args)

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

  5. public static void main (String [], int argv)

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

Valid main method signatures must be public static void with a single String array or varargs parameter. Modifier order (static public vs public static) is flexible. Parameter names can be any valid identifier. Return type must be void, and only one String array/varargs parameter is allowed.

Multiple choice technology programming languages
  1. all sub-classes of Throwable

  2. not the sub classes of RuntimeException

  3. all sub-classes of Error

  4. None of these

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

In Java, checked exceptions are subclasses of Exception but are not subclasses of RuntimeException. Subclasses of Error and RuntimeException are unchecked.