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. After line 9

  2. After line 10

  3. After line 11

  4. Garbage collector never invoked in methodA()

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

Option D is correct. Garbage collection takes place after the method has returned its reference to the object. The method returns to line 6, there is no reference to store the return value. so garbage collection takes place after line 6. Option A is wrong. Because the reference to obj1 is stored in obj2[0]. The Object obj1still exists on the heap and can be accessed by an active thread through the reference stored in obj2[0]. Option B is wrong. Because it is only one of the references to the object obj1, the other reference is maintained in obj2[0]. Option C is wrong. The garbage collector will not be called here because a reference to the object is being maintained and returned in obj2[0].

Multiple choice
  1. An empty memory space is returned so that the developers can utilize it.

  2. void returns no data type.

  3. void is not supported in Java

  4. None of the above

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

The void keyword in Java (and C/C++) indicates that a method returns no value. It specifies the absence of a return type, meaning the method performs its action but doesn't produce any result that can be assigned to a variable.

Multiple choice
  1. main()

  2. destroy()

  3. init()

  4. repaint()

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

The init() method is the first lifecycle method called when an applet is loaded. It initializes the applet's state, sets up components, and prepares the applet for execution. The start() method comes after init() and is called to begin the applet's active execution.

Multiple choice
  1. init(), start() and destroy()

  2. init(), start() and paint()

  3. init(), start(), paint(). stop() and destroy()

  4. init(), start() and stop()

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

The applet lifecycle has four main methods: init() (called once when loaded), start() (called to begin execution), stop() (called when the applet should pause), and destroy() (called when the applet is being removed). The paint() method is for graphics, not a lifecycle method. Option D correctly lists the three core lifecycle methods.

Multiple choice
  1. StringReader

  2. PipeReader

  3. InputReader

  4. Both 1 and 2

  5. Both 1 and 3

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

There is no subclass of Reader class named InputReader. The correct name is InputStreamReader used for reading a character stream.So this is the correct answer according to the question.