简体   繁体   中英

is it possible to have .class and .java classes inside the same source code package?

While going throw some open source programs source code, I realized that some projects have .class and .java inside their source code files! I understand that .class is an already compiled .java file, and that .class is binary but is it possible to have compiled and uncompiled files in a project? if yes, then why to do that? what are the benefits?

long story short: am trying to study test classes in different projects, where I realized that some programs have test files under the (build) folder, where they have .class as extension! Do these classes differ in behave than test classes located under test package with .java extension? is there anyway to decompile them?

thanks

Class files and Java files share the same subdirectory structure defined by the package structure.

IDEs like eclipse allow you to put the class files either into the same folders as the corresponding source files or into another (duplicated) folder structure.

Which of these options you choose is a matter of taste, I'd say.

It is possible, in fact if you run the java compiler ( javac ) without specifying the '-d' option to indicate a specific directory where to place the generated classes, by default it will place them in the same directory as the source files.

There is no conflict doing this, as the javac compiler and jvm launcher ( java ) are not looking at the same file extension.

However, it is generally considered a best practice to place the generated class files in a separate folder under the project: classes, bin, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM