aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP doubt? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP doubt?" Watch "JSP doubt?" New topic
Author

JSP doubt?

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Guys,

The code below is from David Bridgewater's,


The question is What is output to the web page on the second access to the same instance of the following JSP?
(Choose one.)

How the answer is 3?? I thought 4!


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Saurabh Kumar
Ranch Hand

Joined: Aug 21, 2006
Posts: 56
when this jsp is accessed first time, it will run JspInit() thus incrementing x by 1.Then, <%= x++ %> would increment x by 1.
By now x=2.
Now if you access the same instance 2nd time, JspInit() wouldnot be called. just <%= x++ %> would increment x by 1.
So the final value of x will be 3.

Thanks and regards,
Saurabh
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

By now x=2.
Now if you access the same instance 2nd time, JspInit() would not be called. just <%= x++ %> would increment x by 1.
So the final value of x will be 3.[/QB]


Shouldn't it output 2 instead of 3?

<%= x++ %> ---> out.print(x++); // print x, then increment x
But:
<%= ++x %> ---> out.print(++x); // increment x, then print x


[Edit]
Sorry. It should output 3. I forgot to take into account the

at the end of the jsp.
[ April 13, 2007: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Thanks guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP doubt?
 
Similar Threads
Mock exam question doubt?
Question to an output
Mock exam question doubt?
_jspService methiod calarification
Mock exam question doubt?