
Learn Some Efficient Programming Practices
Avoiding null pointer exceptions is a good programming practice. However, simple things such as string comparison can also lead to null pointer exceptions. Considering the following: You have a constant

Avoiding null pointer exceptions is a good programming practice. However, simple things such as string comparison can also lead to null pointer exceptions. Considering the following: You have a constant

There are times when we need to reflect the changes made to a file in a different file as well. Mostly, they are made available in a common place so

for (float f = 10f; f!=0; f-=0.1){ System.out.println(f);} The code above causes an endless loop, it doesn’t act as expected, because 0.1 is an infinite binary decimal and f will

In equal comparisons it is recommended to place literals first. This way you eliminate the risk of NullPointerException: //avoid obj.equals(“foo”);//prefer”foo”.equals(obj);

Java long behaves differently when used with the letter L and without it. Code snippet public class JavaLong{ public static void main(String args[]) { JavaLong javaLong = new JavaLong(); javaLong.proceed();

Annotations are similar to interfaces in that you can convey your own specifications that others will need to follow. Here we are defining an Annotation named ClassHeaderAnnote, which has few

InputStream in = new FileInputStream(file);int q;while ((q = in.read()) != -1) { …} The code above reads a file byte by byte. Every read() method call on the stream causes

“” + set.size()new Integer(set.size()).toString() The return type of the Set.size() method is int, but it is desired a conversion to String. These two lines do the conversion, but the first

int x = Integer.valueOf(str).intValue(); int y = Long.valueOf(Double.valueOf(str).longValue).intValue(); To use the API without allocating unnecessary objects use the following lines of code: int x = Integer.parseInt(str); int y = (int) Double.parseDouble(str);