Monday, October 18, 2010

Java QA Basics On Arrays



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

A
No, 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.

Q Why are some errors called exceptions?

A
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.

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

A
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.
Quiz
If the brain were an array, you could test its length by answering each of the following questions about arrays.
Questions
1. What types of information are arrays best suited for?

(a) Lists
(b) Pairs of related information
(c) Trivia

2.
What variable can be used to check the upper boundary of an array?

(a)
top
(b)
length
(c) limit

3.
Who is the famous Aztec priest-ruler?

(a) Quisp
(b) Quetzalcoatl
(c) Quichelorraine
Answers
1. a. Lists that contain nothing but the same type of information--strings, numbers, and so on--are well-suited for storage in arrays.

2.
b.

3.
b. It's also the name of a god of learning and civilization who is depicted as an approaching storm whose winds kick up dust before the rain comes.

No comments:

Post a Comment