• 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 a package?

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
it may seem a clumsy question to you all,but i want to ask what actually is a package?
i know it is a collection of some files,but is it a conceptual concept only?
or does it make a folder in our current directory?
for example,
i made two files in my current directory named Stuff.java and User.java


package xcom;
public class Stuff{.....}
saved it as Stuff.java

import xcom.Stuff.*;
class User{...}
saved it as User.java

when i compile User.java
it says package xcom.Stuff does not exist.



[ August 30, 2008: Message edited by: Bear Bibeault ]
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A package is an organizational unit. It is reflected in the file system as a directory structure, and in your code as name-spaces.

When you use:
package xcom;
you are declaring this class file to be in the xcom name-space, and implying that the .class file should be found in the xcom directory. The code does not, however, create the directory structure for you. You must do that yourself.

So you should make a new folder called xcom, more the Stuff.java file into it. Then when you compile User it should be able to find the xcom/Stuff.java file, compile that to xcom/Stuff.class and then use the class file to finish compiling User.java.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And there are options in the javac tool (eg -d) which will create a folder for your package (if it doesn't already exist). More details: Java Tutorial, and javac tool documentation.
 
pradeepta chopra
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay got it. thanks
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by pradeepta chopra:
okay got it. thanks

You're welcome
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then there are some accessiblity rules associated with a package

If you do not explicitly use an access modifier such as public, protected, private the class/constructor/member is said to have "package-private" or "package" or "default" access.

For example if you declare a method without an explicit access modifier, that method will be accessible only to other classes that reside in the same package.
 
reply
    Bookmark Topic Watch Topic
  • New Topic