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 general knowledge science & technology
  1. init()

  2. start()

  3. run()

  4. resume()

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

In Java threading, the start() method is used to begin execution of a thread. When start() is called, the JVM creates a new thread and invokes the run() method within that new thread. The init() method is not a standard thread method, run() contains the thread's body but doesn't start execution, and resume() is deprecated. The start() method is specifically designed for thread initialization and execution.

Multiple choice general knowledge science & technology
  1. Object

  2. Thread

  3. Runnable

  4. Class

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

The wait(), notify(), and notifyAll() methods are defined in the Object class in Java, not in Thread or Runnable. This design allows all objects to be used as locks or monitors for thread synchronization. Every object in Java inherits these methods from Object. The Thread class provides methods for thread management, while Runnable is an interface for defining thread tasks. Only Object defines these fundamental synchronization methods.

Multiple choice general knowledge science & technology
  1. void run()

  2. public void run()

  3. public void start()

  4. void run(int priority)

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

The Runnable interface requires implementing the run() method with public void run() signature. The method must be public (to be called by the thread) and void (no return value). Option A (void run()) lacks the public modifier, making it inaccessible. Option C (public void start()) is incorrect because Runnable doesn't define start(). Option D (void run(int priority)) has wrong signature and parameters. The exact signature public void run() is mandated by the interface contract.

Multiple choice general knowledge science & technology
  1. NullPointerException

  2. ServletException

  3. FileNotFoundException

  4. IOException

  5. none of the above

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

The doGet() method in HttpServlet explicitly declares ServletException and IOException in its method signature. ServletException is thrown for servlet-specific errors, while IOException handles general I/O errors during request processing. NullPointerException (unchecked) and FileNotFoundException (not thrown by doGet) are not declared exceptions.

Multiple choice general knowledge science & technology
  1. Getparameter()

  2. getParameterValue()

  3. getParameterValues()

  4. getParamValues()

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

The getParameterValues() method returns all values for a parameter that has multiple values (like multi-select dropdowns or checkbox groups). It returns a String array containing all values. getParameter() returns only the first value, while getParameterValue() and getParamValues() are not standard servlet API methods.

Multiple choice general knowledge science & technology
  1. sendErrorMessage()

  2. sendError()

  3. sendMessage()

  4. sendHttpErrorCode()

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

The HttpServletResponse.sendError() method sends an error response to the client with a specific HTTP status code. Methods like sendErrorMessage(), sendMessage(), and sendHttpErrorCode() don't exist in the servlet API. sendError() is the standard way to send error responses.

Multiple choice general knowledge science & technology
  1. Escape special characters using the specific escape syntax for that interpreter

  2. Use of Parameterized API

  3. Avoid sending the wrong data at first place as request parameter.

  4. Input Validation using Whitelist

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

Option C is the correct answer because 'Avoid sending the wrong data' is not a technical injection prevention mechanism - it's a general practice rather than a specific defensive technique. The other options ARE valid prevention mechanisms: escaping special characters (A), using parameterized APIs/prepared statements (B), and input validation with whitelists (D) are all standard techniques for preventing SQL injection and similar attacks.

Multiple choice general knowledge science & technology
  1. 1.6.0 Rev 24

  2. 1.5.0 Rev 20

  3. 1.6.0 Rev 23

  4. 1.6.2 Rev 24

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

Java 1.6.0 Update 24 was indeed a recent version when this question was written (around 2007-2008). Java 6 (also known as Java 1.6) was a major release and Update 24 was a significant revision. However, note that Java has progressed significantly since then - current LTS versions are Java 17 and Java 21. This question reflects the version landscape of its era.

Multiple choice technology programming languages
  1. new and delete are keywords in the Java language

  2. try, catch, and thrown are keywords in the Java language

  3. return, goto, and default are keywords in the Java language

  4. for, while, and next are keywords in the Java language

Reveal answer Fill a bubble to check yourself
D Correct answer
Multiple choice technology
  1. All of these

  2. (C) & (E)

  3. (A), (C) & (E)

  4. (B),(C) & (D)

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

To solve this question, the user needs to have knowledge about the initial version of Java and the keywords that were reserved but not used. The user must then identify which options list the correct keywords.

The correct answer is:

D. (B),(C) & (D)

Explanation:

In the initial version of Java, the keywords "const" and "goto" were reserved but not used. The keyword "inner" was not reserved at all in the initial version of Java. The other options, "union", "boolean", and "synchronized" were not keywords in the initial version of Java.

Therefore, options (A) and (C) are incorrect as they include options that were not reserved in the initial version of Java. Option (B) is incorrect as "boolean" was not a reserved keyword in the initial version of Java. Option (D), on the other hand, correctly lists all the keywords that were reserved but not used in the initial version of Java, which are "const", "goto", and "inner".

The Answer is: D. (B),(C) & (D)