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 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
  1. One is not a method of the String object.

  2. substr() takes three arguments, substring() only two.

  3. Only one accepts a desired string length as an argument.

  4. Besides the spelling, nothing

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

substr() accepts a start position and length parameter, while substring() takes start and end positions. Only substr() allows specifying the desired string length directly. Option A is incorrect because both are String methods. Option B is wrong because neither takes three arguments. Option D is false because their parameter semantics differ fundamentally.

Multiple choice general knowledge
  1. One is not a method of the String object.

  2. substr() takes three arguments, substring() only two.

  3. Only one accepts a desired string length as an argument.

  4. Besides the spelling, nothing

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

substr() accepts a start position and length parameter, while substring() takes start and end positions. Only substr() allows specifying the desired string length directly. Option A is incorrect because both are String methods. Option B is wrong because neither takes three arguments. Option D is false because their parameter semantics differ fundamentally.

Multiple choice general knowledge
  1. The Java console

  2. LiveConnect

  3. LiveWire

  4. LiveWire Pro

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

LiveConnect was the technology that enabled JavaScript to communicate with Java applets, allowing JavaScript to call Java methods and access Java properties. LiveWire and LiveWire Pro were server-side JavaScript technologies. The Java console is a debugging tool, not an integration mechanism.

Multiple choice general knowledge
  1. for(var i = 0; i < myString.length; i++) {

  2. var myArray = myString.split('x'); myString = myArray.join('');

  3. It wasn't possible until now. Thanks JavaScript1.2!

  4. The first two both work fine

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

Before JavaScript 1.2's enhanced String.replace(), you could remove characters using two approaches: 1) iterate through the string building a new string without 'x', or 2) split on 'x' and join the array with empty string. Both methods work, though split/join is more concise.

Multiple choice general knowledge
  1. Add a TYPE=HIDDEN INPUT to the form

  2. Trap the return keypress and return (null)

  3. Add 'return false' to onsubmit="..." in the FORM tag

  4. Instruct the user not to press the Return key.

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

Adding 'return false' to the onsubmit handler in the FORM tag prevents the default form submission behavior when the user presses Enter. This allows custom JavaScript processing to handle the form data instead. The other options - hidden input, trapping return key, or instructing users - don't address the core issue of form submission behavior.

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 softskills communication
  1. Always

  2. Never

  3. When you want to find when the recepient opened the mail.

  4. My wish

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

Email return receipts are often considered intrusive and unprofessional - they pressure recipients and can be blocked. Best practice is to avoid them unless absolutely necessary for critical business/legal reasons. 'Always' is too aggressive; tracking recipients makes them uncomfortable.