Tag: java

Questions Related to java

In JSP, how can you know what HTTP method (GET or POST) is used by client request ?

  1. by using request.getMethod()

  2. by using request.setMethod()

  3. impossible to know

  4. none of these


Correct Option: A
Explanation:

To determine the HTTP method (GET or POST) used by a client request in JSP, you can use the request.getMethod() method.

The correct answer is:

The Answer is: A. by using request.getMethod()

Explanation:

A) by using request.getMethod(): This option is correct. The request.getMethod() method is used to retrieve the HTTP method used by the client request. It returns a string representing the HTTP method, such as "GET" or "POST".

B) by using request.setMethod(): This option is incorrect. The request.setMethod() method does not exist in JSP. There is no built-in method to set the HTTP method of a request.

C) impossible to know: This option is incorrect. It is possible to know the HTTP method used by the client request by using the request.getMethod() method.

D) none of these: This option is incorrect. The correct answer is option A, as explained above.

Therefore, the correct answer is:

The Answer is: A. by using request.getMethod()

  1. A loop can begin in one Scriptlet and end in another

  2. Statements in Scriptlets should follow Java Syntax

  3. Semicolon is needed at the end of each statement in a Scriptlet

  4. All the above


Correct Option: D

What is the output of following piece of code ?

int x = 2;
 switch (x) {
 case 1:System.out.println("1?);
 case 2:
 case 3:System.out.println("3?);
 case 4:
 case 5:System.out.println("5?);
 }
  1. No output

  2. 3 and 5

  3. 1, 3 and 5

  4. 3


Correct Option: B,D
Explanation:

To solve this question, the user needs to understand the concept of switch case statements in Java. The switch statement tests the value of a variable and compares it with multiple cases. If a case matches the value of the variable, then the code inside that case is executed. If no matching cases are found, then the default case is executed.

In the given code, the variable x is initialized to 2. The switch statement checks the value of x, and since it matches the case 2, the code inside that case is executed. Since there are no break statements, the control falls through to the next case, which is 3. Thus, the output will be "3?".

The case for 1 and 5 are not executed because the value of x is not equal to 1 or 5.

Option A is incorrect because there is output from the code. Option B is incorrect because the output is not just 3 and 5. Option C is incorrect because there is no output for 1.

Therefore, the answer is:

The Answer is: D. 3

  1. the new method should return int

  2. the new method can return any type of values

  3. the argument list of new method should exactly match that of overriden method

  4. the return type of new method should exactly match that of overriden method


Correct Option: C
  1. Stateless session beans doesn’t preserve any state across method calls

  2. Stateful session beans can be accesses by multiple users at the same time


Correct Option: A
  1. The element will be successfully added

  2. ArrayIndexOutOfBounds Exception

  3. The Vector allocates space to accommodate up to 15 elements

  4. none of these


Correct Option: A,C

A class can be converted to a thread by implementing the interface ___.

  1. Thread

  2. Runnable

  3. Both of these

  4. none of these


Correct Option: B

AI Explanation

To answer this question, you need to understand the concept of converting a class into a thread in Java.

In Java, a class can be converted to a thread by implementing the Runnable interface. The Runnable interface defines a single method named run(), which is the entry point for the thread when it is started. By implementing this interface, the class can define the code that will be executed in a separate thread when the thread is started.

Option A) Thread - This option is incorrect because the Thread class itself represents a thread, rather than converting a class into a thread.

Option B) Runnable - This option is correct because implementing the Runnable interface allows a class to be converted into a thread by defining the run() method.

Option C) Both of these - This option is incorrect because only implementing the Runnable interface is required to convert a class into a thread. The Thread class is not necessary for this conversion.

Option D) none of these - This option is incorrect because implementing the Runnable interface is the correct way to convert a class into a thread.

The correct answer is Option B) Runnable. This option is correct because implementing the Runnable interface allows a class to be converted into a thread.

Therefore, the correct answer is B) Runnable.

  1. null

  2. Primary Key class

  3. Home Object

  4. Remote Object


Correct Option: A
  1. abstract double area() { }

  2. abstract double area()

  3. abstract double area();

  4. abstract double area(); { }


Correct Option: C
Explanation:

To pass the reference of one EJB to another, you can use Dependency Injection (DI) or JNDI (Java Naming and Directory Interface). In DI, the reference to the EJB is passed through the constructor or a setter method. In JNDI, the EJB is bound to a JNDI name, and the other EJB looks up the name to get a reference to the EJB.

Option C is the correct syntax for an abstract method in a Java abstract class. The abstract keyword is used to indicate that the method has no implementation and must be overridden in a subclass. The parentheses after the method name are used to define the parameter list, and the semicolon at the end indicates the end of the method signature.

Option A is incorrect because it includes a method body, which is not allowed in an abstract method.

Option B is also incorrect because it does not include parentheses to define the parameter list, which is necessary even if the method takes no parameters.

Option D is incorrect because it includes a method body after the semicolon, which is not allowed in an abstract method.

Therefore, the correct answer is:

The Answer is: C