| Author |
Niko's exam doubt
|
Parth Twari
Ranch Hand
Joined: Jan 20, 2010
Posts: 163
|
|
Hi everyone,
I am back after an awesome 6 day visit to Banglore City(India). Hope you guys have heard about that city?
After the return i jumped straight on to javaranch exam and niko exam.
the ranch exam said that i got 24 out of 25 correct and then when it showed me the question I was wrong at, I was surprised , i had not even attempted that question! Is there some error?
And in the niko's servlet exam I got a doubt-
39. The Container creates a single instance for every servlet. The client requests are served with various threads. (1 correct answer)
a. true
b. false
Anwer : a
Why ?
Has Niko forgotten about STM interface in which case the container may choose to create more than one instance of the servlet?
|
Parth Tiwari
| Pursuing Bachelor of Engineering | OSUM Club Leader | SCJP 6 | SCWCD 5 |...
|
 |
Frits Walraven
Rancher
Joined: Apr 07, 2010
Posts: 1042
|
|
Hi Parth,
Has Niko forgotten about STM interface in which case the container may choose to create more than one instance of the servlet?
The SingleThreadModel is deprecated so it should not be used anymore.
So this part of the specs applies
SRV.2.2 Number of Instances
For a servlet not hosted in a distributed environment (the default), the servlet container must use only one instance per servlet declaration
Regards,
Frits
|
 |
Parth Twari
Ranch Hand
Joined: Jan 20, 2010
Posts: 163
|
|
STM is deprecated but its still on the exam.. so don't we have to consider that its there..?
another thing
Q59.
There is a top-level folder help in the war file with index.html inside. What is the output of this code? (1 correct answer)
request.getRequestDispatcher("help/index.html").forward(request, response);
1. The content of index.html
2. HTTP Status 404
Anwer: 1
but don't you think the answer will depend on the position of servlet where this code is written?
if code is written in a servlet with uri : /dice/source/myservlet.do
then formed url will be /dice/source/help/index.html
then it will not point to the index.html file.
|
 |
Frits Walraven
Rancher
Joined: Apr 07, 2010
Posts: 1042
|
|
STM is deprecated but its still on the exam.. so don't we have to consider that its there..?
Yes, they won't ask you things that are deprecated.
but don't you think the answer will depend on the position of servlet where this code is written?
You are right it depends on the mapping of your Servlet because the String going into the RequestDispatcher doesn't start with a "/".
Regards,
Frits
|
 |
Parth Twari
Ranch Hand
Joined: Jan 20, 2010
Posts: 163
|
|
ok thanks,
the above 2 questions are resolved to me.
In the mean time Mr. Niko managed to raise 2 more doubts in my mind and I think these doubts are going to be easy to solve for you guys (specially for Frits)
Here they go -
Q.25 What is the output of this page? (1 correct answer)
<html>
<body>
Result is ${"a" > "b"}
</body>
</html>
1. “Result is true”
2. “Result is false”
Anwer: 2
Q.26 What is the output of this page? (1 correct answer)
<html>
<body>
Result is ${"a" < "b"}
</body>
</html>
1. “Result is true”
2. “Result is false”
Answer: 1
Ok now the spec says when you give strings to EL logical operator then they are compared lexically?
If A or B is String coerce both A and B to String, compare lexically
What is lexical comparison ? can you justify the answers? and what if we had Result is ${"11" < "b"} ?
|
 |
Frits Walraven
Rancher
Joined: Apr 07, 2010
Posts: 1042
|
|
When you compare to Strings lexicographically you have to look at the Unicode (See ListOfUnicodeChars) value of each character in the strings.
So "1" has a code of (U+0031), which is smaller the "A" (U+0041) and "a" (U+0061)
Also have a look at the String.compareTo() method.
Regards,
Frits
|
 |
Parth Twari
Ranch Hand
Joined: Jan 20, 2010
Posts: 163
|
|
The above to made thier way in head as well.. thanks
Now look at this one-
18. What is the output of the following code? (1 correct answer)
<%= page instanceof JspPage %>
1. true
2. false
Answer: 1
similarly, <%= page instanceof HttpJspPage %>, <%= page instanceof Servlet%>,<%= page instanceof GenericServlet %>,<%= page instanceof HttpServlet %>
all return true!
We know page is of type Object what all can it be cast into? why does all this return true?
|
 |
Frits Walraven
Rancher
Joined: Apr 07, 2010
Posts: 1042
|
|
the implicit object "page" represents the jsp page you are in, and as you know all jsp's are turned into a servlet
Have a look at the example of David Bridgewater's book where he uses a jsp with the name of myjspname.jsp.
The generated Servlet (on tomcat) is a JspPage, HttpJspPage, HttpServlet, GenericServlet and a Servlet!
Regards,
Frits
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
Parth it is generally easier for everyone to follow a topic if there is one question per topic, you'll get better replies that way...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Parth Twari
Ranch Hand
Joined: Jan 20, 2010
Posts: 163
|
|
ok ,I had read about "one question per topic",but i thought since all doubts here were of niko so it would be easier for people to refer to only this topic when they are using niko exams and get most of their doubts solved.
But if its better that way I will go for next question in new post
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
The questions are from the same mock exam, but they are from different topics. If a topic contains question related to only a single topic, its generally easier to follow...
|
 |
Parth Twari
Ranch Hand
Joined: Jan 20, 2010
Posts: 163
|
|
|
ok..
|
 |
 |
|
|
subject: Niko's exam doubt
|
|
|