This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Declarations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Declarations" Watch "Declarations" New topic


Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
What's the difference between
<% int x = 44; %>

<%! int x = 44; %>
Is one a local variable and the other is not?
g madhava
Ranch Hand

Joined: Sep 14, 2001
Posts: 85
<% int x = 44; %>
==> This goes in to the _jspService() method
something like this,[which is effectively a local variable]
public void _jspService()
int x = 44;
<%! int x = 44; %>
goes into the instance declaration. So this is a class level variable.
Mark Stein
Ranch Hand

Joined: May 20, 2002
Posts: 75
Yes, technically one is a local varible, and one is not, but you need to know more.
Declarations (<%! int x = 44; %> are initialized only once, when the page is first loaded. They are outside the jsp service method, so you can also declare a method using the <%! %> tag.
<% int x = 44; %> is a scriptlet. What you've done is declare a local variable that will be called in the jsp service method each time the page is called.
I suggest you read up on the different jsp tags, Declarations, Scriptlets, and Page Directives, and also the jsp life cycle. It'll help you understand things a little better, plus both are important for the test.
I agree. Here's the link:
subject: Declarations
jQuery in Action, 3rd edition