• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Enthuware mock doubt!!

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


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

<%!
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 ..
 
Sheriff
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
ankit kumar
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry ankit
yes it is
 
Ankit Garg
Sheriff
Posts: 9692
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all of you to clear my stupid doubt..

I have noy noticed that line in the 5th option
 
You don't like waffles? Well, do you like this tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic