Loading...
Loading...
A collection of Java development standards based on the Alibaba Java Development Manual (Songshan Edition). It covers seven areas: coding conventions, exceptions and logging, unit testing, security standards, MySQL databases, project structure, and design conventions. Use this skill when the user needs to: (1) write or review Java code, (2) check naming/code standards, (3) handle exceptions and logging, (4) write unit tests, (5) perform secure coding, (6) design databases, or (7) design project architectures. Trigger terms: Java standards, Alibaba standards, coding standards, development manual, coding conventions, exception handling, unit testing, security, MySQL, project structure, design patterns.
npx skill4agent add full-stack-skills/java-skills java-development-manual| Level | Meaning | Description |
|---|---|---|
| Mandatory | Must be followed | Violations may cause serious problems |
| Recommended | Recommended | Improves code quality and maintainability |
| Reference | Optionally adopted | Choose based on the actual situation |
| Chapter | Applicable Scenarios | Detailed Documentation |
|---|---|---|
| Coding Conventions | Naming, formatting, OOP, concurrency, collection handling | coding-convention.md |
| Exceptions and Logging | Error codes, exception handling, logging standards | exception-log.md |
| Unit Testing | Test cases, coverage, Mock | unit-test.md |
| Security Standards | SQL injection, XSS, CSRF, data masking | security.md |
| MySQL Database | Table creation, indexes, SQL, ORM | mysql.md |
| Project Structure | Layered architecture, dependency management, servers | project-structure.md |
| Design Conventions | UML, design patterns, design principles | design.md |
// 类名:UpperCamelCase
public class UserService { }
public class UserDO { } // DO/DTO/VO例外
// 方法名/变量:lowerCamelCase
private String userName;
public void getUserById() { }
// 常量:全大写+下划线
public static final int MAX_RETRY_COUNT = 3;
// 包名:全小写
package com.company.project.service;| Prohibited | Reason |
|---|---|
| Pinyin-based naming | Poor readability |
| Magic values | Difficult to maintain |
| Performance and maintainability issues |
| Creating thread pools with Executors | May cause OOM |
| String concatenation for SQL | Injection risk |
| return in finally | Loses the try return value |
| remove within foreach | ConcurrentModificationException |
| Required | Reason |
|---|---|
Add | Prevents signature errors |
| Required table fields | id, create_time, update_time |
| Mask sensitive data | Privacy protection |
| Validate parameters | Security protection |
| Clean up ThreadLocal | Prevents memory leaks |
| Use placeholders in log messages | Performance optimization |
// 正确的异常处理
try {
// 业务逻辑
} catch (SpecificException e) {
logger.error("操作失败, 参数: {}", params, e);
throw new BusinessException("用户友好提示", e);
} finally {
// 资源关闭(JDK7+ try-with-resources)
}-- 建表必备
CREATE TABLE example (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- 索引命名
-- 主键: pk_字段名
-- 唯一: uk_字段名
-- 普通: idx_字段名// 线程池创建
ThreadPoolExecutor executor = new ThreadPoolExecutor(
corePoolSize,
maximumPoolSize,
keepAliveTime,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>(queueCapacity),
new ThreadFactory() {
private AtomicInteger counter = new AtomicInteger(1);
public Thread newThread(Runnable r) {
return new Thread(r, "worker-" + counter.getAndIncrement());
}
},
new ThreadPoolExecutor.CallerRunsPolicy()
);
// ThreadLocal使用
try {
threadLocal.set(value);
// 业务逻辑
} finally {
threadLocal.remove(); // 必须回收
}