Basic HTML version of Foils prepared June 5 99

Foil 42 Types

From Java Language in the Computer Science Curriculum ADMI Tutorial Duluth Minnesota -- June 3 99. by Geoffrey C. Fox


A variable is either a primitive type such as int, float or double, or it is an object.
Arrays are objects, but have a special syntax for creating and indexing, more like C and C++.
  • int states [ ]; declares the states variable to be a 1D array of ints
  • states = new int [ 128 ]; creates the new 1D array of length 128
  • states [ 27 ] = i + 1; assigning to an element
Multi-dimensional arrays are arrays of arrays
  • char states [ ] [ ] = new char [12 ] [ 24 ]; delaring and creating at the same time
  • they can also be "ragged"
Arrays can have values that are any type of object
  • Color hues = new Color [ 1024 ];



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Jun 5 1999