Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Directory for packages

Tags:

java

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

like image 353
user197122 Avatar asked Mar 24 '23 09:03

user197122


2 Answers

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.)

like image 73
Jon Skeet Avatar answered Apr 02 '23 03:04

Jon Skeet


-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.

like image 43
Shivam Dhabhai Avatar answered Apr 02 '23 03:04

Shivam Dhabhai