Home arrow Java & J2EE arrow Page 5 - The JSP Files (part 2): Attack Of The Killer Fortune Cookies

Lunch In Milan - Java

The second part of our introductory JSP tutorial discussesarithmetic, logical and comparison operators, together with simple examplesand illustrations. You'll also learn the basics of JSP's numerousconditional expressions, including the "if", "if-else" and "switch"statements, and find out a little more about the String object.

TABLE OF CONTENTS:
  1. The JSP Files (part 2): Attack Of The Killer Fortune Cookies
  2. Flavour Of The Month
  3. Do It Or Else...
  4. Cookie-Cutter Code
  5. Lunch In Milan
  6. Switching Things Around
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 4
February 22, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
If you take a close look at the last-but-one example above, you'll notice that the conditional expression

(temp < 25 && temp > 10)

is slightly different from the ones you've been used to thus far. This is because JSP also allows you to combine multiple conditions into a single expression, with the help of an animal called a "logical operator".

The following table should make this clearer.

Assume delta = 12, gamma = 12 and omega = 9
Operator What It Means ExampleEvaluates To
&& ANDdelta == gamma && delta > omega delta equals gamma AND delta is greater than omega
True && ANDdelta == gamma && delta < omegadelta equals gamma AND delta is less than omega
False || OR delta == gamma || delta < omega delta equals gamma OR delta is less than omega
True || OR delta > gamma || delta < omega delta is greater than gamma OR delta is less than omega
False ! NOT !deltadelta doesn't exist

So, instead of something as ugly as this

<% if (day == "Thursday") { if (time == "12") { if (place == "Italy") { lunch = "pasta"; } } } %>
you could have something as elegant as this.

<% if (day == "Thursday" && time == "12" && place == "Italy") { lunch = "pasta"; } %>


 
 
>>> More Java & J2EE Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: