1.
--Controller Servlet in struts
Correct Answer
A. ActionServlet
Explanation
The correct answer is ActionServlet. In the Struts framework, the Controller Servlet is responsible for receiving and handling all the incoming requests. It acts as a front controller, receiving requests from the client and dispatching them to the appropriate Action classes. The ActionServlet is the default controller servlet provided by the Struts framework. It initializes the framework, manages the request processing flow, and delegates the request handling to the appropriate Action classes.
2.
Which of the collection classes will follow the InsertionOrder
Correct Answer
D. All the above
Explanation
All three collection classes mentioned (ArrayList, LinkedHashSet, and Vector) follow the InsertionOrder. This means that the elements in these collections are stored and retrieved in the order in which they were inserted. In ArrayList, elements are stored in an array and can be accessed using their index. In LinkedHashSet, elements are stored in a hash table with a linked list running through it, preserving the order of insertion. Vector is similar to ArrayList but is synchronized, making it thread-safe. Therefore, all three classes maintain the insertion order of elements.
3.
Http protocol is a _____________
Correct Answer
B. State less
Explanation
The given question is asking about the nature of the HTTP protocol. The correct answer is "stateless." This means that the HTTP protocol does not retain any information or state between requests. Each request is treated as an independent transaction, and the server does not remember any previous requests or interactions with the client. This allows for a more scalable and efficient system, as the server does not need to store and manage session data for each client.
4.
Public static void parse(String str) {
try {
float f = Float.parseFloat(str);
} catch (NumberFormatException nfe) {
f = 0;
} finally {
System.out.println(f);
}
}
public static void main(String[] args) {
parse("invalid");
}
What is the result?
Correct Answer
B. Compilation fails.
Explanation
The code in the main method calls the parse method and passes the string "invalid" as an argument. In the parse method, there is a try-catch block that attempts to parse the string as a float using the Float.parseFloat method. If the parsing fails and a NumberFormatException is thrown, the catch block sets the value of f to 0. However, since the variable f is declared within the try block, it is not accessible outside of it. Therefore, when the code tries to print the value of f in the finally block, a compilation error occurs because f is not recognized. Hence, the correct answer is "Compilation fails."
5.
Public class Yippee2 {
static public void main(String [] yahoo) {
for(int x = 1; x < yahoo.length; x++) {
System.out.print(yahoo[x] + " ");
}
. }
}
and the command line invocation:
java Yippee2 a b c
What is the result?
Correct Answer
B. B c
Explanation
The code starts iterating through the yahoo array from index 1 (since x is initialized to 1) and prints each element followed by a space. So, the output will be "b c" as it skips the first element "a" and starts printing from the second element "b" followed by "c".
6.
Public class Test {
public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;
f ((x == 4) && !b2 )
System.out.print("1 ");
System.out.print("2 ");. if ((b2 = true) && b1 )
System.out.print("3 ");
}
}
What is the result?
Correct Answer
D. 2 3
Explanation
The result is "2 3" because the first if statement evaluates to false since the condition (x == 4) is false. Therefore, the code inside the if statement is not executed. The second if statement evaluates to true since the assignment b2 = true returns true, and b1 is true. Therefore, the code inside the second if statement is executed, resulting in the output "3 ". Finally, the "2 " is printed outside of any if statements, resulting in the final output "2 3".
7.
Public class Hello {
String title;
int value;
public Hello() {
title += " World";
}
public Hello(int value) {
this.value = value;
title = "Hello";
Hello();
}
}
and:
Hello c = new Hello(5);
System.out.println(c.title);
What is the result?
Correct Answer
C. Compilation fails.
Explanation
The code will not compile because there is a syntax error in the constructor. The line "Hello();" is attempting to call the constructor within the constructor, which is not allowed.
8.
Public class Wow {
public static void go(short n) {System.out.println("short");}
public static void go(Short n) {System.out.println("SHORT");}
public static void go(Long n) {System.out.println(" LONG");}
public static void main(String [] args) {
Short y = 6;
int z = 7;
go(y);
go(z);
}
}
What is the result?
Correct Answer
C. Compilation fails.
Explanation
The code will not compile because there is no matching method signature for the argument passed in the second call to the "go" method. The argument "z" is of type int, and there is no method that accepts an int as an argument. Therefore, the code will not compile.
9.
Which of the following are correct as per MVC architecture
Correct Answer
B. Every web application should contain only one controller.
Explanation
In MVC architecture, the controller is responsible for handling user input and updating the model and view accordingly. Having multiple controllers in a web application can lead to confusion and inconsistency in handling user requests. Therefore, it is recommended to have only one controller in a web application to ensure proper coordination and organization of the application's functionality.
10.
<% int a = 10; %>
<%! int a = 20; %>
<%! int b = 30; %>
The value of b multiplied by a is <%= b * a %>
Correct Answer
C. The value of b multiplied by a is 300
Explanation
The given code snippet includes two scriptlet declarations, and . These scriptlet declarations are used to declare variables that can be accessed throughout the entire page. Therefore, the variable "a" is declared twice, once with a value of 10 and once with a value of 20. However, the variable "b" is only declared once with a value of 30. When the expression is evaluated, it will use the value of "b" (30) multiplied by the value of "a" (10), resulting in 300. Therefore, the correct answer is "The value of b multiplied by a is 300."
11.
If i want to use the name of the person across multiple pages then we have to store that person name in ___
Correct Answer
B. Session
Explanation
To use the name of a person across multiple pages, it is necessary to store that person's name in the session. The session is a mechanism that allows the server to store information about a user's interactions with a website. By storing the person's name in the session, it can be accessed and used on different pages throughout the user's session. This ensures that the person's name remains available and consistent as they navigate through the website.
12.
Using which object we can reduce the network traffing in JDBC
Correct Answer
B. PreparedStatement
Explanation
PreparedStatement can reduce network traffic in JDBC because it allows the database to compile and optimize the SQL statement only once, and then reuse the compiled statement with different parameter values. This reduces the amount of data that needs to be sent over the network for each execution of the statement, resulting in improved performance and reduced network traffic.
13.
Using which class object we can call Stored Procedures inJDBC
Correct Answer
D. CallableStatement
Explanation
CallableStatement is the correct answer because it is a JDBC interface that provides methods to call stored procedures in a database. It allows the execution of SQL statements that may contain input and output parameters. CallableStatement extends the PreparedStatement interface and provides additional methods specifically for calling stored procedures. Therefore, using a CallableStatement object, we can easily call and execute stored procedures in JDBC.
14.
Which object is responsible for reading confiuguration file in hibernate
Correct Answer
C. Configuration
Explanation
The Configuration object is responsible for reading the configuration file in Hibernate. It is used to configure and bootstrap Hibernate, including reading the hibernate.cfg.xml file which contains the necessary configuration settings for the Hibernate framework. The Configuration object is used to create a SessionFactory, which in turn is used to create Session objects for interacting with the database.
15.
Which of the following is a Legacy class in collections
Correct Answer
C. Vector
Explanation
Vector is considered a legacy class in collections because it was one of the original classes introduced in Java's early versions. It is part of the Java Collections Framework but has been largely replaced by the more modern ArrayList class. Vector is synchronized, which means it is thread-safe, but this can also lead to performance issues in multi-threaded environments. Therefore, it is generally recommended to use ArrayList instead of Vector in most cases.
16.
What will be the output of the following JSP page?
<% a = 100; %>
<% int a = 200; %>
<%! int a = 300; %>
a = <%= a %>, <%= this.a %>
Correct Answer
A. A = 200, 100
Explanation
The output of the JSP page will be "a = 200, 100". This is because the first declaration of "a" assigns it the value of 100. The second declaration of "a" is a local variable within the tags and assigns it the value of 200. The third declaration of "a" is a global variable within the tags and assigns it the value of 300. The final line of code outputs the values of "a" using the tags, which will output the value of the local variable "a" (200) followed by the value of the global variable "a" (100).
17.
Which of the following design patterns is used to separate the task of writing the GUI screens and business logic?
Select 1 correct option.
Correct Answer
C. Model View Controller
Explanation
The Model View Controller (MVC) design pattern is used to separate the task of writing the GUI screens and business logic. In MVC, the model represents the data and business logic, the view represents the GUI screens, and the controller acts as an intermediary between the model and the view, handling user input and updating the model and view accordingly. This separation of concerns allows for easier maintenance and testing of the application.
18.
Regarding the processing of a BodyTag handler, in which of the following cases a BodyContent object will be "pushed" into the pageContext?
Select 1 correct option.
Correct Answer
C. If the doStartTag() returns SKIP_BODY
Explanation
If the doStartTag() returns SKIP_BODY, a BodyContent object will be "pushed" into the pageContext.
19.
Your web application named "FWorks" uses SpecialMath.class. This is an unbundled class and is not contained in any jar file. Where will you keep this class file?
Select 1 correct option.
Correct Answer
B. FWorks/WEB-INF/classes
Explanation
The correct answer is FWorks/WEB-INF/classes. This is because in a web application, the classes that are not contained in any jar file are typically stored in the WEB-INF/classes directory.
20.
Identify the implicit objects available to EL expressions.
Correct Answer
E. All the avove
Explanation
The implicit objects available to EL expressions include requestScope, pageScope, header, and pageContext. These objects provide access to various information and functionalities within the application. The requestScope object allows access to attributes stored in the request scope, the pageScope object allows access to attributes stored in the page scope, the header object allows access to HTTP request headers, and the pageContext object provides access to the page context. Therefore, all of the above options are correct.