Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Trying to Figure out Packages

  1. #1
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Trying to Figure out Packages

    After awhile I learned how to use multiple class files instead of having a huge singular file and now I'm trying to figure out how to keep organized with all my class files. I've looked up packages and read the official tutorial, although a few of the words threw me off I managed to figure out a few things. My question is, am I using packages properly?

    File structure:

    thing Folder
    -> enemy Folder
    -> functions Folder
    -> player Folder
    -> skills Folder

    Thing Folder is the main folder and then all the others are within the thing folder.

    For Creature.java within the enemy folder the first line is "package thing.enemy;", all of the other .java files in the other folders are similarly named; they all start with Thing then they go to the next folder and sometimes even one after that so some files have "package thing.skills.cooking;".

    When I want to use, for example, Rolls.java from the functions folder I'd write "import thing.functions.Rolls;" in the class that I want to use Rolls in.

    Is this how to properly use packages or am I doing something wrong?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Trying to Figure out Packages

    Seems pretty reasonable to me. Although you might want to resist the urge to overly-package your code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    tyeeeee1 (February 18th, 2013)

  4. #3
    Member tyeeeee1's Avatar
    Join Date
    Sep 2012
    Posts
    61
    Thanks
    31
    Thanked 2 Times in 2 Posts

    Default Re: Trying to Figure out Packages

    Thanks for checking and for the advice. ^.^ I had to get a second opinion because when I tried using Netbeans for the first time a few minutes ago it had every single package line underlined saying that it was wrong, I guess it's just because of some weird Netbeans thing I didn't know. =P

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Trying to Figure out Packages

    Just make sure that your directories match up to your packages exactly. I don't know about netbeans, but eclipse doesn't like it when you modify the project outside of the IDE, so if you're creating the package directories manually outside netbeans, try refreshing the project to make sure it sees the changes.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. The Following User Says Thank You to KevinWorkman For This Useful Post:

    tyeeeee1 (February 18th, 2013)

Similar Threads

  1. packages
    By Spidey1980 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 6th, 2011, 06:45 PM
  2. Packages and Servlets
    By god1gracious in forum Java Servlet
    Replies: 3
    Last Post: October 1st, 2011, 10:05 AM
  3. Meaning of Java Packages
    By Effrego in forum Java Theory & Questions
    Replies: 1
    Last Post: February 5th, 2011, 05:18 PM
  4. Problem with Packages
    By pirezas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 12th, 2010, 03:41 PM
  5. importing packages..
    By chronoz13 in forum Java IDEs
    Replies: 4
    Last Post: November 23rd, 2009, 05:49 PM