devxlogo

Java

Image

Should Log Instances Be Static or Not?

Private static final Log log = LogFactory.getLog(MyClass.class); It is a good idea to store the log instance in a static final variable, because: No problems with serializable classes Initialization cost

Image

Assembling XML with String Operations

String name = …String attribute = …String xml = “”+””+ name +””+”; Many beginners are tempted to create an XML file like the one listed above using String operations because

Image

How to Diagnose Memory Leaks

Memory leaks don’t have to be hard/scary/tedious problems to solve if you follow the three simple steps mentioned below: Step 1: Capture baseline heap dump You need to capture heap

Image

Infinite Loop Using Java

Certain aspects of your code may want to perform certain activities in a loop and wait infinitely for a command. However, the “while(true)” command is an easier way to achieve

Image

Infinite Heap in Java

This method creates a PDF file and returns the binary PDF data as a byte array. This particular line of code supposes that the resulting file is small and fits

Image

List All Available Time Zones

In case you are developing an application that is based on time zones, this example will be of help. Lisiting 1. import java.util.TimeZone;public class AvailableTimeZones{ public static void main(String args[])

Image

Usage of a Custom Ordinal in Enum

The getCustomValue() method on the enum returns the custom value associated. You can use this mechanism when you want to override the default ordinal with a custom ordinal. Code snippet public