Skip to main content
gamedev.net
🔒 Locked

[java] Packages

Started by jolyqr 7 replies 1.5k views
Original Post
jolyqr
jolyqr
I've got some questions dealing with the use of packages in Java. I'm using Eclipse and I have tried to run an application. This program has got some packages declarations. These declarations creates some errors in the source code. I would like to know what is a package and how could I resolve my problem. Cheers !!
Whackjack
Whackjack
A package is merely a way to group related classes. For instance, java.awt.* contains all (or most) of the classes that are AWT-related.
Packages are represented on disk as a tree of directories, with the files located in the leaf directories. So, if you wanted to run a class with the fully-qualified name of net.gamedev.AwesomeJavaGame, the class file would be located in the "gamedev" directory, which itself is located within the "net" directory.
Try looking at the project directory where Eclipse has the files. You'll see how it's arranged.
Thygrrr
Thygrrr

Hint: Google any words in the following paragraphs you don't understand... it's an explanation, though not a "layman's explanation", because I suck at these :)

Packages are somewhere between simple directory structures and namespaces, especially since static imports in java 5.

Methods, fields and classes neither declared as private, public or protected are "package protected", meaning they're friend of all other classes in the package; but not to outsiders.

Some may consider this dirty, but it helps rapid prototype development at times.
jolyqr
jolyqr
thank you
Giuoco
Giuoco
Well, some times a class can be hidden deep within a jar file (an external Jar). So if you have errors in your import statements or you have a symbol can not be resolved debug message. You might need to adjust your class path with the appropriate jar entries.

I have a fair amount of experience with eclipse so I can walk you through modifying your class path if you'd like.

Lastly, you are not alone when this happens. I've known great developers that spend hours searching for a third party class in hundreds of jar files (on larger projects). Ultimately, they adjust their class path to include the correct jar and the errors go away.

Let us know if you reslove your issue.

Thanks,
“every idea is a responsibility”
jolyqr
jolyqr
Quote:
Original post by Giuoco
Well, some times a class can be hidden deep within a jar file (an external Jar). So if you have errors in your import statements or you have a symbol can not be resolved debug message. You might need to adjust your class path with the appropriate jar entries.

I have a fair amount of experience with eclipse so I can walk you through modifying your class path if you'd like.

Lastly, you are not alone when this happens. I've known great developers that spend hours searching for a third party class in hundreds of jar files (on larger projects). Ultimately, they adjust their class path to include the correct jar and the errors go away.

Let us know if you reslove your issue.

Thanks,


Basically I have downloaded a tutorial dealing with LWJGL programming. The programme has got lots of import and package instructions. I have tried to run the application on eclipse, it doesn't work, because all the import and packages are all in red...
CaptainJester
CaptainJester
You have to add the LWJGL jars as a library to the project. Project->Properties->Java Build Path->Libraries
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Giuoco
Giuoco
Check the LWJGL eclipse instructions. They also mention some native libraries you need in your "run time" class path. That one is very important and not that obvious.
“every idea is a responsibility”
jolyqr
jolyqr
Thank you guys. I have resolved my problem !!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.