This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
First, am I to understand that if you create a class file as part of an application, it's intended to be able to be used as part of other applications?
It means that you should code in a reusable manner so that various parts of your application could be plugged out, replaced or simply be reused in another application.
It's a way of organizing applications. In bigger projects you have several thousand class files. Having them all in one place is not the greatest thing. It also acts a role when it comes to access modifiers.
Third, (and I have looked in other threads for this) why won't my "GameLauncher" run? I keep getting weird error messages like: could not find the main class. See the screenshot attachment.
Launch your program from the root dir, not a package dir.
JDBCSupport - An easy to use, light-weight JDBC framework -
I made a 2 new directories and put the java files in the parent and re-compiled to the child directory. It wouldn't run from the parent, but when I ran it from the directory the class files were in it worked....
One of the other threads said to comment out the package.
What's the difference in syntax (or behavior), if any, when running it?
Joined: Oct 13, 2005
Very sensible advice to comment out the package name.
If you look at the printed versions in the book, they do not have package names. Package names are required for any large application; if you look in the Java™ Tutorials ("creating packages" you find that
If you do not use a package statement, your type ends up in an unnamed package. Generally speaking, an unnamed package is only for small or temporary applications or when you are just beginning the development process. Otherwise, classes and interfaces belong in named packages.
Your game with 3 classes counts as a "small application".
When you download the whole code from the website, however, it is a large amount of code, so you would need package names; you will see the package names correspond to the chapter numbers. That makes it easier to find the code. After all the main reason for packages is to make classes etc easier to find. But compiling such code needs a folder structure to match. There are at least three ways to do it, which I have written about before (and so have several other people on "beginning Java") so you can find them if you do a search. For beginners, it is best to use the easiest instructions for the compiler, so missing out the package names is easier. Then you use the folder you happen to be in as the "unnamed package."
Syntactically there are differences:
If you use package names, you can have several classes with the same name, in different packages.
Thanks a lot! I'm learning Java for a class I'm taking, so I'm trying not to get too far ahead of things.... but sometimes it's good to get a more thorough understanding of things even when it's stuff I don't need to know yet.
I'm a bigger picture learner so I like to know how things should work even if they don't need to.