SunQuest
 
       Java
  Home arrow Java arrow Page 5 - The JSP Files (part 1): Purple Pigs In...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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? 
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: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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

    - 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...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup

    BlackBerry VTS




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway