Java
  Home arrow Java arrow Page 5 - The JSP Files (part 1): Purple Pigs In A Fruitbasket
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 1): Purple Pigs In A Fruitbasket
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2001-02-07


    Table of Contents:
  • The JSP Files (part 1): Purple Pigs In A Fruitbasket
  • Studying The Foundations
  • Java In A Teacup
  • Enter John Doe
  • Putting Two And Two Together
  • Basket Case
  • Alphabet Soup For The Soul

  • 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 1): Purple Pigs In A Fruitbasket - Putting Two And Two Together
    ( Page 5 of 7 )

    Just as you can create a variable to hold strings, you can create variables of other types too:

    int - used to store integers

    char - used to store a single character in Unicode format

    float and long - used to store floating-point numbers

    boolean - used to store "true" and "false" values (note that unlike languages like C and PHP, JSP does not recognize 1 => true and 0 => false)

    Let's take a simple example that adds two numbers and displays the result.


    <html> <head> </head> <body> <%! int alpha = 45; int beta = 34; int Sum; %> <% // add the two numbers Sum = alpha + beta; // display the result out.println("The sum of " + alpha + " and " + beta + " is " + Sum); %> </body> </html>

    And the output is:

    The sum of 45 and 34 is 79

    In this case, we've simply defined two variables as integer values, assigned values to them, and added them up to obtain the sum.

    In a similar vein, the next example demonstrates adding strings together:

    <html> <head> </head> <body> <%! // define the variables String apples = "The lion "; String oranges = "roars in anger"; String fruitBasket; %> <% // print the first two strings out.println("<b>The first string is</b>: " + apples + "<br>"); out.println("<b>The second string is</b>: " + oranges + "<br>"); // concatentate the strings fruitBasket = apples + oranges; // display out.println("<b>And the combination is</b>: " + fruitBasket + "<br>Who says you can't add apples and oranges?!"); %> </body> </html>

    And the output is:

    The first string is: The lion The second string is: roars in anger And the combination is: The lion roars in anger Who says you can't add apples and oranges?!

    In this case, the + operator is used to concatenate two strings together, which is then displayed via println().

     
     
    >>> 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 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek