Java project structure explained for newbies?

前端 未结 10 1063
攒了一身酷
攒了一身酷 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 13:53

    A package in Java is very similar to a namespace in .Net. The name of the package essentially creates a path to the classes that live inside it. This path can be thought of as the class's namespace (in .Net terms) because it is the unique identifier for the specific class you want to use. For example if you have a package named:

    org.myapp.myProject
    

    And inside it you had a bunch of classes:

    MyClass1
    MyClass2
    

    To specifically refer to those classes you would use:

    org.myapp.myProject.MyClass1
    org.myapp.myProject.MyClass2
    

    The only real difference between this and .Net (that I know of) is that Java organizes its "namespaces" structurally (each package is a distinct folder) whereas .Net allows you to scope classes using the namespace keyword and ignores where the document actually lives.

    A JAR file is roughly analogous to a DLL in most cases. It is a compressed file (you can open them with 7zip) that contains source code from other projects that can be added as dependencies in your application. Libraries are generally contained in JARs.

    The thing to remember about Java is that is is very structural; WHERE files live is important. Of course there is more to the story then what I posted but I think this should get you started.

提交回复
热议问题