Java is considered very safe programming language compared to C and C++ as it doesn't have free() and malloc() to directly do memory allocation and deallocation, You don't need to worry of array overrun in Java as they are bounded and there is pointer arithmetic in Java. Still there are some sharp edges in Java programming language which you need to be aware of while writing enterprise application. Many of us make subtle mistake in Java which looks correct in first place but turn out to be buggy when looked carefully. In this series of java articles I will be sharing some of common Java mistake programmers make while programming application in Java. As I have said earlier every day we learn new things but we forget something equally important. This again highlight importance of code review and following best practices in Java. In this part we will discuss why double and float should not be used in monetary or financial calculation where exact result of calculation is expected.
comparing dates in Java is common need for Java programmer, now and then we need to compare two dates to check whether two dates are equals, less than or greater than each other, some time we also needs to check if one dates comes in between two dates. Java provides multiple ways to compare two Dates in Java which is capable of performing Date comparison and letting you know whether two dates are same, one date come before or after another date in Java. In last couple of article we have seen how to convert String to Date in Java and Converting Date to String in Java and here we will see three different example of comparing two dates in Java.
There are lot of differences between instance variable, class variable and local variable in Java and knowing them will help you to write correct and bug free Java programs. Java is full featured programming language and provides different kind of variables like static variable also called Class variable since it belongs to whole Class, non static also called instance variable and local variables which varies in scope and value. Thank god Java doesn't have any register variable or auto scope like C otherwise it would have so much detail to remember. static variables are common source of error in may multi-threaded java program and does require a bit of carefulness while using it. On the other hand instance variable and local variable has less sharing visibility than static variable.