This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Most Most Confusing Question

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is from enthuware.

Consider the following JSP code:

<mylib:MyIterTag>
<%="Hello World"%>
</mylib:MyIterTag>

If the tag handler class for MyIterTag implements IterationTag and returns IterationTag.EVAL_BODY_BUFFERED from doStartTag(), what will be output in the response?

1)Hello World

2)<%="Hello World"%>

3)The tag handler will not compile.

4)The tag handler will compile but throw an exception at request time.

5)No compile-time or run-time erros and nothing will be printed in the output.

The correct answer given is 3.

But according to me the correct answer should be 4. Because even though the Iteration Tag is returning the EVAL_BODY_BUFFERED value, it is a int value, and as far as the container and compliler is concerned they only look out that a int value is returned. So this should complain about the exception only at reuqest time.

Why the answer 4 is wrong?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the default <body-content> of taghandler?
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


IterationTag interface is not containing attribute called EVAL_BODY_BUFFERED.

EVAL_BODY_BUFFERED is there in BodyTag interface.



So the answer is the correct one. The Tag Handler will not compile.


Some inputs :

Tag Interface :

SKIP_BODY
EVAL_BODY_INCLUDE
SKIP_PAGE
EVAL_PAGE

IterationTag interface :

EVAL_BODY_AGAIN

BodyTag interface:

EVAL_BODY_BUFFERED
[ August 19, 2008: Message edited by: deepa raj ]
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why it won't compile, it is retruning the int value .
I think compiler will check return value is int or not. But it won't check the validity of int value, validity of int value will be checked at run time.
So option 4 may be correct..
Correct me if I am wrong.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no EVAL_BODY_BUFFERED constant in IterationTag interface, so it will not compile
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know EVAL_BODY_BUFFERED is just an int value. Suppose it is 4.
And the above program returns 4. The compiler will not complain about an int value. But only at run time it will throw exception.

I haven't seen Chrisopher Veere for so many days. He the best man can answer this question.
 
deepa raj
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
return 4; is different from return IterationTag.EVAL_BODY_BUFFERED;

if your tag handler uses integer number to return , then tag handler should compile.

if your tag handler uses return IterationTag.EVAL_BODY_BUFFERED;,it shouldnt compile.

better you can write one tag handler .it will clarify your doubt.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My option is "The tag handler will not complie" because it does not return 4 ,it says return IterationTag.EVAL_BODY_BUFFER and that constant is only a part of BodyTag..
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Correct answer is 3 will not compile

If the tag handler class for MyIterTag implements IterationTag and returns IterationTag.EVAL_BODY_BUFFERED
Since it doesnt implement BodyTag it cannot see the static variable
EVAL_BODY_BUFFERED
IterationTag doesn't have this static variable defined so it will give compile
time error.

This is from the specs

public interface BodyTag extends IterationTag

public static final int EVAL_BODY_BUFFERED

IterationTag doesnt define this static variable. So
by J2SE rule it will not find this variable while compiling

Thanks and Regards
Joy
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Amruth Puppala
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much deepa and joy
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-----------------------------------------------------------------
IterationTag doesnt define this static variable. So
by J2SE rule it will not find this variable while compiling
-------------------------------------------------------------------

Where does it this say, it will not compile.

I have also got somewhat similar question to this in Enthuware,

when i will get that and then will let you know guys.

i tried my self to compile this code it worked fine. But when i did doGet

request, it had given exception at request time.
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attempting compilation would help answer a question like this
 
Joy Mukherjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code Amandeep......
 
We noticed he had no friends. So we gave him this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic