aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes contradictory answers? 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 "contradictory answers?" Watch "contradictory answers?" New topic
Author

contradictory answers?

J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

There are two questions in the enthuware test studio that seem to contradict each other. The first one is:

Consider the following JSP code:

If the tag handler class for MyIterTag implements IterationTag contains a return statement - return Iterationtag.EVAL_BODY_BUFFERED; in it's doStartTag() method, what will be the output?

The answer says that it will not compile because EVAL_BODY_BUFFERED is defined by the BodyTag interface so it's an invalid statement. It can only return SKIP_BODY or EVAL_BODY_INCLUDE.

Ok, I get that. But then the next question:

Given:

If the aTagWithBody extends from TagSupport and returns BodyTag.EVAL_BODY_BUFFERED from doStartTag(), what will the above page print?

I said it wouldn't compile, based on the first question, as it seems similar. TagSupport cannot return BodyTag.EVAL_BODY_BUFFERED because it does not implement the BodyTag interface. However, the answer says it will compile but throw an exception at runtime, with the reasoning being "It will compile because the compiler only checks whether the doStartTag() is returning an int or not. It does not check whether the int value is valid or not. However, the tag can be coded to return BodyTag.EVAL_BODY_BUFFERED without an compile time error because the compiler does not have any knowledge of what this tag is allowed to return."

These two answers seem contradictory to me. Maybe I've just looked at these questions too long. I'm going to test this myself, but I would expect that neither one would compile. Can someone explain this?



"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3293
    
    7
This is regular Java programming stuff If you try to access a field that is not defined in an interface (i.e. Iterationtag.EVAL_BODY_BUFFERED), it will not compile because Iterationtag.EVAL_BODY_BUFFERED does not exist.

If a method's return type is an int, you can return any int and it will compile. The return value is not invalid from a Java point of view but is invalid from an application logic point of view, which can't be determined by the compiler and so the code fails at run time.

HTH,
Paul.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

The first example I understand. It's the second one that doesn't make sense. I tried this:

And this:


Neither one will compile, so I still don't see how the second example is supposed to compile.

Sure you could do a "return 0" or whatever, but that's not what the question is asking. It's referring to the predefined constants.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3293
    
    7
That is because you are not trying the second one exactly as specified by the question. The question clearly says that the method returns BodyTag.EVAL_BODY_BUFFERED, while you are trying to return EVAL_BODY_BUFFERED.

But I think I understand your confusion now. You are probably not assuming appropriate import statments and I think the question statement should make it clear that the tag code contains import javax.servlet.jsp.tagext.*;

In the first case, "return EVAL_BODY_BUFFERED;" will not work because IterationTag does not have EVAL_BODY_BUFFERED constant defined. In the second case, it does not depend on IterationTag for the definition of EVAL_BODY_BUFFERED constant because it explicitly returns BodyTag.EVAL_BODY_BUFFERED, which exists.

HTH,
Paul.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 954
    
  13

That was it; the import statements. I had tagext.IterationTag, tagext.Tag, and tagext.TagSupport. Once I changed that to tagext.* it compiled.

Thanks, I understand now.
Damien Clarke
Greenhorn

Joined: Mar 10, 2010
Posts: 6
Just wondering - do you guys know if these questions are still relevant for the current Java 6 version of the exam(1Z0-899)?
Doesn't seem to be any mention of either 'Simple/Custom' tag handlers in the exam objectives.
Any idea if there are questions of this nature on the new exam?

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: contradictory answers?