devxlogo

Java

Time Zone Conversion

The method below does nothing because the returned Date is exactly the same with the input value. Always remember that the Date does not carry time zone information, it is

finding right tech

How to Find the End of a File in Java

Easily find the end of file that you are processing. Scanner again has a easier way of doing it. import java.util.*;import java.io.*;public class EndOfFile { public static void main(String args[])

Interesting Java.lang.Math Class

public class UsingLangDotMath {    final int TWENTY_SEVEN = 27;        public static void main(String args[])    {       UsingLangDotMath usingLangDotMath = new UsingLangDotMath();       usingLangDotMath.proceed();    }        private void proceed()    {       System.out.println(“Cube root of 27: ” + Math.cbrt(TWENTY_SEVEN));       System.out.println(“Trigonometric sine: ” + Math.sin(TWENTY_SEVEN));       System.out.println(“Trigonometric cosine: ” + Math.cos(TWENTY_SEVEN));       System.out.println(“Trigonometric tangent: ” + Math.tan(TWENTY_SEVEN));           } } /* Expected output: [root@mypc]# java UsingLangDotMath Cube root of 27: 3.0 Trigonometric sine: 0.956375928404503 Trigonometric cosine: -0.2921388087338362 Trigonometric tangent: -3.273703800428119 */

Daemon Threads in Java

Did you know that execution of a Java program will continue only when there is at least one user thread running? In cases in which there are no user threads,

Avoiding the HashMap Size Trap

Map map = new HashMap(collection.size());for (Object obj : collection) { map.put(obj.key, obj.value);} The code above wants to make sure that the HashMap doesn’t need to be resized, so its sets

Catching to Log in Java

The code below catches the exception to write out a log statement and then re-throws the same exception. It is recommended to let the caller decide if the message should

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