-1

I'm relatively new to java. I have a book that is helping me, I'm trying to make a package and the book is no help right there it's telling me I have to go into the file directly and make one. But YouTube is telling me otherwise.

  • A package is generally just a folder that contains the java class files. So if you are writing your code using a text editor, then yes, you can just make a new folder. If you are using an IDE you can do it within the application. – sorifiend May 03 '21 at 23:06
  • On disk, a package is just a folder. In Java, it designates where resources are located. It can be confusing sometimes to compile and run a java program from the command line without understanding packages and class/source file relationships. I suggest you check out the [Java Tutorials](http://docs.oracle.com/javase/tutorial/index.html) for more detailed information on this topic, – WJS May 03 '21 at 23:07

1 Answers1

-1

If you work with an IDE, it should help a lot.

In Java, a package is a declaration at the start of your class files. It also matches the folder hierarchy where this file is stored, from your project's root (source path).

e.g. to declare class MyClass in package foo.bar, you do it in file foo/bar/MyClass.java:

package foo.bar;

import whatever.other.classes.you.need;
...

class MyClass {
  ...
}
julien.giband
  • 2,467
  • 1
  • 12
  • 19