devxlogo

Java

Image

Char Is Not Int

The code below expects that you can create a character from a number. It’s already bad technically: int is signed, while char is unsigned (a char is just 16 bits

Image

Starting JVM with Memory of User’s Choice

After successive development exposure, we understand the memory needs of our application. Java allows you to start the application with memory specifications as required and the application is bound to

Image

3 Options for Capturing Heap Dump from an Android App

Heap Dumps are vital artifacts to diagnose memory-related problems such as memory leaks, Garbage Collection problems, and java.lang.OutOfMemoryError. They are also vital artifacts to optimize memory usage as well. In

Image

Object Arrays are so Flexible

/*** @returns [1]: Location, [2]: Customer, [3]: Incident*/Object[] getDetails(int id) {… This sort of passing back values from a method is error prone; it is recommended to declare a small

Image

Relying on the Default TimeZone

Calendar calendar = new GregorianCalendar();calendar.setTime(date);calendar.set(Calendar.HOUR_OF_DAY, 0);calendar.set(Calendar.MINUTE, 0);calendar.set(Calendar.SECOND, 0);Date startOfDay = calendar.getTime(); The code above calculates the start of the day (0h00). The first mistake is the missing millisecond field of

Image

Modifying Setters In Java

The code below eliminates spaces at the beginning or end of a name entered by the user, it tries to remove the spaces inside the setter method of a bean.

Image

Effective Usage of Variables in Loops

For effective usage of variables in loops, it is advised to create variables outside of loops and use them in the loops. This helps save lot of memory and makes