Advanced Java Quiz

Reviewed by Samy Boulos
Samy Boulos, MSc (Computer Science) |
Data Engineer
Review Board Member
Samy Boulos is an experienced Technology Consultant with a diverse 25-year career encompassing software development, data migration, integration, technical support, and cloud computing. He leverages his technical expertise and strategic mindset to solve complex IT challenges, delivering efficient and innovative solutions to clients.
, MSc (Computer Science)
By JQuizMaster
J
JQuizMaster
Community Contributor
Quizzes Created: 1 | Total Attempts: 12,224
| Attempts: 12,225 | Questions: 22
Please wait...
Question 1 / 22
0 %
0/100
Score 0/100
1. Which design pattern allows you to decouple the business logic, data representation, and data presentation? (Select one)

Explanation

In the Model-View-Controller pattern, Model is the data representation, View is
the data presentation, and Controller is the implementation of business logic.

Submit
Please wait...
About This Quiz
Advanced Java Quiz - Quiz

Have you practiced Java enough that you are ready to learn advanced Java? Take this advanced Java quiz, and see how much you have learned. This will examine... see moreyour understanding of JSP, Servlet, and Design patterns. You will get an idea about your understanding while taking the quiz and after checking the result. Give it a try and see what more you need to learn, or you know everything. All the best! Do share the quiz with other programming fans. see less

2. Which method in the HttpServlet class services the HTTP POST request? (Select one)

Explanation

Remember that HttpServlet extends GenericServlet and provides HTTPspecific functionality. Thus, all its methods take HttpServletRequest and HttpServletResponse objects as parameters. Also, the method names follow the standard Java naming convention—for example, the method for processing POST requests is doPost() and not doPOST().

Submit
3. What file is the deployment descriptor of a web application named BankApp stored in?

Explanation

The deployment descriptor of a web application is always kept in a file named
web.xml, no matter what the name of the web application is.

Submit
4. Your web application, named simpletax, depends on a third-party JAR file named taxpackage.jar. Where would you keep this file?

Explanation

All the classes that are packaged in a JAR file must be kept in the WEB-INF/lib
directory. The servlet container automatically adds all the classes in all the JAR files
kept in this directory to the classpath of the web application.

Submit
5. Which of the following implicit objects is not available to a JSP page by default?

Explanation

The implicit variables application and config are always available to a JSP
page. The implicit variable session is available if the value of the page directive’s
session attribute is set to true. Since it is set to true by default, the implicit
variable session is also available by default. The implicit variable exception is
available only if the value of the page directive’s isErrorPage attribute is set to
true. It is set to false by default, so the implicit variable exception is not
available by default. We have to explicitly set it to true:

Submit
6. Which of the following correctly declares that the current page is an error page and also enables it to take part in a session?

Explanation

The isErrorPage attribute accepts a Boolean value (true or false) and indicates whether the current page is capable of handling errors. The session attribute accepts a Boolean value (true or false) and indicates whether the current page must take part in a session. Since the pageType attribute is not a valid attribute for a page directive, answer is not correct. The mandatory value is not a valid value for the session attribute, which means answer is not correct. The errorPage attribute is a valid attribute, but it is used for specifying another page as an error handler for the current page. Therefore, that answer is also incorrect.

Submit
7. Which of the following lines would initialize the out variable for sending a Microsoft Word file to the browser?

Explanation

For sending any data other than text, you need to get the OutputStream object.
ServletResponse.getOutputStream() returns an object of type Servlet-
OutputStream, where ServletOutputStream extends OutputStream.

Submit
8. Which element is used to specify useful information about an initialization parameter of a servlet in the deployment descriptor?

Explanation

Remember that the description element is used for all the elements that can
take a description (useful information about that element). This includes servlet,
init-param, and context-param, among others. For a complete list of the
elements that can take a description, please read the DTD for web.xml.

Submit
9. Consider the following class: import javax.servlet.*; public class MyListener implements ServletContextAttributeListener { public void attributeAdded(ServletContextAttributeEvent scab) { System.out.println("attribute added"); } public void attributeRemoved(ServletContextAttributeEvent scab) { System.out.println("attribute removed"); } } Which of the following statements about the above class is correct?

Explanation

ServletContextAttributeListener also declares the public void attributeReplaced(
ServletContextAttributeEvent scab) method, which
is called when an existing attribute is replaced by another one.

Submit
10. Consider the following code, contained in a file called this.jsp: <jsp:include page="that.jsp" /> Which of the following is true about the AddressBean instance declared in this code?

Explanation

By default, the scope is page, so the bean is not available in that.jsp.

Submit
11. Which of the following is a valid taglib directive?

Explanation

A taglib directive requires uri and prefix attributes

Submit
12. You are automating computer parts ordering business. For this purpose, your
web application requires a controller component that would receive the requests
and dispatch them to appropriate JSP pages. It would also coordinate the request
processing among the JSP pages, thereby managing the workflow. Finally, the
behavior of the controller component is to be loaded at runtime as needed.
Which design pattern would be appropriate in this situation?

Explanation

This is a standard situation for the Front Controller pattern. The Front Controller
receives all the requests and dispatches them to the appropriate JSP pages. This is
not the MVC pattern, because the question only asks about controlling the workflow.
You would choose the MVC pattern if it asked about controlling and presenting
the data in multiple views.

Submit
13. What will be the output of the following code? (Select one) x = ,

Explanation

The above code will translate to servlet code similar to the following:
public class ...
{
int x = 7;
public void _jspService(…)
{
...
out.print("

");
x = 3;
int x = 5;
out.write("x = "); out.print(x);
out.write(","); out.print(this.x);
out.print("");
}
}
The declaration will create a member variable x and initialize it to 7. The first
scriptlet, x=3, will change its value to 3. Then, the second scriptlet will declare a
local variable x and initialize it to 5. The first expression refers to the local variable
x and will therefore print 5. The second expression uses the keyword this to
refer to the member or instance variable x, which was set to 3. Thus, the correct
answer is c, x = 5, 3.
Submit
14. Consider the following doPost() method of a servlet: public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("Inside doPost"); PrintWriter out = response.getWriter(); out.println("Hello, "); String name = getNameFromDBSomeHow(); if(name == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unable to get name."); } out.println(name); } Assuming that getNameFromDBSomeHow() returns null, which of the following statements regarding this code are correct?

Explanation

When the sendError() method is called, the response is assumed to be committed.
If you write anything to the response after it gets committed, an Illegal-
StateException is thrown. In this case, sendError() is called if the name is
null. This commits the response. However, after the if condition, we have
out.println(name), which will cause the IllegalStateException to
be thrown.

Submit
15. Which of the following statements are correct? (Select two)

Explanation

Making the Value Object immutable reinforces the idea that the Value Object is not a remote object and any changes to its state will not be reflected on the server.

clients require a fewer number of remote calls to retrieve attributes.

Submit
16. Which of the following are the benefits of using the Value Object design pattern? (Select two)

Explanation

The Value Object pattern allows you to retrieve all the data elements in one
remote call instead of making multiple remote calls; therefore, it reduces the network
traffic and improves the response time since the subsequent calls to the
object are local.

Submit
17. What are the benefits of using the Business Delegate pattern? (Select three)

Explanation

The clients delegate the task of calling remote business service methods to the Business Delegate. Thus, they are shielded by the business delegates from the access mechanism of the business services. The Business Delegate is meant to shield the clients from the implementation of the business services. It provides the clients with a uniform interface to the business services, which is a goal of this pattern. x---in correct Business Delegate does not implement any business service itself. It calls remote methods on the business services on behalf of the presentation. Business Delegate does not reduce the number of remote calls. It calls the remote methods on behalf of the client components.

Submit
18. What are the benefits of using the Data Access Object pattern? (Select two)

Explanation

This pattern is used to decouple business logic from data access logic. It hides the
data access mechanism from the business objects so that the data source can be
changed easily and transparently to the business objects.

Submit
19. In the context of Java concurrency, what is the primary function of the volatile keyword when applied to a variable?

Explanation

The volatile keyword in Java is used to indicate that a variable's value will be modified by different threads. Declaring a variable as volatile ensures that any write to the variable by one thread is immediately visible to other threads. This is achieved by preventing the variable from being stored in the local thread cache, thereby directly writing to and reading from the main memory, which maintains memory visibility across threads.

Submit
20. Which of the following tags can you use to print the value of an expression to the output stream?

Explanation

You can use a JSP expression to print the value of an expression to the output stream.
For example, if the expression is x+3, you can write . But you can also use a scriptlet to print the value of an expression to the output stream as
.

Submit
21. Which of the options locate the bean equivalent to the following action? (Select three)

Explanation

beans cannot be get or set as request parameters.
They can be get and set as request attributes.

getServletContext() returns an object of type ServletContext and Servlet-
Context has nothing to do with the request scope.

the methods getRequestAttribute() and getRequestParameter()
do not exist in PageContext.

Submit
22. Consider the following code: state = Which of the following are equivalent to the third line above? (Select three)

Explanation

the standard convention
that the beans follow is to capitalize the first character of the property’s
name. Therefore, it should be getState() and not getstate().
the method call address.getState() is in a declaration
instead of an expression.
the scriptlet and does not print any output.

Submit
View My Results
Samy Boulos |MSc (Computer Science) |
Data Engineer
Samy Boulos is an experienced Technology Consultant with a diverse 25-year career encompassing software development, data migration, integration, technical support, and cloud computing. He leverages his technical expertise and strategic mindset to solve complex IT challenges, delivering efficient and innovative solutions to clients.

Quiz Review Timeline (Updated): Sep 1, 2024 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Sep 01, 2024
    Quiz Edited by
    ProProfs Editorial Team

    Expert Reviewed by
    Samy Boulos
  • Jan 18, 2012
    Quiz Created by
    JQuizMaster
Cancel
  • All
    All (22)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which design pattern allows you to decouple the business logic, data...
Which method in the HttpServlet class services the HTTP POST request? ...
What file is the deployment descriptor of a web application named...
Your web application, named simpletax, depends on a third-party JAR...
Which of the following implicit objects is not available to a JSP page...
Which of the following correctly declares that the current page is an...
Which of the following lines would initialize the out variable for...
Which element is used to specify useful information about an...
Consider the following class:...
Consider the following code, contained in a file called this.jsp:...
Which of the following is a valid taglib directive?
You are automating computer parts ordering business. For this purpose,...
What will be the output of the following code? (Select one) x = ,
Consider the following doPost() method of a servlet:...
Which of the following statements are correct? (Select two)
Which of the following are the benefits of using the Value Object...
What are the benefits of using the Business Delegate pattern? (Select...
What are the benefits of using the Data Access Object pattern? (Select...
In the context of Java concurrency, what is the primary function of...
Which of the following tags can you use to print the value of an...
Which of the options locate the bean equivalent to the following...
Consider the following code:...
Alert!

Advertisement