Learning java newly. Can anybody clear my doubt in following?
My demo application has code like this
SourcePackages —> ex1.pkg1
|
—>food
- My ex1.pkg1 has one class called Ex11 and it contains the main function.
- My food package contains one abstract class fruit and another subclass of class fruit as Apple.
- I am creating an instance of Apple class in my main function in class Ex11.
The code compiles fine and runs also fine. But I am trying to understand the directory structure in java.
When I run the program I can see the following folders inside the build/class directory
- ex1 -> pkg1 -> Ex11.class
- food -> Apple.class and fruit.class
- fruit -> empty
I don’t understood why the directory fruit is created although I don’t have any package named fruit? Even if I delete it and compile again its not created. But created when I run the application.
Extra Info – I am using netbean IDE
To answer your question Not exactly. You can create same directory structures ( hence same package) in different locations and even in different jars. For example; you can have directories CoreDomain\com\example and CoreServices\com\example. Now, classes within these two directories will have same package com.example even though they are in different directories ( but same directory with ref. to starting point ; as both are in com.example )