• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the difference between a folder and a Java package in NetBeans IDE?

 
Ranch Hand
Posts: 353
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am learning to write codes in Java and also learning to use the NetBeans IDE.  So far, it looks like learning to use NetBeans is harder than learning Java.  In the IDE, I see a popup menu with the options to create a folder, a Java package and other things. When I create a folder and a Java package, they both look the same. I am unable to notice the difference between them.  Please, have a look at the two images below.  Nice if someone can oblige me with explanation of what's different between a folder and a Java package.  

Still on NetBeans IDE, I came across the following statement:

Adding a group of class files to a project's classpath tells the IDE which classes the project should have access to during compilation and execution.


My question is: Does adding a class file to a project's classpath copy the class file into the project?
Before-creation.png
[Thumbnail for Before-creation.png]
After-creation.png
[Thumbnail for After-creation.png]
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The src folder has been marked as a source folder, as in a folder holding the source code.
Every folder under that is treated as a package.

Outside of a source folder I expect you either can't create a package, or a package is just treated as a folder.

I can't answer the other question, though.
 
Biniman Idugboe
Ranch Hand
Posts: 353
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder why Java people will not, for the sake of simplicity, call a folder a folder.  Instead, they call it a Java Package. And the Netbeans IDE has an option to create a folder.  Another option to create a Java Package. Yet both play similar role - grouping files and folders.  For a learner, it gets confusing.
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a difference.

A package is a namespace where types and resources live. A package has a name such as 'com.example.app'. A package like 'com.example.app' is completely unrelated to any other package, even 'com.example'.

A folder is where files live. A folder has a name such as 'app' and has a path such as 'src/com/example/app'. The folder 'app' is related to the folder 'example' in that it is a subfolder.

The fact that javac chooses to implement a package through folders doesn't mean that I shouldn't be able to plug in my own compiler and project layout that doesn't work with folders at all. For instance, it might store the files in a blob storage. When you add a package to your project, it's clear what you mean and the IDE can help you do it correctly, even when the underlying storage is not a conventional filesystem. When you add a folder, the IDE doesn't know what it's for and throws its hands up and says "sure I'll create the folder, whatever you want".
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:
The fact that javac chooses to implement a package through folders doesn't mean that I shouldn't be able to plug in my own compiler and project layout that doesn't work with folders at all.



Repeated for emphasis.

On the IBM mainframe computers, hierarchical directories didn't exist*, but certain filename coding conventions could be used as an approximation. You might end up with a disk file named "COM.EXAMPLE.APP.TEST.CLASS" and the next file on the volume set might be name "COM.EXAMPLE.APP.UTILS.JAVA".

That's historical and never happened. For one thing, back when this was the norm, not only were filenames limited to upper-case, they also could not exceed 44 characters. But then, try squeezing a JVM into 24MB of virtual memory. Which was all that even the biggest water-cooled behemoths could manage until circa 1985.

Point is, the name/paths of Java classes are mapped to directories is that it's convenient in the context of the popular server OS's. You could just as easily store them in cloud objects, as Stephen mentioned, in SQL databases as BLOBs, and so forth. To the best of my knowledge, in fact, nowhere in the Java spec does it require a class to be a file in a directory.

And certainly the classloaders aren't so limited. In fact, a classloader could even construct a class from scratch in memory if it wanted to. The classloaders in webapp servers can pull classes from the jars in the webapps's WEB-INF/lib directory, even though officially a webapp is a WAR, which is a JAR, and the standard Java runtime does not search JARs inside of other JARS for class resources.
 
mooooooo ..... tiny ad ....
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic