• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SCWCD mock questions II

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

javabeat



I have some queries in the following question
Please Help.



1.Consider the following description of a tag in a TLD:
Which of the following statements regarding the above tag are correct?
Select 2 correct options.
A.It is an empty tag.
B.It may be used as an empty tag.//answer
C.It must have a body
D.It must implement BodyTag interface.//answer
E.It may take an attribute named 'name'. But if present, its value must be dynamic.

Why is D one of the correct answer ?

If only one option has to be chosen I think B is the correct answer as Tagdepedent body can be empty

-------------------------------------------------------------------------------------------------------------
2.A Tag Handler implements BodyTag interface. How many times its doAfterBody method may be called?
Select 1 correct option.
A.BodyTag does not support doAfterBody.
B.0
C.1
D.0 or 1
E.Any number of times.----correct answer

If i leave the body of tag as empty then the doAfterBody wouldnot be called
so ,anser can be B also.

-------------------------------------------------------------------------------------------
3.Which of the following are true regarding the parameters defined using the <context-param> element of a deployment descriptor?
correct answer:.
A.They are thread safe.
B.They are accessible from multiple threads simultaneously and from any servlet of the web application.


Arent the 2 options contradictory ?
If parameters are thread safe that means they cant be used when one thread uses them
how is it possible?

------------------------------------------------------------------------------------------
4.Which of the following is a sensible way of sending an error page to the client in case of a business exception that extends from java.lang.Exception?
Select 2 correct options.
A.Catch the exception and use RequestDispatcher to forward the request to the error page.---correct ans.
B.Don't catch the exception and define the 'exception to error-page' mapping in web.xml
C.Catch the exception, wrap it into ServletException and define the 'business exception to error-page' mapping in web.xml--correct ans

How is A and C correct ?
I think the easiest way is to define a exception to error page mapping with exception-type of throwable class
----------------------------------------------------------------------------------------------------------
5.Which of the following XML frgaments correctly define the <login-config> element of web.xml?



Select 3 correct options.
A.1-----correct answer
B.2-----correct answer
C.3-----correct answer
D.4
E.5

How is 2 option correct ?
form-login-config is for FORM (auth-method) only.


-------------------------------------------------------------------------------------------------------------
6.Following is the code for doGet() method of TestServlet. Which of the given statements about it are correct?

Select 2 correct options.
A.This will not compile.
B.This will compile but will not work as expected.
C.This code will work just fine.
D.It will compile but not work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");
E.It will compile and will work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");

correct answer: C and E

According to Servlet 2.4 specification

SRV.8.1 Obtaining a RequestDispatcher
The getRequestDispatcher method takes a String argument describing a
path within the scope of the ServletContext. This path must be relative to the root
of the ServletContext and begin with a ‘/’.



Answer should be A and E
 
Ranch Hand
Posts: 207
jQuery Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think these are too many questions for one thread. Would have been easier if separate threads were used.

Question 1:
From the description of the tag it's clear that it is intended to process the body of the tag. Which can only be done if tag-class implements BodyTag interface.

Question 2:
Yes if you leave the body of the tag as empty then the doAfterBody would not be called.
But since you have to select only one option then it should be closest and most sensible. Since you are implementing BodyTag interface then its logical to think that you want to access the contents of the body, so chances of having an empty body are very less.

Question 3:
Being "Thread safe" doesn't necessarily mean that only one thread can use them at one time. Thread safe means that they are safe from any unwanted side-effects while being accessed by multiple threads simultaneously. For example : Any Immutable object is thread safe.
So since we can not modify the values of existing context-params, only read access is provided, so it wont have any negative effect if multiple threads are reading the same context-param simultaneously, therefore they are thread-safe.
 
Ranch Hand
Posts: 55
jQuery Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mohit

I am also working on OCPWCD 6.
Can you share the enthuware or any questions you have got?

Here is what I think about your questions

1)In this you need to manipulate the body so you have to implement the BodyTag interface.

2)You are right.If you leave the body empty then doAfterBody() will not be called but as they are asking for one best answer the best choice is "n" times.

3)Both options are correct as you cannot write a context param value you can only read it.So no matter how many threads access it it will always be thread safe.


4)First of all wrapping is necessary and then you have to declare the custom exception in web.xml

Also have a look at the specification
If no error-page declaration containing an exception-type fits using the
class-heirarchy match, and the exception thrown is a ServletException or
subclass thereof, the container extracts the wrapped exception, as defined by the
ServletException.getRootCause method. A second pass is made over the error
page declarations, again attempting the match against the error page declarations,
but using the wrapped exception instead.


5)I agree with you.

6)B and E should be correct rather you wil get a IllegalArgumentException when you will request for the servlet.Code will compile.


Regards
Ankur Garg
 
Ankur Gargg
Ranch Hand
Posts: 55
jQuery Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Regarding your 5 question in dtd of web.xml I found out this
The form-login-config element specifies the login and error pages
that should be used in form based login. If form based authentication
is not used, these elements are ignored.


so the option selected are right.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic