Sunday, May 6, 2012

Java Tips 1 - Project Organization

Project Organization

Once you are becoming a expert programmer, two things will eventually happen:

You can now make bigger programs for bigger purposes.
You look at other's people code to learn something from them

This is the part when being organized with your code will help you, and other programmers, get along and learn from other people's work and don't get lost in the process. If you follow a few guidelines while writing your program, you will soon realize that after a while you will follow those guidelines almost automatically, and if, for example, you  leave out a project for a couple of months because something important had to be done, and you come back to it, you will be thankful with yourself for following the guidelines.

Now let's see some of the things we can do to stay organized:

Guideline No. 1: Project creation

At this stage try to create a project with a meaningful name, one that describes a little about what is it's main purpose.
Also keep your files organized in folders. The source files in the 'src' folder (same name as the package), the binary files in the 'bin' folder, if you are using images or documents keep them all in a folder name 'data', and the documentation of your project, that you can put it in a folder called 'docs'. This way you will quickly find the information every time you need it.

Once you have this structure created, keep your source files inside their own packages. What I usually do is create a package for the Graphic User Interface (named 'src.gui') and a package for the logic (named 'src.logic'), so most of my projects have two layers of functionality. You can create more layers to include Data Base transactions or Security Layers and so on, but I recommend to have at least two.

Finally, I would recommend not to mix the Eclipse's "workspace" folder with you projects' folders. Eclipse keeps it's session files in it's own workspace, with information about your working session, your preferences, and your projects. I like to keep my projects in my own folders depending on the topic I am working now, that way I can easily find it every time I need it. Doing so, I could properly tell you exactly where is a Java project that I made 5 years ago!!

Guideline No. 2: Naming convention

Here what you can do to make your project more readable and understandable is properly naming everything you create. As with the name of the project, try to name everything else with something meaningful.

For packages, keep an organized hierarchy, and names in lower case. I recommend creating a new package once you have 3 or more classes with similar functionality. For example: src.logic, src.gui, src.logic.products, src.logic.clients, etc.
All the Classes should begin with an upper case, and if it is composed by more than one word, each word should also begin with an upper case. For example: MyMainClass, Product, Client
The contents of a Class should always have the same order. Start with the class package and file imports. Then create the constants and attributes. Now you can create the Class Constructor and all it's methods. If the class has a main method put it all the way to the end.

I suggest naming the constants all in upper case, the attributes in lower case (the first letter), the methods in lower case and the variable in lower case.


  1. Awesome, been waiting for a new guide! Thanks, this is most excellent!

  2. I really aprecciate you put these guides here. Been helping me a lot

  3. Can you make C tutorials also ?

  4. cool tutorial, keep em coming ;)

  5. I need to brush up on my computer skills..go on lol

  6. i wanna make a program that makes money grow on trees

  7. A great way to get started on a project, especially it's a big project, people need to be organised, or risk blowing it all, just because one file was in the wrong place.

  8. Programming has always fascinating me.

  9. That's useful, but those "tips" are just common sense