Java – What is serialVersionUID

In Java, serialVersionUID is something like version control, assure both serialized and deserialized objects are using the compatible class. For example, if an object saved into a file (Serialization) with serialVersionUID=1L, when we convert the file back to an object (Derialization), we must use the same serialVersionUID=1L, otherwise an InvalidClassException is thrown. Terminal Exception in …

Read more

Constant value should always come first in comparison

Normal practice Constant value comes second in comparison. private static final String COMPARE_VALUE = "VALUE123"; public boolean compareIt(String input){ if(input.equals(COMPARE_VALUE)){ return true; }else{ return false; } } Problem This is fine to compare a constant value with the above method, however it will potentially causing a NullPointerException, if user pass a “null” value for the …

Read more