Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book


  1. Do arrays have to begin with an element 0, or can they range from a higher minimum number to a higher maximum number, such as 65 to 90?

  2. They don't have to begin at element 0, but it is more efficient to do so because it takes up less memory in the computer to store arrays that begin with 0. You can use arrays of a higher index number simply by referring to the numbers you want to use. For example, if you created a for loop that cycled from array element 65 to element 90, you could disregard any other element numbers. However, there still will be array elements numbered from 0 to 64 taking up space in memory, even if you don't use them for anything.

  3. Is the numeric range of the alphabet, from 65 for A to 90 for Z, part of the basic Java language? If so, what are 1 through 64 reserved for?

  4. The numbers 1 through 64 include numerals, punctuation marks, and some unprintable characters, such as linefeed, newline, and backspace. A number is associated with each printable character that can be used in a Java program, as well as some unprintable ones. Java uses the Unicode numbering system, which supports more than 60,000 different characters from the different languages of the world. The first 127 characters are from the ASCII character set, which you might have used in another programming language.

  5. Why are some errors called exceptions?

  6. The significance of the term is that a program normally runs without any problems, and the exception signals an exceptional circumstance that must be dealt with. Exceptions are warning messages that are sent from within a Java program. In the Java language, the term error is sometimes confined to describe error conditions that take place within the interpreter running a program. You learn more about both subjects during Hour 18, "Handling Errors in a Program."

  7. In a multidimensional array, is it possible to use the length variable to measure different dimensions other than the first?

  8. You can test any dimension of the array. For the first dimension, use length with the name of the array, as in x.length. Subsequent dimensions can be measured by using length with the [0] element of that dimension. Consider an array called data that was created with the following statement:

    int[][][] data = new int[12][13][14];

    The dimensions of this array can be measured by using the data.length variable for the first dimension, data[0].length for the second, and data[0][0].length for the third.

  9. Can the length variable be set to increase or decrease the size of an array after it has been created?

  10. There's no way to modify the size of an array after it has been created; length is strictly used to find out an array's upper boundary.

  • + Share This
  • 🔖 Save To Your Account