aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Enthuware mock doubt!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Enthuware mock doubt!!" Watch "Enthuware mock doubt!!" New topic
Author

Enthuware mock doubt!!

Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Which of the following are valid JSP code fragments?
Each option shows code for an independent JSP file.

1. <%@ page import="java.util.*" autoFlush="true"%>
<%@ page import="java.io.*" autoFlush="false"%>

2. <%Date d = new Date();
out.println(d);
%>


3. <%= String val = request.getParameter("hello");
out.println(val);
%>

4. <%!
Hashtable ht = new Hashtable();
{
ht.put("max", "10");
}
%>


5. <%!
Hashtable ht = new Hashtable();
ht.put("max", "10");
%>

the given answer are in bold. I wonder how option 4 is the right answer?? Is this block indicate a intance intializer??
moreover why option 5 is not a correct answer??


Thanks


Thanks <br />Poonam Agarwal SCWCD 86%
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3855

Poonam Agarwal wrote:
4. <%!
Hashtable ht = new Hashtable();
{
ht.put("max", "10");
}
%>


I wonder how option 4 is the right answer?? Is this block indicate a intance intializer??


Yes. Declarations will ended up outside the service method of the generated servlet.

moreover why option 5 is not a correct answer??




You cannot put the second statement there unless within a block. You can try in a simple class try to put that as instance members. Second line will fail to compile



SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
ankit kumar
Ranch Hand

Joined: Apr 28, 2008
Posts: 108
<%!
Hashtable ht = new Hashtable();
{
ht.put("max", "10");
}
%>


In this the code between {} is static Initialize thats why it is correct and in last option it is not ..


Cleared SCJP 1.5 | Cleared SCWCD 5.0
SCDJWS 6 in progress.....
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

kumar ankit wrote:
<%!
Hashtable ht = new Hashtable();
{
ht.put("max", "10");
}
%>


In this the code between {} is static Initialize thats why it is correct and in last option it is not ..


Well it is not a static initializer, it is an instance initializer block.

And about option 5, you can understand the cause of the error by looking at the type of code that will be generated by that declaration



The code won't look exactly like this but this is just to give you an idea...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
ankit kumar
Ranch Hand

Joined: Apr 28, 2008
Posts: 108
sorry ankit
yes it is
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

kumar ankit wrote:sorry ankit


Relax buddy . No need to say sorry to me. No one is perfect dude. Mistakes happen, its not a big deal
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Thanks to all of you to clear my stupid doubt..

I have noy noticed that line in the 5th option
 
 
subject: Enthuware mock doubt!!