If you are compiling your code from command line, then you can use the following command to automatically create the folder corresponding to your packages: -
javac -d . Account.java
This will create a folder com
in the current folder, where your Account.java
is placed, and move the class file automatically to that folder.
Note that, packages are there for your class files
. You can place your .java
file anywhere. But in addition, your corresponding .class
file should be inside a folder corresponding to your package
in your .java
file.
For e.g, see the below directory structure: -
root --+ Account.java
|
+-- com --Account.class (com is the package folder)
So, the fully qualified name of your Account
class becomes - com.Account
.
Then in order for your Account
class to be found by other class, set the classpath till the com
folder ( Note: - Don't include the com
folder in classpath).