Commit 478115

2026-01-16 09:55:54 Melisha Dsouza: Updated link
CMMI/Guidelines/Coding Standard/Java EE.md ..
@@ 1,6 1,13 @@
# **Java EE**
- ### **General Java Naming Conventions**
+ ### **1. Revision History**
+
+ | Date | Version | Author | Description of Changes |
+ | ---------- | ------- | ------ | --------------------------------------------------------------------------------------------- |
+ | 2026-01-12 | 1.0 | YS | Initial official release combining Enovate legacy standards and modern Jakarta EE guidelines. |
+
+
+ ### **2. General Java Naming Conventions**
These conventions ensure modules and components are easy to identify and organize, enhancing maintenance. All conventions are compliant with standard Java Programming Language code conventions.
* **Classes & Interfaces**: Use PascalCase (mixed case with the first letter of each internal word capitalized).
@@ 14,7 21,7 @@
* **Packages**: Use all-lowercase ASCII letters.
* **Example**: `com.enovate.paymentsystem.service.`
- ### **J2EE Application, Module, and Component Names**
+ ### **3. J2EE Application, Module, and Component Names**
This includes archive names and display names in deployment descriptors.
* **J2EE Application (EAR):** Packaged as an Enterprise Archive with a .ear extension.
* **Archive Name:** All-lowercase ASCII letters.
@@ 29,7 36,7 @@
* **Archive Name:** `<module-name>.war.`
* **Display Name**: `<expanded-module-name> WAR.`
- ### **EJB Component Naming Standards**
+ ### **4. EJB Component Naming Standards**
Conventions for the different parts of an enterprise bean.
* **Entity & Session Beans:**
* **Local Interface:** `<component-name> or <component-name>Local.`
@@ 41,7 48,7 @@
* **Implementation Class:** `<component-name>Bean.`
* **Display Name:** `<expanded-component-name> MDB.`
- ### **Web Component Naming Standards**
+ ### **5. Web Component Naming Standards**
Includes Servlets, JSPs, filters, and listeners.
* **Servlets: **
@@ 56,7 63,7 @@
* **JSP Segments: **`/WEB-INF/jspf/file.jspf.`
* **Tag Files:** `/WEB-INF/tags/file.tag.`
- ### **Web Service Naming (JAX-RPC & Endpoint)**
+ ### **6. Web Service Naming (JAX-RPC & Endpoint)**
Naming for clients, endpoints, and configuration files.
* **Service Name:** PascalCase base name of the EJB or JAX-RPC endpoint.
* Example: `WeatherService.`
@@ 68,7 75,7 @@
* **WSDL File:** `<service-name>.wsdl.`
* **Mapping File:** `<all-lower-case-service-name>-mapping.xml.`
- ### **Reference Names (JNDI & Resources)**
+ ### **7. Reference Names (JNDI & Resources)**
All reference names are relative to java:comp/env.
* **EJB References**: Logical name for JNDI lookup of home interfaces.
* Format: `ejb/<component-name>.`
@@ 79,7 86,7 @@
* **Mail**: `mail/<resource-qualifier>.`
* **Environment Entries**: `param/<parameter-name>.`
- ### **Database & XML Document Naming**
+ ### **8. Database & XML Document Naming**
* **Database Naming:** Name CMP databases after the application (e.g., `PaymentSystemDB`).
* **Database schema:** Use lower_case_with_underscores (e.g. `payment_system_db`).
* **Database tables:** Use lower_case_with_underscores (e.g. `payment_records`).
@@ 88,7 95,7 @@
* **XML Attributes:** Follow variable naming (`camelCase`).
* **Alternative XML Notation:** Element names in lower case separated by hyphens (e.g., `<credit-card>`).
- ### **Deployment Descriptor & Manifest Standards**
+ ### **9. Deployment Descriptor & Manifest Standards**
* **Standard Descriptors:**
* **Application**: `application.xml.`
* **Web**: `web.xml.`
@@ 96,14 103,14 @@
* **Manifest Files:** Prototype names used in source directories to distinguish files before they are renamed to `MANIFEST.MF` in the archive.
* EJB Manifest: `ejb-jar-manifest.mf.`
- ### **Modern Jakarta EE Compatibility**
+ ### **10. Modern Jakarta EE Compatibility**
While maintaining legacy code, new development must align with modern Jakarta EE practices.
* **Dependency Injection (CDI)**: Use @Inject instead of manual JNDI lookups (relative to java:comp/env) where supported.
* **REST Services**: Prefer Jakarta REST (JAX-RS) over new Servlet implementations for service interfaces.
* **Persistence**: Utilize JPA @Entity POJOs to replace legacy CMP Entity Beans.
* **Validation**: Use Bean Validation annotations (@NotNull, @Size) to replace manual validation in Web components.
- ### **Architecture & Layering Strategy**
+ ### **11. Architecture & Layering Strategy**
We adhere to a strict Separation of Concerns (SoC). Business logic must never leak into the Database or Web layers.
* **Controller (JAX-RS):** Handles HTTP requests/responses. Use DTOs (Data Transfer Objects) here; never expose JPA Entities directly to the client.
* **Service Layer (EJB/CDI):** Contains the "What" of the application. Transaction boundaries (@Transactional) start here.
@@ 113,11 120,10 @@
* **Business Layer (Service):** Core logic and transaction boundaries (@Transactional).
* **Data Access Layer (Repository/DAO):** Database interactions using JPA/Hibernate.
- ### **General Coding Standards**
- #### 1. **Dependency Injection (DI)**
+ ### **12. General Coding Standards**
+ #### 12.1. **Dependency Injection (DI)**
Use constructor injection instead of @Autowired or field injection to ensure the class remains testable and final.
- ```
- Java
+ ```Java
// Recommended
private final UserService userService;
@@ 127,10 133,9 @@
}
```
- #### 2. **Avoid "Magic Numbers"**
+ #### 12.2. **Avoid "Magic Numbers"**
Never hardcode numeric literals in logic. Use constants or Enums.
- ```
- Java
+ ```Java
// Bad
if (status == 1) { ... }
@@ 140,14 145,13 @@
if (status == STATUS_ACTIVE) { ... }
```
- #### 3. **Use StringBuilder for Loops**
+ #### 12.3. **Use StringBuilder for Loops**
For string manipulation inside loops, use StringBuilder to avoid unnecessary object creation in the heap.
- ### **EJB and CDI (Dependency Injection)**
+ ### **13. EJB and CDI (Dependency Injection)**
Modern Java EE favors CDI over older EJB styles where possible.
* **Prefer Constructor Injection:** It makes the code immutable and easier to unit test without a container.
- ```
- Java
+ ```Java
@ApplicationScoped
public class OrderService {
@@ 162,12 166,11 @@
* **Scope Awareness:** Use @RequestScoped for web-related beans and @ApplicationScoped for singleton-like services. Avoid @SessionScoped unless strictly necessary for stateful web apps to save memory.
- ### **JPA (Persistence) Best Practices**
+ ### **14. JPA (Persistence) Best Practices**
Database performance is usually the bottleneck of Java EE apps.
* **Fetch Type:** Always default to FetchType.LAZY for @OneToMany and @ManyToMany relationships to avoid the "N+1" select problem.
* **Use Named Queries:** This allows the JPA provider to pre-compile the query.
- ```
- Java
+ ```Java
@Entity
@NamedQuery(name="User.findByEmail", query="SELECT u FROM User u WHERE u.email = :email")
@@ 175,7 178,7 @@
```
* **Avoid System.out.println for SQL**: Use the persistence property javax.persistence.schema-generation.database.action and standard logging.
- ### **RESTful API Design (JAX-RS)**
+ ### **15. RESTful API Design (JAX-RS)**
* **Use Standard HTTP Verbs**: * `GET (Read)`, `POST (Create)`, `PUT (Update)`, `DELETE (Remove)`.
* **Proper Status Codes**: * 201 Created for successful POSTs.
* `400 Bad Request for validation failures.`
@@ 183,14 186,12 @@
* **Version your APIs:** Always include a version in the URL path.
* **Example**: `@Path("/v1/orders"`
- ### **Exception Handling**
+ ### **16. Exception Handling**
* **Don't Swallow Exceptions:** Never leave a catch block empty. At least log the error.
* **Specific Exceptions:** Catch FileNotFoundException rather than a generic Exception.
* **Custom Exceptions:** Create domain-specific exceptions (e.g., `UserNotFoundException`) to provide better context to the API consumer.
* **Global Exception Mapper**: Use `ExceptionMapper<T>` to catch internal exceptions and return a clean JSON response to the user.
- ```
- Java
-
+ ```Java
@Provider
public class EntityNotFoundMapper implements ExceptionMapper<EntityNotFoundException> {
@@ 201,19 202,17 @@
}
```
- ### **Logging**
+ ### **17. Logging**
* **SLF4J + Logback:** Use placeholders {} instead of string concatenation to improve performance.
* **Bad**: `logger.info("User " + name + " logged in");`
* **Good**: `logger.info("User {} logged in", name);`
- ### **Security & Validation Best Practices**
+ ### **18. Security & Validation Best Practices**
* **Input Validation**: Never trust client data. Use Bean Validation `(@NotNull, @Size, @Email).`
* **Principle of Least Privilege: **Class members should be private by default.
* **Sensitive Data**: Never log passwords, credit card numbers, or PII (Personally Identifiable Information).
* **Bean Validation:** Use standard constraints to keep logic clean.
- ```
- Java
-
+ ```Java
public class UserDTO {
@NotBlank(message = "Username is required")
@@ 226,3 225,5 @@
```
* **Encoding**: Always specify UTF-8 encoding for all web responses to prevent character corruption.
* **No Hardcoded Credentials**: All passwords, API keys, and DB URLs must be stored in environment variables or a microprofile-config.properties file.
+
+ **Document** - [JAVA EE](https://docs.google.com/document/d/1IVK8d4CH07CCje1yJsev01vM3Fq-2hpE0VWCPbEXBSk/edit?usp=sharing)
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9