Java Error Handling

Tech Guy on September 16th, 2009

Overriding allows programmers to replace a method’s implementation with new code. Overriding is a handy feature, and most OO programmers make heavy use of it. If you use the AWT 1.1 event handling model, you’ll often override listener implementations to provide custom functionality. One easy trap to fall into with overriding, is to mistype the [...]

Continue reading about Mistyping the name of a method when overriding

Tech Guy on September 15th, 2009

I know it’s very tempting to write blank exception handlers, and to just ignore errors. But if you run into problems, and haven’t written any error messages, it becomes almost impossible to find out the cause of the error. Even the simplest exception handler can be of benefit. For example, put a try { .. [...]

Continue reading about Java Programming Best Practice Writing blank exception handlers

Tech Guy on September 15th, 2009

If you’ve come from a C/C++ background, you may not find this quite as much a problem as those who have used other languages. In Java, arrays are zero-indexed, meaning that the first element’s index is actually 0. Confused? Let’s look at a quick example.

// Create an array of three strings

String[] strArray = new String[3];

// [...]

Continue reading about Java Developers Forgetting that Java is zero-indexed

Tech Guy on September 15th, 2009

This is one of the most frequent errors that we all make. It’s so simple to do, and sometimes one can look at an uncapitalized variable or method and still not spot the problem. I myself have often been puzzled by these errors, because I recognize that the method or variable does exist, but don’t [...]

Continue reading about Capitalization Errors while Java Programming

Tech Guy on September 15th, 2009

Null pointers are one of the most common errors that Java programmers make. Compilers can’t check this one for you – it will only surface at runtime, and if you don’t discover it, your users certainly will.
When an attempt to access an object is made, and the reference to that object is null, a [...]

Continue reading about How to avoid Null pointers Error while coding Java programs