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. This method returns the closest long or int, as indicated by the method's return type, to the argument.

  2. This method returns the smallest integer that is greater than or equal to the argument as a double.

  3. This method returns the largest integer that is less than or equal to the argument as a double.

  4. This method returns a String object representing the value of specified int or Integer.

  5. This method converts the primitive data type of a certain String.

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

ceil() method does this.

Multiple choice
  1. toLower()

  2. trim()

  3. split()

  4. both 1 and 3

  5. both 2 and 3

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

This is the correct answer. Because there is no method defined in the String class named toLower(). So it cannot be invoked using the object of String class.The correct method is toLowerCase() which converts the characters to lowercase.So this is correct answer according to the question asked.

Multiple choice
    • 1
  1. 11

  2. 6

  3. Compiler error : method lastIndexOf() not declared

  4. Compiler error : parameters to method not sufficient

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

lastIndexOf(String s , index i) method return the last occurrence of string s before the from index. Return -1 if string not found. So here the string to find is “Java” before the index 5 which means before the character m.but string “java” is not present before the index 5 i.e character m.so it will return -1.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 default capacity will not change.So this is correct answer.

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. Wait()

  2. Destroy()

  3. Dead()

  4. Both 1 and 3

  5. Both 1 and 2

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

This is the correct option because destroy() method is invoked when browser exits normally to inform the applet that is no longer needed and should release any recourses allocated.So this is the correct method. Hence this is correct choice according to the question asked.

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.

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.