Java project structure explained for newbies?

前端 未结 10 1039
攒了一身酷
攒了一身酷 2020-12-07 13:15

I come from a .NET background and am completely new to Java and am trying to get my head around the Java project structure.

My typical .NET solution structure conta

10条回答
  •  一整个雨季
    2020-12-07 14:10

    A package is a grouping of source files that lets them see each others' package-private methods and variables, so that that group of classes can access things in each other that other classes can't.

    The expectation is that all java classes have a package that is used to disambiguate them. So if you open a jar file in your project, like spring, every package starts with org.springframework. The classloaders don't know about the jarfile name, they use only the package.

    There's a common practice of breaking things down by type of object or function, not everybody agrees about this. Like Cletus posted here, there's a tendency to group web controllers, domain objects, services, and data access objects into their own packages. I think some Domain-Driven Design people do not think this is a good thing. It does have the advantage that typically everything in your package shares the same kind of dependencies (controllers might depend on services and domain objects, services depend on domain objects and data access objects, etc.) so that can be convenient.

提交回复
热议问题