This is a sad story. About three decades ago, I wrote a program in C++ and
with the platform I was using, was supposed to have null
as the last value
in my arrays. I didn't read the documentation and thus didn't do this. I was
running the code on Solaris and for some reason it worked, despite the bug in
my code. A fellow student wanted to see whether my program would also compile
and run on Windows. I strongly urged him not to try it, but he did anyway. It
compiled fine, but when it ran, due to the unterminated array, it caused a
catastrophic failure and wiped out his hard drive. It was an unfortunate
mistake, and I did feel quite bad for my colleague.
Hackers exploit these types of bugs all the time - they are called buffer overflow attacks - in order to insert their own program code and to take over control of machines.
Java protects us against writing or reading past the end of an array by
consistently throwing an
ArrayIndexOutOfBoundsException
. Much better!
We hope you enjoyed this tutorial. If you did, you will also enjoy our courses. We suggest you start with Extreme Java - Advanced Java, followed by Extreme Java - Concurrency Performance for Java 8.
We deliver relevant courses, by top Java developers to produce more resourceful and efficient programmers within their organisations.
We can help make your Java application run faster and trouble-shoot concurrency and performance bugs...