Default Directory for packages

Default Directory for packages

I am a newbie in java I Want to know that what is the default directory for packages in java ? I Mean if i compile a java file which contains a package statement,and i compile it without using -d option in javac command,then where will be the package created ? eg.

package test;
class Test{}

and compile it using javac Test.java
then where will be the package created?

Thanks

If you don’t specify -d, the class file will be created in the same directory as the source file.

That’s fine if you’re already storing your source in a directory structure matching your package structure (and if you’re happy for your source and class files to live in the same place) but if your source structure doesn’t match your package structure, you’ll basically end up with class files in locations where they can’t sensibly be used.

Personally for anything other than quick throwaway (usually Stack Overflow 🙂 code I would make the following suggestions:

  • Avoid using the default package
  • Keep your source code in a directory structure (e.g. with a root of src) matching package structure
  • Generate class files into a separate directory structure (e.g. with a root of bin or out or classes)

(Sorry, misread the question to start with.)

-d option in javac command is use to specify where to generate the class file,if you don’t specify it,then the .class file will be created in the same directory where your .java file is present.

.
.
.
.