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. replace(char, char)

  2. replaceAll(String, String)

  3. append(String)

  4. Both (1) and (2)

  5. All of these

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

This is the correct answer. Because the String class objects are immutable (i.e once the object of the String class is created its contents cannot be changed). So we cannot append new characters or string in the old string. So this is the correct answer.

Multiple choice
  1. 16

  2. 4

  3. 18

  4. 3

  5. 15

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

The correct answer is 16. When stringbuffer object is created the default capacity of the object is always 16. If the number of characters in the string increases, the capacity will increase with the following formula:-2 * (previous capacity + 1). In this case hello has 5 characters, so the default capacity will not change. Hence, this is correct.

Multiple choice
  1. IllegalArgumentException

  2. NullPointerException

  3. IOException

  4. IndexOutOfBoundException

  5. ArithmeticException

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

IOException is not a subclass of RuntimeException class, this class is a Subclass of Exception class. This exception is thrown when invalid input/output are given. So, this is the correct answer as this is not a subclass of RuntimeException class.

Multiple choice
  1. setLocation(int, int)

  2. setVisible(Boolean)

  3. setSize(int, int)

  4. setDefaultCloseOperation(int)

  5. Pack()

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

This function is not defined in the Frame class. This function is defined in JFrame class in Swings. So, this method cannot be invoked using the object of Frame class. But can be invoked using the Object of JFrame class. This method specifies the operation when the frame is closed. So, the following line would be false. Frame f1 = new frame(); f1.setDefaultCloseOperation(int); so, this is the correct answer.

Multiple choice
  1. windowMoved()

  2. windowClosing()

  3. windowIconified()

  4. windowActivated()

  5. windowDeiconified()

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

If a class implements an interface then it is necessary for that class to define body to all the methods defined in the interface it is implementing. But, windowMoved() method is not present in windowListener interface. So, when a class will implement this interface this method need not to be define in the class. So, this option is correct.