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 web technology
  1. The Remote object reference

  2. The Remote object’s stub

  3. A local copy of the remote object

  4. None

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

When passing Remote objects to/from remote methods, the stub (proxy) is passed, not the actual remote object. The stub runs on the client side and communicates with the remote object via RMI. This is fundamental to how Java RMI works.

Multiple choice technology programming languages
  1. Asynchronous

  2. Synchronous

  3. Synchronous and Asynchronous

  4. None of above

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

In SAP, the Session Method (specifically BDC Session Method or Call Transaction) for data transfer is synchronous - it waits for processing to complete before moving to the next record/session. This ensures data integrity and proper error handling during batch data processing.

Multiple choice technology programming languages
  1. Vector

  2. HashMap

  3. ArrayList

  4. Hashtable

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

In java.util, Vector and Hashtable are legacy classes (from Java 1.0/1.1) that are synchronized and therefore thread-safe. Modern classes like ArrayList and HashMap (added in Java 1.2) are not thread-safe for performance. ConcurrentHashMap would be a modern thread-safe alternative. Options A and D are correct.

Multiple choice technology programming languages
  1. Thread(Runnable threadob,String threadName)

  2. Thread(String threadob, Runnable threadName)

  3. Thread(Runnable threadob,ArrayList threadName)

  4. Thread(ArrayList threadob,String threadName

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

To solve this question, the user needs to know the syntax and signature of the constructor of the Thread class in Java.

The constructor signature for the Thread class is:

Thread(Runnable threadob, String threadName)

This constructor creates a new thread object with the specified name and the given runnable object.

Now, let's go through each option and explain why it is right or wrong:

A. Thread(Runnable threadob, String threadName): This option is correct as it matches the signature of the Thread class constructor.

B. Thread(String threadob, Runnable threadName): This option is incorrect because the order of the parameters is reversed, and the first parameter is of type String, which is not valid for the Thread constructor.

C. Thread(Runnable threadob, ArrayList threadName): This option is incorrect because the second parameter should be of type String, not ArrayList.

D. Thread(ArrayList threadob, String threadName): This option is incorrect because the first parameter should be of type Runnable, not ArrayList.

Therefore, the answer is:

The Answer is: A

Multiple choice technology programming languages
  1. True

  2. False

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

To solve this question, the user needs to have knowledge about the Thread class and its methods.

The Thread class is a built-in class in Python that is used to create new threads of execution. A thread is a lightweight process that runs concurrently with other threads in a process.

When creating a subclass of the Thread class, the run() method is the method that is executed when the start() method is called on an instance of the class. The run() method contains the code that will be executed in the new thread.

Therefore, the run() method is necessary in a class created as a subclass of Thread class.

The answer is: A. True.

Multiple choice technology web technology
  1. setContentType()

  2. setPrintType()

  3. setWriter()

  4. setContentWriter()

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

Before using PrintWriter to write response content, you must set the content type using response.setContentType() to inform the browser about the data format (e.g., text/html, application/json). This ensures proper character encoding and content rendering on the client side.

Multiple choice technology programming languages
  1. <jsp:getColor bean="fruit"/>

  2. <jsp:getProperty id="fruit" property="color"/>

  3. <jsp:getProperty bean="fruit" property="color"/>

  4. <jsp:getProperty name="fruit" property="color"/>

  5. <jsp:getProperty class="Fruit" property="color"/>

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

The standard JSP action to retrieve a property from a JavaBean is . It requires the 'name' attribute (matching the 'id' in useBean) and the 'property' attribute. Option 539806 correctly uses 'name' instead of 'id' or 'bean'.

Multiple choice technology programming languages
  1. This is incorrect syntax of <jsp:setProperty/> and will generate a compilation error. Either value or param must be defined.

  2. All the properties of the fruit bean are initialized to a value of null.

  3. All the properties of the fruit bean are assigned the values of input parameters of the JSP page that have the same name.

  4. All the properties of the fruit bean are initialized to a value of *.

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

When property="*" is used in , it automatically matches request parameter names to bean property names and sets all matching properties. This is a shorthand for bulk property setting from HTTP parameters.

Multiple choice technology programming languages
  1. <listener>MyClass</listener>

  2. <listener> <listener-class>MyClass</listener-class></listener>

  3. <listener> <listener-name>aListener</listener-name> <listener-class>MyClass</listener-class> </listener>

  4. <listener> <servlet-name>myServlet</servlet-name> <listener-class>MyClass</listener-class> </listener>

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

The listener element in web.xml must contain a listener-class subelement specifying the fully-qualified class name of the listener class. Option A is missing the listener-class wrapper. Option C incorrectly includes listener-name (which is not a valid element). Option D incorrectly references servlet-name (listeners are not tied to specific servlets). Only option B shows the correct structure.

Multiple choice technology programming languages
  1. The JSTL code does not compile as an attribute for forEach tag is not correct.

  2. 0

  3. 2

  4. ABC

  5. Nothing gets printed as c.out statement does not get executed.

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

The forEach loop with begin=0, end=0, step=2 executes once with index=0. The var='item' sets the loop variable to 0. outputs 0. The key is that begin=0 end=0 means 'iterate from index 0 to index 0' in JSTL.

Multiple choice technology programming languages
  1. No number gets printed.

  2. One number gets printed.

  3. Two numbers gets printed.

  4. Three numbers gets printed.

  5. Four numbers gets printed.

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

To solve this question, the user needs to know the working of the JSTL choose tag and the conditions used in the when tags.

The code fragment defines a variable 'item' whose value is set to 2. The code then goes on to use the choose tag which is used for conditional processing. The choose tag contains multiple when tags. The when tags are evaluated in the order they are written, and the first condition that is true gets executed. If none of the conditions is true, the code in the otherwise tag is executed.

Looking at the code, the value of the 'item' variable is 2. The first condition in the when tags is "${item>0}" which is true for the given value of item. Therefore, the code inside the first when tag is executed which prints the number 1. The code doesn't go on to evaluate the other when tags because the first condition is true.

So, the answer is:

The Answer is: B. One number gets printed.

Multiple choice technology programming languages
  1. 1

  2. 2

  3. 3

  4. 4

  5. abc

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

The c:forEach tag processes the comma-separated string as a collection. The 'begin' and 'end' attributes are zero-indexed relative to the items. Index 1 refers to the second item ('3') and index 2 refers to the third item ('2'). Therefore, 3 and 2 are printed.