J2EE Naming Conventions Rules
Overview
Table A.2. J2EE Naming Conventions Overview
JEN_001: Name An EJB Bean Class Like [Name]EJB or [Name]Bean (High)
A class that extends one of the enterprise bean types (SessionBean, EntityBean or MessageDrivenBean) must have a name that ends with EJB or Bean.
 | Note
Use of the Bean suffix for the enterprise bean class name can lead to developers thinking they are dealing with a standard JavaBean and not an EJB. Use of the EJB suffic clearly states that the class represents an enterprise java bean implementation. |
WRONG
public class Foo implements EntityBean {
public Foo() {
}
}
RIGHT
public class FooBean implements EntityBean {
public FooBean() {
}
}
JEN_002: Name An EJB Remote Home Interface Like [Name]Home (High)
An interface that extends EJBHome must have a name that ends with Home.
WRONG
import java.rmi.RemoteException;
import javax.ejb.EJBHome;
public interface Foo extends EJBHome {
}
RIGHT
import java.rmi.RemoteException;
import javax.ejb.EJBHome;
public interface FooHome extends EJBHome {
}
JEN_003: Name An EJB Remote Interface Like [Name] (High)
A remote interface that extends EJBObject should be the name of the EJB.
WRONG
public interface FooRemote extends EJBObject {
void bar(String value) throws RemoteException;
}
RIGHT
public interface Foo extends EJBObject {
void bar(String value) throws RemoteException;
}
JEN_004: Name An EJB Local Home Interface Like [Name]LocalHome (High)
Feedback
Only classes that extend the EJBLocalHome interface should have a suffix LocalHome.
WRONG
public interface FooHome extends EJBLocalHome {
}
RIGHT
public interface FooLocalHome extends EJBLocalHome {
}
JEN_005: Name A Transfer Object Like [Name]TO (High)
Implementations of the J2EE pattern Transfer Object must have a suffix TO.
 | Note
The Transfer Object pattern was previously called Value Object and normally used a name suffix VO. |
WRONG
public class AccountData implements Serializable {
}
RIGHT
public class AccountTO implements Serializable {
}
JEN_006: Name An EJB In The Deployment Descriptor Like [Name]EJB (High)
RIGHT
<enterprise-beans>
<entity>
<ejb-name>FooEJB</ejb-name>
<home>be.vlaanderen.myproject.subpackage.FooHome</home>
<remote>be.vlaanderen.myproject.subpackage.Foo</remote>
<ejb-class>be.vlaanderen.myproject.subpackage.FooBean</ejb-class>
</entity>
</enterprise-beans>
JEN_007: Name An EJB Display Name In The Deployment Descriptor Like [Name]JAR (High)
<ejb-jar>
<description>A Session EJB Example</description>
<display-name>SessionJAR</display-name>
<enterprise-beans>
</enterprise-beans>
<assembly-descriptor>
</assembly-descriptor>
</ejb-jar>
JEN_008: Name A Servlet Like [Name]Servlet (High)
The name of a Servlet should always end with Servlet, for example when implementing a Front Controller Servlet the name should be FrontControllerServlet.
JEN_009: Name A Primary Key Class Like [Name]PK (High)
The name of primary key class used by Entity Beans must end with PK.
WRONG
public class FooKey implements java.io.Serializable {
}
RIGHT
public class FooPK implements java.io.Serializable {
}
JEN_010: Name A Filter Servlet Like [Name]Filter (High)
The name of a Filter Servlet should always end with Filter, for example EncodingFilter.
JEN_011: Name A Local Interface Like [Name]Local (High)
An interface that extends EJBLocalObject must have a name that ends with Local.
WRONG
import java.rmi.RemoteException;
import javax.ejb.EJBLocalObject;
public interface Foo extends EJBLocalObject {
}
RIGHT
import java.rmi.RemoteException;
import javax.ejb.EJBLocalObject;
public interface FooLocal extends EJBLocalObject {
}
JEN_012: Name A Data Access Object Like [Name]DAO (High)
Implementations of the J2EE pattern Data Access Object must follow the naming convention [Name]DAO.
WRONG
RIGHT
public class AccountDAO {
}
JEN_013: Use A Correct Name For An Enterprise Application Display Name (High)
The enterprise application display name within the deployment descriptor is the application name, written in mixed cases, with a suffix EAR.
WRONG
<display-name>myproject</display-name>
RIGHT
<display-name>MyProjectEAR</display-name>
JEN_014: Use A Correct Name For A Web Module Display Name (High)
The Web module display name within the deployment descriptor is the web module name, written in mixed cases, with a suffix WAR.
WRONG
<display-name>mywebproject</display-name>
RIGHT
<display-name>MyWebProjectWAR</display-name>
{code:xml}
h3. {anchor:JEN_015} JEN_015: Use A Correct Name For An EJB Environment Reference Name (High)
All references to Enterprise Java Beans must be organized in the {{ejb}} subcontext of the application component's environment.
WRONG
{code:xml}
<ejb-ref>
<description>
This is a reference to the entity bean that
encapsulates access to Foo.
</description>
<ejb-ref-name>Foo</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>be.vlaanderen.FooHome</home>
<remote>be.vlaanderen.Foo</remote>
</ejb-ref>
RIGHT
<ejb-ref>
<description>
This is a reference to the entity bean that
encapsulates access to Foo.
</description>
<ejb-ref-name>ejb/Foo</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>be.vlaanderen.FooHome</home>
<remote>be.vlaanderen.Foo</remote>
</ejb-ref>
JEN_016: Name A JMS Destination Like [Name]Queue Or [Name]Topic (High)
JMS destinations must either have a suffix Queue or Topic depending on their jms type.
WRONG
<resource-env-ref>
<description>
This is a reference to a JMS queue
</description>
<resource-env-ref-name>jms/Foo</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
RIGHT
<resource-env-ref>
<description>
This is a reference to a JMS queue
</description>
<resource-env-ref-name>jms/FooQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
JEN_017: Use A Correct Name For A JMS Environment Reference Name (High)
All references to Java Messaging Service's must be organized in the jms subcontext of the application component's environment.
WRONG
<resource-env-ref>
<description>
This is a reference to a JMS queue
</description>
<resource-env-ref-name>FooQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
RIGHT
<resource-env-ref>
<description>
This is a reference to a JMS queue
</description>
<resource-env-ref-name>jms/FooQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
JEN_018: Use A Correct Name For A JDBC Environment Reference Name (High)
All references to JDBC resources must be organized in the jdbc subcontext of the application component's environment.
WRONG
<resource-ref>
<description>
A data source for a Foo database
</description>
<res-ref-name>FooDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
RIGHT
<resource-ref>
<description>
A data source for a Foo database
</description>
<res-ref-name>jdbc/FooDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
JEN_019: Name A Database Like [Name]DB (High)
The database name used by JDBC resource references must have a suffix DB.
WRONG
<resource-ref>
<description>
A data source for a Foo database
</description>
<res-ref-name>jdbc/Foo</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
RIGHT
<resource-ref>
<description>
A data source for a Foo database
</description>
<res-ref-name>jdbc/FooDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>