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
Solved

jsp true and false better way

Posted on 2002-07-22
5
448 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
Protect jar file - windows app 2 65
Spring Framework HTTPSession management 1 45
Java basic valueOf question 1 29
Setup GlassFish 4 21
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

860 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