magazine resources subscribe about advertising

New Architect Daily
Commentary and updates on current events and technologies

CMP Media E-Book

Download your copy today.

Research
Search for reports and white papers from industry vendors and analysts.

This Week at NewArchitect.com Subscribe now to our free email newsletter and get notified when the site is updated with new articles







Day of Defeat Online Gaming

 New Architect > Archives > 1998 > 11 > Java@Work  

Tackling Arrays

If you mainly write applets for the Web, it's easy to forget that Java is a full-blown object-oriented language. That means it has lots of features that applet writers often overlook. This is especially true of features that work differently from the way they do in other languages you've used before.

Take arrays, for example. While most programmers are familiar with arrays, Java implements them very differently from the way other languages do. In addition to arrays, Java also offers objects that manage lists, such as the Vector object.

Start at the Beginning

Conceptually, arrays are variables that hold more than one item of a particular type. For example, let's say you have a list of four integers in an array and you want to average them. If you kept them in normal variables, your code would look like that in Example 1(a).

While this will work, it isn't very good code. What happens when you want to average more than one list of items? How could you write a general-purpose function to compute averages regardless of how many items you supply? Arrays solve this problem.

Java uses a variable name followed by square brackets to specify an array. Inside the square brackets, you enter the element number (starting with 0) that you want to access (this number is the array index).




  Day of Defeat Online Gaming

home | daily | current issue | archives | features | critical decisions | case studies | expert opinion | reviews | access | industry events | newsletter | research | careers | info centers | advertising | subscribe | subscriber service | editorial calendar | press | contacts


Copyright © 2006 CMP Media, LLC Read our privacy policy, your California privacy rights, terms of service.
SDMG Web sites: BYTE.com, C/C++ Users Journal, Developer Pipeline, Dr. Dobb's Journal, DotNetJunkies, MSDN Magazine, Sys Admin,
SD Expo, SD Magazine, SqlJunkies, The Perl Journal, Unixreview, Windows Developer Network, New Architect

web2