It is very natural to make mistakes when you know something rather well. Take Java, if you are a casual programmer or are new to the language, be rest assured that mistakes can and will be made. Here is a list of the top seven most common mistakes and how to avoid making them:
1.Mistyping a method when you override. By overriding, programmers are allowed to replace a particular method with a new code. An easy pitfall you may experience during overriding is to mistype the specified method name. When a programmer mistypes a method’s name, they are now creating a new method as opposed to overriding the code.
2.Comparison of two objects. When you use the == operator, you are actually comparing two object references. You should use the .equals method—a method by all classes from java.lang.
3.Assignment comparison. Another quite easy error that programmers make. Most common, a programmer will run into an error message that states: “Can’t convert XXX to boolean,” where the Java type that you are assigning to the code is represented by the XXX.
4.Blank exception handlers. If you have yet to write any error messages, it can become rather hard to find out the cause of an error when you write blank exception handlers and ignore the errors. You will not need to write a handler for each exception, just do not leave the area blank.
5.Capitalization errors. A very frequent error that most people make. I often have been lost because I do not recognize that the variable or method does exist, but I overlook the lack of the capitalization. A quick trick you can learn is:
- a.Variables in the Java API begin with lowercase letters.
- b.Variables use capitalization where a new word will begin.
6.Null pointers. Many compilers can not check this as it will only appear at the system’s run time. Most functions return to indicate an incorrect condition—normal testing may not pick it up.
7.Passing by value. This can be quite upsetting to diagnose because Java uses both meaning when you review the code, you must be sure that it is indeed passy by its reference, but find out that it is being passed by its value.
These listed seven are only some that many programming errors you may encounter and stumble across while writing code. Be it known that many programmers, Java programmers especially, will often encounter these same sorts of stumbling blocks.