Top Ten Errors Java Programmers Make
I read an article (linked below) on “Top Ten Errors Java Programmers Make“. The author has mentioned the errors which even the most experienced programmers often commit or the New to Java programmers may commit in the future. Not only has he listed the errors but also given the possible solution for the same. I found the article really informative.
One can read the article here.
I would like to add some more:
- A .java source file can contain more than one class but it can contain atmost one Top level class (or interface) definition that is public and the name of the source file must be same as that of the public class (or interface).
- Static methods cannot be overridden but can be hidden if they are not final (Read about Overriding vs Hiding here).
- The objects created in the String pool are not subjected to GC until the class is unloaded by the JVM.
- Only methods or code blocks can be marked “synchronized”.
- Local classes cannot access non-final variables.
- -0.0 == 0.0 is true.
- Collection (singular) is an Interface, but Collections (plural) is a helper class.
- continue must be in a loop (e.g., for, do, while). It cannot appear in case constructs.
- Instance initializers are executed only if an object is constructed.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)