Results 1 to 7 of 7
  1. #1
    diggitydoggz is offline Member
    Join Date
    Dec 2008
    Posts
    55
    Rep Power
    0

    Default importing from default package?

    How do you use default classes that don't belong to any package in classes/code that is in its own, separate package?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm not sure I know what you mean by "default" classes, but if you need to use classes from another package, that means that you'll need to import them.

  3. #3
    Jary316 is offline Member
    Join Date
    Dec 2008
    Posts
    8
    Rep Power
    0

    Default

    There is a default package that is automatically imported in Java.
    If you want to import some of your own classes, or any other library, then you need to use an import statement.
    Last edited by Jary316; 01-05-2009 at 08:23 PM.

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    You also need to ensure that the classes are found in the classpath, both during development and at run time.

  5. #5
    Join Date
    Dec 2008
    Location
    Italy
    Posts
    79
    Rep Power
    0

    Default

    Default package is usually the current directory in which you invoke the JVM.
    If you need to use a class that is in a specified directory but
    • neither belongs to a package
    • nor is packaged in a .jar file

    then you need to add that directory to your CLASSPATH environment variable. Then use the import statement to import your class. But is much better to put all your classes in some package... Maybe your.name.trash...

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Not that you should ever create classes without a package, however. They should always have a package.

  7. #7
    diggitydoggz is offline Member
    Join Date
    Dec 2008
    Posts
    55
    Rep Power
    0

    Default

    Quote Originally Posted by raffaele181188 View Post
    Default package is usually the current directory in which you invoke the JVM.
    If you need to use a class that is in a specified directory but
    • neither belongs to a package
    • nor is packaged in a .jar file

    then you need to add that directory to your CLASSPATH environment variable. Then use the import statement to import your class. But is much better to put all your classes in some package... Maybe your.name.trash...
    Thanks for the replies. How do you add the directory to your CLASSPATH environment variable? That's what my textbook said too but I couldn't figure out how to do it.

Similar Threads

  1. Importing a zipped package to Eclipse
    By Abder-Rahman in forum Eclipse
    Replies: 10
    Last Post: 02-24-2010, 06:26 PM
  2. Need help with importing classes
    By Deathmonger in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 11:03 AM
  3. Importing / compiling and running with .jar package
    By splinter64uk in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 03:47 AM
  4. Importing package
    By bugger in forum New To Java
    Replies: 5
    Last Post: 11-26-2007, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •