In Java, what are the differences between source packages and test packages? Given a Java project containing several Java class files and manifest.mf files... how can you identify whether a class belongs to the source package or test package? What is the significance of creating them?
Best How To :
Source packages contain your Java class, interface, enumeration, and annotation type files. That is, anything with a .java extension. This package contains your application logic.
Test packages contain your Java test class files. These packages will typically contain your JUnit test class files.
Note that the Java Language Specification does not require the organisation of the Java source files and other files into source packages and test packages. This is purely a convention followed by most developers and also as mentioned in the comments by popular build tools such as Maven.
The significance of creating them is to provide some sort of organisation to your Java project. Imagine you have hundreds of Java class files: some for your main business logic, others for testing etc and you placed them all in one directory. Your application will still compile but if you had to locate some code in that directory, it will be tedious to say the least. On major Java projects it is typical to have thousands of Java files. If there was no organisation of those files, developer productivity would be significantly hampered.