Thursday, July 30, 2009

Does Java do boundary checking of arrays during program execution?

A. Yes, always


B. Yes, but only if a project file setting is made to enable such checking


C. Yes, but it is limited to single-dimension arrays


D. Yes, but only if the array is a member of a class


E. No

Does Java do boundary checking of arrays during program execution?
A. Yes, always.





This is one of the many advantages of Java over older languages such as Pascal, C, and even C++.





If you ever try to use an index that is invalid, the Java Runtime immediately throws and exception and a stack trace is displayed on the console showing you exactly where the invalid attempt to index the array occurred.





In older languages, you could spend days trying to debug an array-out-of-bounds errors.





Today's computers are so fast that a question is "what do you do with all of that speed?" My answer is that you use a more modern development system such as Java to increase programmer productivity.


--------


You should try indexing an array out-of-bounds and see what happens, then when it happens when you're trying to get something done, you'll recognize the problem and the solution.


--------
Reply:A.


No comments:

Post a Comment