Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is "isDefined" function in java?

Status
Not open for further replies.

GoSooJJ

Programmer
Feb 24, 2001
76
US
hi all~
I'm new to java.
currently i have a project that convert php to jsp. php has "isset(variable name)" function for look for variable that already defined or not. how does jsp works? I tried to find this simple function, but no luck.
Please help me out.

Thank you~
JJ //
 
Need further clarification but I will give you the first thing I could think of.

You can always check if a variable is null to determine if it has been "set". Example:
Object x = null;
...
if (x == null) {
/* not set yet */
}
else {
/* x is set */
} Wushutwist
 
thx Wushutwist,

ok here is what i need.
in php, we can have 'isset()' function to see the variable is defined or not. something like this.

if (isset(varName) AND varName == "DefinedVariable")
echo ("hello");

therefore even without initialize variable name 'varName' we can check for the either it's defined or not. if i run this code in jsp

if (varName == NULL)
...do something...

above code will generate error that 'varName' is not defined. i want to know that is there any way that i can check the variable already initialized or not...

thx again,
JJ //
 
No. You must define a variable before you use it in almost all programming languages and Java is no exception. This allows a strongly typed language and as a result many potential problems can be caught at compile time. This is good programming practice even if it isn't required by the language. Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top