| 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).
* **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.