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. i. and iii. are true

  2. i. and iv. are true

  3. ii. and iii. are true

  4. ii. and iv. are true

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

This answer is correct. When an object invokes yield() method, the object will be ready to perform the next action and so it will be returned to the ready state. When the object calls sleep() method, it will not execute any further action and so it will not be ready to perform next action.

Multiple choice
  1. i. and iii. are true.

  2. i. and iv. are true

  3. ii. and iii. are true.

  4. ii. and iv. are true.

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

This answer is correct. String Buffer is synchronized or thread-safe and String Builder has higher performance compared to String Buffer.

Multiple choice
  1. i. and iv. are true

  2. i. and iii. are true

  3. ii. and iii. are true

  4. ii. and iv. are true

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

This answer is correct. NoSuchMethodException is caused when the method does not exist. NoSuchMethodException is a Checked Exception.

Multiple choice
  1. getClass()

  2. notify()

  3. notify all()

  4. hashCode()

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

This answer is correct. GetClass(), notify(), notify all() and wait() methods in Object class are declared as final. All other methods can be overridden. HashCode() can be overridden in any class.

Multiple choice
  1. i. and iii. are true

  2. i. and iv. are true

  3. ii. and iii. are true

  4. ii. and iv. are true

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

This answer is correct. ClassNotFoundException is caused when the class is not found and it is a checked exception.

Multiple choice
  1. Activity.getPreferences() can be used for that.

  2. There must be a single SharedPreferences object.

  3. By overriding an Activity's onSaveInstanceState event handler.

  4. Options 1 and 2.

  5. Options 1, 2 and 3.

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

Yes, it the correct answer.

Multiple choice
  1. addBatch()

  2. executeQuery()

  3. executeBatch()

  4. execute()

  5. getMetaData()

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

executeBatch() method is present in the Statement interface and not in PreparedStatement interface and it submits a batch of commands to the database for execution and if all commands execute successfully, returns an array of update counts. So, this answer is true.

Multiple choice
  1. isCloseOnInsertion()

  2. isCloseOnCompletion()

  3. isCloseOnDeletion()

  4. isCloseAfterUpdate()

  5. isCloseAfterInsertion()

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

isCloseOnCompletion() method is present in the Statement interface. This method returns a value indicating whether this statement will be closed when all its dependent result sets are closed or not. So, this answer is correct.

Multiple choice
  1. 10

  2. 9

  3. 8

  4. 7

  5. 6

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

There are 10 methods present in the Time class in java. These are:- 1) getDate() 2) getDay() 3) getMonth() 4) getYear() 5) setDate(int i) 6) setMonth(int i) 7) setTime(int i) 8) setYear(int i) 9) toString():- Formats a time in JDBC time escape format 10) valueOf(String s):- Converts a string in JDBC time escape format to a Time value So, this is the correct answer.

Multiple choice
  1. addBatch(String sql)

  2. closeOnCompletion()

  3. executeQuery(String sql)

  4. executeBatch()

  5. getResults()

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

There is no method named getResults() in Statement interface. The correct method name is getMoreResults() which moves to this Statement object's next result, returns true if it is a ResultSet object, and implicitly closes any current ResultSet object(s) obtained with the method getResultSet. So, this answer is true.