The mock exam has been moved to a separate application working on the OpenShift and is available at

This post will be still available because of the comments — at this point the exam simulator doesn’t have the commenting functionality so you can leave your opinion here. In time it’ll be modified and will allow to post comments directly next to the questions.

If you’d like to get more information about the exam migration take a look at this post: New OCE WCD Exam Simulator.

Important: if because of any reason, the above exam simulator is not available, you can grab the copy of the exam in PDF from here.

If you’d like to download the source code of the questions you can do so here:

SCWCD Java EE 6 Mock Exam - This package consists of source code of ~30 questions from my SCWCD JEE6 mock exam.
Did you like this? Share it:

61 thoughts on “Java EE 6 SCWCD Mock Exam

  1. In question #29, you say that f is valid.
    class NullServlet extends HttpServlet {
    since the default name of the WebServlet is the fully qualified name. But in the question f states: The name of this servlet is “com.nullhaus.NullHausServlet“ either this should be “com.nullhaus.NullServlet” or the class name needs to change to NullHausServlet.

    Aside, this is EXCELLENT review for me. Thanks for the effort it is appreciated.

    • Hi Roy,

      You’re right – the name of the class should be NullHausServlet instead of NullServlet. I just fixed it.
      Thanks a lot for pointing this out!
      I’m glad you found this exam useful :-)


  2. In question 41, statement F. In reading over Sec. 8.2.3 – 5.d “Web fragments are merged into the … The merging takes place before annotation processing on the corresponding fragment”. So in reasoning about just that it seems that F should be valid. Or is there another section of the spec. that also applies that I’m missing?

    • Hi Roy,

      Well I guess it’s just an unfortunate sentence construction… The meaning of this question is somewhat:

      “Are the web fragments scanned all at the same time or one after another?”

      As you quoted:
      “The merging takes place before annotation processing on the *corresponding fragment*”.

      Which means that there is no ‘scan all *web fragments* and put them in the web.xml and then process all annotations for those fragments’. There is a sequential process: ‘scan one web fragment, put it in the DD, read it’s annotation… take next web fragment, put it in the DD, read it’s annotation, …’ and so on.

      Does it answer your question? Maybe the last answer should be rephrased. What do you think?

  3. That answers it. Maybe it was my ignorance that caused the confusion about the answer.

    Check out Answer 49, there seems to be an inconsistency A,C or A,B

    Aside, w.r.t. ServletRegistration#setServletSecurity(-) method, does it make a difference in that it is really the ServletRegistration.Dynamic#setServletSecurity(-) is the actual method?

    Note: Thanks for the responses! It is always helpful when you are in the learning mode.

    • Hi Roy,

      Another point for being on guard! You’re right, the answer should be A and B as the answer description tells.

      And second time you’re right – it is my mistake – it should have been ServletRegistration.Dynamic#setServletSecurity(-) which I fixed right now.

      Glad you are so observant! :-)


  4. Question 56, 57, 58, 59. I had “code does not compile” since there is NO throws declaration in the doGet(…) {.

    protected void doGet(HttpServletRequest req,
    HttpServletResponse resp)
    throws ServletException,

    Clearly that wasn’t the intent for all these questions. I didn’t check the other code samples to see if this issue is repeated else where.

  5. No, sorry, that is my next step to see what my server implementation does with some of the examples.

    • Roy, did you have the time to check the code for questions 56 – 59? Is it really not compiling?


  6. In question 13:

    public class NullFilter implements Filter {

    Was the intent to use the same class in the question or 2 different classes? Also check question 14 too.

    • You’re right – both, the DD and Filter class should have the same class name (NullFilter instead of MyFilter). Thanks for pointing this out!

  7. Piotr, just a question about #18.
    The *, I haven’t coded up an example for this yet, but in reading the spec. sec. 12.2 “Specification of Mappings”, should this have a /* instead? I’m not clear yet on what is actually needed.

    • Once again right – I’ve copied the example from the above question where it was “*” but after changing it to I forgot to change the wildcard to “/*”.

      Thanks for being on guard!


  8. Actually, in NetBeans 7.0, Glassfish server, it does need the /* for question 18 to be deployed. Just using * failed to deploy for me.

  9. I am a SCWCD seeker and have recently started the preparation. This site has really made my confidence high. Now I know that if I attempt the latest 6th version for this exam, I have this place to refer to regarding the new additions to the exam.

    Thanks a lot for taking your time and making these things available for us.

    Very Well Done…!!!
    (I will soon be back after finishing with my preparation to take a final look here.)


  10. Any Ebook or study material available to prepair for this exam ? Can i just study Servlets 3.0 FR specification ?

  11. Question 67:
    public class MyListener implements AsyncListener …

    In the Java Docs for this annotation it does NOT list AsyncListener as a valid listener. In coding this up using NetBeans IDE 7.0 and using GlassFish v.3.1 it reports back to me a severe error during deployment:
    SEVERE: The Class MyListeners.Listener67 having annotation javax.servlet.annotation.WebListener need to implement one of the following interfaces: javax.servlet.ServletContextListener, javax.servlet.ServletContextAttributeListener, javax.servlet.ServletRequestListener, javax.servletServletRequestAttributeListener, javax.servlet.http.HttpSessionListener, javax.servlet.http.HttpSessionAttributeListener.
    as well as:
    SEVERE: Annotations processing failed for file …

    Commenting out the annotation and using an element in the DD (web.xml) also results in the same deployment error.

    Commenting out the annotation and having no entry in the DD results in a good deployment.

    So is there an error here? Is my ignorance showing? Is a correction needed?

  12. Pingback: OCPWCD 6, pierwsze wrażenia z przygotowań | CaveRed

  13. Question 54:

    I think g is the correct answer, since rolesAllowed = “*” will returns a non-emtpty array, hence the emptyRolesSemantic should not be specified, this will cause an invalid usage of @ServeltSecurity.

    • You’re right – thanks for pointing this out!

      I’ve removed the “g” answer from the question, as I decided that this was not the real purpose it was asked and you can still gain some knowledge from it. I’ve added additional explanation in the answers section.

      Once again – thanks for your awareness!

  14. Howdy Piotr?

    I am starting preparations for this exam. Currently I have started with HFSJ. Could you please let me know how to learn the specs? I there any simple way / trick to learn it? I mean if I read HFSJ then it covers Servlet 2.4. How can I find exact differences between Servlet 2.4 and 3.0 from learning perspective? One more question: There are three more specs other than that of Servlet 3.0 namely: EL, JSTL and JSP. I think those are also in the syllabus but never seen anyone mentioning those who have passed this exam.

    Could you please guide me?


    • Hi Swapnil,

      Well, there is no real trick in learning the specs – I just found it interesting to read it and test some of the discussed features. I do believe that there are few websites talking what changes were made between 2.4, 2.5 and 3.0 like here: and here:

      After reading HFSJ, I think you can just skim the specs and you’ll fast see what are the differences. I’ve skimmed the JSTL and JSP specifications but didn’t really use it for the exam. The EL is more important so I took some time with it (although e.g. deferred expressions weren’t at the exam…)

      If you have more time, I’d just advise to read the Servlets 3.0 specs after the HFSJ (it’ll give you the big picture) and then go with the Enthuware’s mock exam. If don’t have much time, I’d just take the Enthuware’s mock exam after the HFSJ.

      Good luck mate!

      • Thanks a lot Piotr!!

        I believe reading JSP, EL specs is not that much important from exam point of view.

        I would thoroughly study Servlet specs though and would definitely try your mock exam.


        • Thanks a lot piotr. Your mock exam was very helpful in understanding servlet 3.0 concepts. Today I passed OCE- WCD exam. Thanks a lot to you.


  15. Hi Piotr!
    Many thanks for this exam preparation question/answers. I am currently in preparation and they are of great use for me. Please let me know what is HFSJ? I was taking the course from Oracle and went through the servlet spec 3.0 in detail (apart from learning JSP/EL). And apart from some bits and pieces (e.g. asynchronous processing) I am confident I could take the exam in some time.
    Regards, Michael

    • Hello Michael!

      I’m glad you find the exam useful :-)
      HFSJ is an abbreviation for “Head First: Servlets and JSP” – a book by Kathy Sierra and Bert Bates (
      If you took the training and read the specs (or at least skimmed over it), just do some mock exams and I’m more than sure that you’ll pass it easily :-) I would definitely recommend exam – it’s definitely worth its price!

      Good luck and don’t forget to tell us about the result! :-)

      • Hi Piotr,
        thanks for the info! Much appreciated. For two of the tasks I have questions:
        Nr. 58 I rerun the given example and you are right, however, according to servlet spec 9.7 “All the variations of the dispatch methods returns immediately and do not commit the response.” So commit could theoretically be called AFTER the dispatch. I couldn’t find in the spec a statement saying that AsyncContext#complete will lead to a runtime exception if the request was dispatched before!?
        Nr. 59 when in NullServlet response.flushBuffer is called BEFORE the AsyncContext is created and started the response is already committed to the client. According to the spec “It is illegal to call startAsync […] if the response has been committed […]” However, the example then still would run and both strings be printed. Why?
        In which case would “Howdy from NullServlet1″ be lost – just be using a Wrapper for the original request and response?

        • Michael,

          As for your first question, take a look at the Javadoc for AsyncContext#dispatch():

          Throws: IllegalStateException – if one of the dispatch methods has been called and the startAsync method has not been called during the resulting dispatch, or if complete() was called

          You’d need to give me some time for the second question, as I haven’t recently used asynchronous features of Servlets 3.0 :-)

        • Well, Michael, about question 59. I’ve just tested it on Tomcat 7.0.27, and it seems a bit strange indeed.

          The flushBuffer() does not make any changes to the response – both texts are included. However, section 5.5. Closure of Response Object says when the response should be trated as ‘closed’ (note that sometimes they use ‘commited’ and sometimes ‘closed’ – not sure if these are the same). Flushing the buffer is not one of the cases when the response object is “closed”.

          So if instead of flushing the buffer, you’ll sendError(-), you won’t get anything printed out BUT the request will be dispatched correctly (wicked!)

          It’s a bit strange for me, as the response has already been commited (isCommited() returns true) but you still can create an AsyncContext despite the following information in the javadoc for ServletRequest#startAsync():
          IllegalStateException – (…) or if the response has already been closed

          If you’ll dig into it, it would be great if you could post some info here :-)


  16. Hi Piotr,
    many thanks for your answers! Today I successfully passed the exam – with the help of your questions as well! Thanks again,

  17. Hi Piotr,
    I have a tiny concern about #8. Isn’t it possible to add ServletContextListener programatically inside ServletContainerInitializer#onStartup(). I know that it is actually pointes but I am asking just out of curiosity.
    btw, this test is really great source of information.


  18. Hi Piotr,

    Nice work. Appreciate your tedious efforts. This helps us all a lot.

    The answer for Q31 seems confusing. I read from the specs (Servlet 3.0 – 8.2.3 – pg 74) “ v. elements with the same are additive“. So I was thinking whether both /foo/* and /bar/* url patterns will be invoking the servlet.

    Kindly help me out.
    Thanks a ton. Continue your good work

    • Hello Vimal!

      Take a look at mentioned page 81, 8.3 Annotations and pluggability, point enumerated ‘n. iv':

      “url-patterns, when specified in a descriptor for a given servlet name overrides the url patterns specified via the annotation.”

      I do believe that the part you cited, refers to the combination of web-fragments. Although I think it should be more precisely split as it can be hard to find the relevant information in all those multilevel bullet points.

      Hope it helps


      PS. I also encourage you to download the sample code from my github account I mentioned in the post and try deploying the app yourself. It’s quite helpful!

  19. Hi Piotr,

    I was wondering about question 35.Part of the explanation is:

    “Explanation: When the servlet is programmatically created using the same name as previously
    defined (using annotations or DD), the behaviour is not specified.”

    If we had the same scenario but instead of annotations we used DD and programatic addition then
    wouldn’t this always yield null(as opposed to unspecified behaviour)?
    ServletRegistration.Dynamic d = ctx.addServlet(“NullHaus1″, s);

    In the API:”Returns:a ServletRegistration object that may be used to further configure the
    registered servlet, or null if this ServletContext already contains a complete ServletRegistration
    for the given servletName”

    Maybe I am missing something here…Thanks for your time and great test:)

    • Hello Valentina.

      Did you try using DD and programmatic addition? I wonder how Resin would interpret this situation. It might be interesting to see if metadata-complete="true" would change this behavior in any way.


  20. Shouldnt the option b in 36 be javax.servlet.http.HttpServlet? When do you think Oracle will update their online documentation (field,method and classes summary) of the Servlets 3.0 related parts?

    • Hello Avik.

      You’re right – that is an obvious mistake of mine. It should have the .http. package in it. I’ve already tried to fix it but the markdown and wordpress started to do weird things, so the formatting of the whole exam might be a bit messed up.

      Nevertheless, about the update of the online docs – what exactly do you mean? The Java EE 6 Javadoc API is already published here:

      Is it what you’re looking for?


  21. Hi,

    In the answer for question 26 you are saying:

    ….If the value is set to “false</>” the container will ignore any web-fragment.xml files as well as any used annotations.

    As per me it has to say:

    ….If the value is set to “true” the container will ignore any web-fragment.xml files as well as any used annotations.

    Anyways, thanks for sharing your job, is really helpful.

  22. Hello,

    I really appreciate what you have done here… Your mock exam on Servlet 3.0 helped me a lot.

    I think that the answer on question 2 is not correct. According to the java api ServletResponse.getWriter() throws which is a checked Exception. Since your doPost() method does not declare this exception, the code will not compile.

    Without that (I mean if the method throws the exception), the correct answer is of course N°d.

  23. Hello Kenny,

    Thanks a lot for your input. I think you’re right – this method signature should have a throws clause. I will update the question accordingly (probably with some update of the web exam simulator itself)



Leave a reply



<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>