Computer Knowledge

Java Core Classes and Threads

1,473 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. Throwable is the superclass of all exception classes in Java.

  2. Stack overflow is an example of runtime exception.

  3. Checked exceptions occurr due to user error.

  4. Finally clause is used to free the resources allocated by the methods in the beginning of the program.

  5. All of the above

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

This is a false statement as it is not an exception. It is an error.

Multiple choice
  1. public int hashCode(String s) { int h = 0; char val[] = s.toCharArray(); for (int i = 0; i < value.length; i++) { h = 31 * h + val[i]; } } return h; }

  2. public int hashCode(String s) { int h = 0; char val[] = s.toCharArray(); for (int i = 0; i < value.length; i++) { h = 27 * h + val[i]; } } return h; }

  3. public int hashCode(String s) { int h = 0; char val[] = s.toCharArray(); for (int i = 0; i < value.length; i++) { h = 131 * h + val[i]; } } return h; }

  4. public int hashCode(String s) { int h = 0; char val[] = s.toCharArray(); for (int i = 0; i < value.length; i++) { h = 231 * h + val[i]; } } return h; }

  5. public int hashCode(String s) { int h = 0; char val[] = s.toCharArray(); for (int i = 0; i < value.length; i++) { h = 531 * h + val[i]; } } return h; }

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

31 is used because 31 * i == (i << 5) - i. This can be performed very quickly.