Solved

jsp true and false better way

Posted on 2002-07-22
5
444 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now