Java project structure explained for newbies?

前端 未结 10 1056
攒了一身酷
攒了一身酷 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:58

    From Wikipedia:

    A Java package is a mechanism for organizing Java classes into namespaces

    and

    Java packages can be stored in compressed files called JAR files

    So for package a.b.c, you could have Java classes in the a, a.b, and a.b.c packages. Generally you group classes inside the same package when they represent related functionality. Functionally, the only difference between classes in the same package and classes in different package is that the default access level for members in Java is "package-protected", which means that other classes in the same package have access.

    For a class a.b.c.MyClass, if you want to use MyClass in your project you would import a.b.c.MyClass or, less recommended, import a.b.c.* Also, for MyClass to reside in package a.b.c in the first place, you would declare it in the first line of MyClass.java: package a.b.c;.

    To do this you could JAR up the whole package (including packages b and c and class MyClass) and put this JAR into your $CLASSPATH; this would make it accessible for your other source code to use (via the aforementioned import statement).

提交回复
热议问题