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 technology programming languages
  1. Compile time error, class Rpcraven does not import java.lang.Thread

  2. Output of One One Two Two

  3. Output of One Two One Two

  4. Output of One Two Two One

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

The code calls run() directly on each Pmcraven object instead of start(). This means the code executes sequentially in the main thread, not as separate threads. Each run() method prints the thread name twice before returning, producing 'one one' then 'two two'.

Multiple choice technology programming languages
  1. An exception is thrown if you attempt to add an element with a duplicate value.

  2. The add method returns false if you attempt to add an element with a duplicate value.

  3. A set may contain elements that return duplicate values from a call to the equals method.

  4. Duplicate values will cause an error at compile time.

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

The Set interface prevents duplicate elements. When attempting to add an element already present in the set, the add method simply returns false and leaves the set unchanged. It does not throw exceptions or cause compile-time errors.

Multiple choice technology programming languages
  1. An exception is thrown if you attempt to add an element with a duplicate value.

  2. The add method returns false if you attempt to add an element with a duplicate value.

  3. A set may contain elements that return duplicate values from a call to the equals method.

  4. Duplicate values will cause an error at compile time.

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

To answer this question, the user needs to understand the basic functionality of the Set collection in Java.

Option A is incorrect. When attempting to add an element to a Set that already exists in the Set, an exception is not thrown. Instead, the Set simply ignores the duplicate element and does not add it to the collection.

Option B is correct. The add method of a Set returns a boolean value of false if the element being added already exists in the Set. This is because Sets do not allow duplicate elements.

Option C is incorrect. Sets are designed to contain only unique elements. If an element already exists in the Set, it will not be added again. Therefore, a Set cannot contain elements that return duplicate values from a call to the equals method.

Option D is incorrect. Duplicate values will not cause an error at compile time. Instead, the Set will simply ignore the duplicate value when the code is executed.

Therefore, the correct answer is:

The Answer is: B. The add method returns false if you attempt to add an element with a duplicate value.

Multiple choice technology programming languages
  1. Compile time error, class Rpcraven does not import java.lang.Thread

  2. Output of One One Two Two

  3. Output of One Two One Two

  4. Output of One Two Two One

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

Calling run directly on a Thread executes the method synchronously in the current thread instead of starting a new thread of execution. Therefore, pm1 completes its loop printing one twice before pm2 starts its loop printing two twice.

Multiple choice technology platforms and products
  1. Activity-End

  2. Activity-Exit

  3. End-Activity

  4. Exit-Activity

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

In Pega PRPC, invoking the Activity-End method immediately terminates the current activity as well as all calling activities in the execution stack. It prevents the system from returning control to the parent/calling activity. Conversely, the Exit-Activity method only terminates the current activity and returns control to the caller.

Multiple choice technology programming languages
  1. Extend Thread class

  2. Implement Runnable interface

  3. Both

  4. None

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

Implementing the Runnable interface is preferred over extending the Thread class in Java because Java does not support multiple inheritance. By implementing an interface, the class remains free to inherit from another class. This approach also promotes better separation of concerns between the task execution logic and the thread mechanism.

Multiple choice technology programming languages
  1. Extend Thread class

  2. Implement Runnable interface

  3. Both

  4. None

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

Implementing Runnable interface is preferred over extending Thread class because Java supports only single inheritance - by implementing Runnable, your class can still extend another class if needed. It also separates the task logic from the thread execution mechanism, following better object-oriented design principles. Extending Thread should only be used when you need to override Thread methods other than run().

Multiple choice technology architecture
  1. (a) Activity-End

  2. (b) End-Activity

  3. (c) Exit-Activity

  4. (d) Activity-Exit

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

Activity-End terminates both the current activity and the calling activity, then continues with the next activity on the requestor's list. End-Activity, Exit-Activity, and Activity-Exit are not valid PRPC method names.

Multiple choice technology architecture
  1. a. Immediate, Write-Now

  2. b. Write-Now, Immediate

  3. c. Save-Now, Immediate

  4. d. Immediate, Save-Now

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

Obj-Save has a Write-Now checkbox that writes immediately to the database, while Obj-Delete has an Immediate checkbox for the same purpose. Both bypass the normal Commit method requirement when these checkboxes are selected.

Multiple choice technology architecture
  1. (a) Activity-End

  2. (b) End-Activity

  3. (c) Exit-Activity

  4. (d) Activity-Exit

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

Activity-End is the correct Pega method that terminates the current activity and returns control to the calling activity, which then continues with the next activity on the requestor's list. This is essential for controlling flow in Pega processes. The naming convention places the object (Activity) before the action (End).

Multiple choice technology architecture
  1. a. Immediate, Write-Now

  2. b. Write-Now, Immediate

  3. c. Save-Now, Immediate

  4. d. Immediate, Save-Now

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

In Pega, Obj-Save has a Write-Now checkbox that causes immediate database write, while Obj-Delete has an Immediate checkbox for the same purpose. Both bypass the standard Commit method queue and perform the database operation instantly. Remembering which method uses which checkbox name is key.

Multiple choice technology web technology
  1. _jspService()

  2. jspInit()

  3. jspDestroy()

  4. getParameter()

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

In JSP, only jspInit() and jspDestroy() can be overridden by developers. The _jspService() method is generated by the container and cannot be overridden (it's marked final in the generated servlet). getParameter() is a method of ServletRequest interface, not a JSP lifecycle method.

Multiple choice technology web technology
  1. main method

  2. start method

  3. init method

  4. paint method

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

When a web browser loads an applet, it calls the init() method first - this is where one-time initialization happens. The browser then calls start() to begin execution, and may call paint() when the display needs rendering. The main() method is NOT used in applets - that's for standalone applications.