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
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
Ideally, when you do not know the data type that you want to store in an array, you can create an Object array and later associate it with the data
Imagine, you want to schedule activating a task few moments (3 seconds in this case) from now, the following code snippet will be helpful. import java.util.*;//We only need Timer and
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
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
Writer w = new OutputStreamWriter(os, “UTF-8”);while (…){ w.write(“something”);} OutputStreamWriter uses memory for each call to its write() methods. This is why it is better to avoid this; if you do
Java provides a very easy mechanism to read jar files. It is the same process used for reading a zip file. The file myFiles.jar contains one or more files (as
In nearly all applications, there is critical data that we would not want anyone to see. Java has an easy way of implementing this. All that is required is to
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