Solved

jsp true and false better way

Posted on 2002-07-22
5
449 Views
Last Modified: 2006-11-17
I am using the following code a number of times on a jsp page.  Is there a more efficient way to do this

and futher down I use it the same way
minus  boolean  display = false ;
------------------------------
<%
boolean  display = false ;
if ( (new Integer(passedCalculatedElecSerDay)).intValue()>0 )
{
display = true;
}
if ( (new Integer(passedCalculatedElecSerYear)).intValue()>0 )
{
display = true;
}
if  ( display == true  )
{
%>    
do this
<%
 } else {
%>
do that
<% } %>
0
Comment
Question by:schroom
  • 2
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 200 total points
ID: 7169756
 Why do you use the: new Integer(passedCalculatedElecSerYear)).intValue()>0 twice?. Can you not do it only once or the "passedCalculatedElecSerYear" chanegs all the time? And the: if  ( display == true  ) could be written as if  ( display ).

  Besides that I can't see any other way you could make your source code better.

  Hope it helps.
0
 

Author Comment

by:schroom
ID: 7169841
okay - but maybe creating a formMode would work
0
 
LVL 2

Expert Comment

by:flumpman
ID: 7169849
In addition, you should use

int Integer.parseInt(String) instead of new Integer(String).intValue() as this is more efficient.  It avoids the creation of an object that has to be garbage collected.

--
flumpman
0
 

Author Comment

by:schroom
ID: 7169864
flumpman thanks for more that extra tip,
I will change my code
0
 
LVL 35

Expert Comment

by:girionis
ID: 7169898
 Thank you for the points schroom ]:-). I am glad I helped. What exactly is the formMode?

  As for the Integer.parseInt(String) I think this is a betetr solution as well. It would be wise to catch a NumberFormatException as well:

int passedCalculatedElecSerYear = 0; // Default value
try
{
    passedCalculatedElecSerYear = Integer.parseInt(<string>);
}
catch (NumberFormatException nfe) {}

  Hope it helps.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question