Java Project Development Basics

Naming Convention

Java uses camelCase as the naming convention for variables, methods, and classes. But class names must be capitalized.

Package management

You can use Maven or Gradle for package (dependency) management.

Project Creation

Maven project

You can create a Maven project in the following way.

1. Maven command line

$ mvn archetype:generate \
-DgroupId=com.taogen.demo \
-DartifactId={project-name} \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.4 \
-DinteractiveMode=false

2. Create a Maven project in a IDE

3. Spring Initializr

Project structure

Basic Maven Application

java-project/

├── src/main/java/
│ └── com/taogen/javaproject/

├── src/main/resources/

├── src/test/java/
├── src/test/resources/
└── pom.xml
  • src/main/java: Java source code
    • com/taogen/javaproject: Base package path. It represents the domain name of your project website.
  • src/main/resources/: Static resources such as image, JavaScript, and CSS files. And configuration files.
  • src/test/java/: Test code.
  • pom.xml: Maven project configuration file.

Spring boot Web Application

java-project/

├── src/main/java/
│ └── com/taogen/javaproject/
│ ├── modules/
│ │ └── user/
│ │ ├── controller/
│ │ │ └── UserController.java
│ │ ├── entity/ (or domain/)
│ │ │ └── User.java
│ │ ├── service/
│ │ │ ├── UserService.java
│ │ │ └── impl/
│ │ │ └── UserServiceImpl.java
│ │ ├── repository/ (or mapper/)
│ │ │ └── UserRepository.java
│ │ ├── vo/
│ │ └── dto/
│ ├── util/
│ ├── config/
│ ├── aspect/
│ ├── annotation/
│ ├── constant/
│ ├── enums/
│ ├── exception/
│ ├── filter/
│ └── task/

├── src/main/resources/
│ ├── static/
│ ├── templates/
│ ├── log4j2.xml
│ └── application.yml (or application.properties)

├── src/test/java/
├── src/test/resources/

├── .gitignore
├── .gitmessage
├── Dockerfile
├── pom.xml
├── LICENSE
└── README.md
  • src/main/java: Java source code
    • modules/
      • controller/: HTTP request handlers.
      • entity/: JavaBeans, POJOs, or domain models.
      • service/: Business logic processing code.
      • repository/: Data access layer code for various persistence stores.
      • dto/: Data Transfer Objects, encapsulate values to carry data between processes or networks.
      • vo/: Value objects, a special type of objects that can hold values.
    • util/: Utility classes such as StringUtil, DateUtil, IOUtil, etc.
    • config/: Configuration files such as Redis, MySQL data source, Security, etc.
    • aspect/: Spring AOP classes.
    • annotation/: Custom Java annotations.
    • constant/: Static variable classes.
    • enums/: Java Enum type classes.
    • exception/: Custom exception classes that are extended by a java.lang.Exception class or its subclass.
    • filter/: Servlet filter classes that are implemented javax.servlet.Filter.
    • task/: Scheduled tasks.
  • src/main/resources/
    • static/: Static files such as CSS, JavaScript, image, etc.
    • templates/: Template files such as JSP, FreeMarker, Thymeleaf, etc.
    • log4j2.xml: Log configuration file.
    • application.yml: Spring boot configuration file.
  • src/test/java/: Test code.
  • pom.xml: Maven project configuration file.