Java
  Home arrow Java arrow The JSP Files (part 2): Attack Of The Killer Fortune Cookies
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVA

The JSP Files (part 2): Attack Of The Killer Fortune Cookies
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2001-02-22


    Table of Contents:
  • The JSP Files (part 2): Attack Of The Killer Fortune Cookies
  • Flavour Of The Month
  • Do It Or Else...
  • Cookie-Cutter Code
  • Lunch In Milan
  • Switching Things Around

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    The JSP Files (part 2): Attack Of The Killer Fortune Cookies
    ( Page 1 of 6 )

    The second part of our introductory JSP tutorial discusses arithmetic, logical and comparison operators, together with simple examples and illustrations. You'll also learn the basics of JSP's numerous conditional expressions, including the "if", "if-else" and "switch" statements, and find out a little more about the String object.With a little bit of luck, our introductory article on JSP left you so excited that you spent the last few days eagerly practicing variable names and letting your friends know how much smarter you are than them. And this week, we're going to help you cement your reputation still further, by giving you a crash course in JSP's conditional statements and loops.

    Make sure you're strapped in tight - this is gonna be one hell of a ride!{mospagebreak title=Adding It All Up} You'll remember how, in the first part of this tutorial, we used the + operator to add numbers and strings together. And just as you have the + operator for addition, JSP comes with a bunch of other arithmetic operators designed to simplify the task of performing mathematical operations.

    The following example demonstrates the important arithmetic operators available in JSP:


    <html> <head> </head> <body> <%! // declare variables int alpha = 25; int beta = 5; int sum, difference, product, quotient, remainder; %> <% // perform operations out.println("The sum of " + alpha + " and " + beta + " is " + (alpha + beta) + "<br>"); out.println("The difference of " + alpha + " and " + beta + " is " + (alpha - beta) + "<br>"); out.println("The product of " + alpha + " and " + beta + " is " + (alpha * beta) + "<br>"); out.println("The quotient after division of " + alpha + " and " + beta + " is " + (alpha / beta) + "<br>"); out.println("The remainder after division of " + alpha + " and " + beta + " is " + (alpha % beta) + "<br>"); %> </body> </html>
    And here's the output:

    The sum of 25 and 5 is 30 The difference of 25 and 5 is 20 The product of 25 and 5 is 125 The quotient after division of 25 and 5 is 5 The remainder after division of 25 and 5 is 0
    As with all other programming languages, division and multiplication take precedence over addition and subtraction, although parentheses can be used to give a particular operation greater precedence. For example,

    <% out.println(10 + 2 * 4); %> <hr noshade size=1 color=#cccccc></pre></blockquote><br> returns 18, while<br> <blockquote><pre><hr noshade size=1 color=#cccccc> <% out.println((10 + 2) * 4); %>
    returns 48.

    In addition to these operators, JSP comes with the very useful auto-increment [++] and auto-decrement [--] operators, which you'll see a lot of in the next article. The auto-increment operator increments the value of the variable to which it is applied by 1, while the auto-decrement operator does the opposite. Here's an example:

    <%! int x = 99; %> <% // x = 99 out.println("Before increment, x = " + x + "<br>"); x++; // x = 100 out.println("After increment, x = " + x); %>

    JSP also comes with a bunch of comparison operators, whose sole raison d'etre is to evaluate expressions and determine if they are true or false. The following table should make this clearer.

    Assume x=4 and y=10
    Operator What It Means Expression Result

    ==

    is equal to

    x == y

    False

    !=

    is not equal to

    x != y

    True

    >

    is greater than

    x > y

    False

    <

    is less than

    x < y

    True

    >=

    is greater than
    or equal to

    x >= y

    False

    <=

    is less than
    or equal to

    x <= y

    True


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

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek