Java Coding Standards

You use JDeveloper and the Java programming language to create JD Edwards EnterpriseOne business service and published business service classes that run in a J2EE environment. The business services foundation package provides classes that you extend when you write your code. The business services foundation and JDeveloper provide wizards that help you structure your code. JDeveloper enables you to set preferences for placing braces and then reformats the code to your desired style.

You use basic Java programming style conventions when you write your code. For example, instead of sprinkling literals and constant values throughout the code, you should define these values as private static final variables at the beginning of a method or function or define them globally. Another convention is to use uppercase letters for each word. You should separate each pair of words with an underscore when naming constants, as illustrated in this code sample:

private static final String DEFAULT_ERROR = "c39f495121b...etc"; 

You should include meaningful comments consistently throughout your code. For easier readability when you create a Java class, order the elements in the following way:

  1. Attributes

  2. Constructors

  3. Methods

The code that you write should check for null and empty strings, as illustrated in this example code:

if ((string != null) && (string.length() !=0))   
                     or
if ((string == null) || (string.length() == 0)) 
                     or 
if ((string == null) || (string.equals(""))) 

Your code should check for null objects. You can use this sample code to check for null objects:

if (object !=null)
{
  doSomething()
}

When you compare strings, use equals(). This code sample shows the correct way and the wrong way to compare strings:

String abc = "abc"; String def = "def";
// Correct way
if ( (abc + def).equals("abcdef") )
{
  .....
}

// Wrong way
if ( (abc + def) == "abcdef" )
{
   ......
}

When you create published value objects, the code should test for null objects in the set methods. This code sample shows how to test for null objects:

public void setCarrier(Entity carrier)
 {
   if (carrier != null)
     this.carrier = carrier;
   else
     this.carrier = new Entity();
 }