devxlogo

Java

Avoid the XML Encoding Trap

It’s not a good idea to read an XML file and store it in a String because it wastes memory. XML specifies its encoding in the XML header, so when

Taking Advantage of Immutable Objects in Java

zero = new Integer(0);return Boolean.valueOf(“true”); Integer and Boolean are immutable; so, it is a bad idea to create objects that represent the same value, those classes have built-in caches for

Performance Measurements with String Class Usage

The new keyword definitely consumes more time when compared to direct initializing the value to a String object. The following illustrates the time consumed by both the mechanisms. These values

Testing for String Equality

if (name.compareTo(“Jerry”) == 0) …if (name == “Jerry”) …if (name.equals(“Jerry”)) …if (“”.equals(name)) … All the above comparisons are correct, but they are not great. The compareTo method is overkill and