File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Questions HFSJ (2nd edition) and some frustrations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Questions HFSJ (2nd edition) and some frustrations" Watch "Questions HFSJ (2nd edition) and some frustrations" New topic

Questions HFSJ (2nd edition) and some frustrations

Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

Hi ranchers,

I was very active here a few years ago for my SCJP, now I decided to go for the SCWCD and I turn back to you guys for help
So you can expect some questions coming your way the next months. I hope you'll help me again as much as you did then.

Unlike most people, I'm not so fond of the head first book. I like the style, I have already learned a lot from it, but I don't agree on some questions and think that sometimes they have just been sloppy in the book while fixing the mistakes according to the errata.

for instance p249, they corrected the book according to the the errata, but nobody took the time to see that that this code
doesn't even compile anymore since the declaration of 'foo' has been removed.
Or even worse is p 445 where they adapted the "Renders as" "Hello null" but didn't change the title, and the textblock that talks about 'things that evaluate to null prints nothing' still arrows to the 'Hello null' block. Makes no sense.

Furthermore I take the coffee cream tests rather seriously and evaluate myself on that. I find it very frustrating to correct my results
and lose points on topics I completely understand but where I am wrong because
(a) the question contained material which is not in the book (don't claim that everything for the exam is in the book and then do that!) e.g p275 answer B about SSL... or
(b) the question is formulated in such a way that even with the book open next to me I still couldn't get it right.

There, I said it.

I also have some questions some are somewhat related to what I said above.

1)What exactely is the difference between encodeURL and encodeRedirectURL ? I don't understand what is in the book, and the result
of both functions are the same: urls rewritten with the jsessionid attached to it...

2) p274 question 2 , answer 2 is an example of what I just said above in (b), the question says: If a client will NOT accept a coockie, which session management mechanism could the web container employ ?

Well here I say to myself: the container has no way of knowing what the client WILL do, so it uses both in the first request. A smart container will then fall back on only url rewriting but it doesn't have to and could use both (see p238 answer to Q). The jsessionid cookie won't return from the client but who cares, the server can still use both if it feels like that.

So answer E 'Cookies and URL rewriting must be used together' looks ok to me. I will work so its a possible strategy.
But the answer is B 'URL rewriting, but NOT cookies' ??

3) question 7 answer C: I don't understand what they mean with "servlets belonging to a ServletContext" , for me a ServletContext is a place to store read only init parameters from the web.xml and to store attributes, both of which are available to the complete application. Not something to which servlets belong.
Since I don't think what it says is correct, I don't choose this answer. Of course, they say its correct, no explanation give.

4) small question:
p359: is it ok that the tags <input> are not self closing ? is this how it should be or sloppyness ? html will probably be forgiving on this point.

Could you please give your opinion on these questions ?
Is it just me or what?


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Charles Lyons' book is also a recommended book. You may prefer the author's more "conventional" style. By "conventional", I mean not like HF The book is listed in the ScwcdLinks.

[My Blog]
All roads lead to JavaRanch
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper

Joined: Apr 07, 2010
Posts: 2043

Hi Mark,

Welcome back!

I am just giving you some guidelines when posting questions:
  • Do one posting per question, that makes it easier to answer
  • Please post the question + answers as not everybody has that book your are using

  • Regarding your first question
    What exactely is the difference between encodeURL and encodeRedirectURL ?

    The difference between the two is that encodeRedirectURL is used by HttpServletResponse.sendRedirect(). (which goes back to the client, to issue a new request to the redirect location)

    The explanation in the API is quite good as a matter of fact:
    String encodeURL(String url)
    Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.
    For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

    String encodeRedirectURL(String url)
    Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separated from the encodeURL method.
    All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

    Bert Meijers

    Joined: Feb 06, 2011
    Posts: 15
    Hi Mark,

    Good to read your opinion about the HeadFirst books. Really, I enjoy them, but you're right about sloppiness and completeness.
    I can imagine, mock-questions that can only be solved by googling or by trial-and-error-testing on your eclipse-app, force the reader
    to think beyond the borders of the book. Or to expand his view... Anyway, this works to a certain degree. There-after starts irritation and

    HF scwcd 1.4 : final mock-exam, page 787 question 48. According book D is the right answer.

    According to Charles Lyon's Study Companion, there can be a <description> within <listener> but
    it comes BEFORE <listener-class>.

    Even my Beer-application agree's on that :-)

    So good luck to you, happy to know I am not the only one who turned gray on this book...


    I agree. Here's the link:
    subject: Questions HFSJ (2nd edition) and some frustrations
    It's not a secret anymore!