Java
  Home arrow Java arrow Page 6 - The JSP Files (part 4): The Red Pill
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 4): The Red Pill
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 6
    2001-03-07

    Table of Contents:
  • The JSP Files (part 4): The Red Pill
  • The Last Action Hero
  • Entering The Matrix
  • Requesting More
  • Taking Some Medication
  • What's For Dessert?
  • A Chocolate Addiction
  • Couch Potato
  • Beating It Into Submission

  • 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 4): The Red Pill - What's For Dessert?


    (Page 6 of 9 )

    Thus far, the variables you've used contain only a single value - for example,


    int i = 0
    However, array variables are a different kettle of fish altogether. An array variable can best be thought of as a "container" variable, which can contain one or more values. For example,

    String[] desserts = {"chocolate mousse", "tiramisu", "apple pie", "chocolate fudge cake"};
    Here, "desserts" is an array variable, which contains the values "chocolate mousse", "tiramisu", "apple pie", and "chocolate fudge cake".

    Array variables are particularly useful for grouping related values together - names, dates, phone numbers of ex-girlfriends et al.

    The various elements of the array are accessed via an index number, with the first element starting at zero. So, to access the element

    "chocolate mousse"
    you would use the notation

    desserts[0]
    while

    "chocolate fudge cake"
    would be

    desserts[3]
    - essentially, the array variable name followed by the index number enclosed within square braces. Geeks refer to this as "zero-based indexing".

    Defining an array variable in JSP is somewhat convoluted, as compared to languages like PHP and Perl; you need to first declare the variable and its type, and then actually create the array.

    <% // declare type of arrayString[] desserts;// initialize array// the number indicates the number of elements the array will holddesserts = new String[4];// assign values to array elementsdesserts[0] = "chocolate mousse";desserts[1] = "tiramisu";desserts[2] = "apple pie";desserts[3] = "chocolate fudge cake";%>
    Or you can use the simpler version:

    <% String[] desserts = {"chocolate mousse", "tiramisu", "apple pie","chocolate fudge cake"};%>
    Note that if you try to add more elements than the number specified when creating the array, JSP will barf with a series of strange error message.

    More Java Articles
    More By Vikram Vaswani, (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

    SlickEdit




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