jsp true and false better way

Posted on 2002-07-22
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
<% } %>
Question by:schroom
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 35

Accepted Solution

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.

Author Comment

ID: 7169841
okay - but maybe creating a formMode would work

Expert Comment

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.


Author Comment

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

Expert Comment

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
    passedCalculatedElecSerYear = Integer.parseInt(<string>);
catch (NumberFormatException nfe) {}

  Hope it helps.

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb example issues 3 88
restrict decimal places for double datatype 10 49
Java array sort 10 62
maximize the sum of fractions 33 74
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

732 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