Tuesday, April 3, 2012

Java Tutorial & Lesson 2 - Setting up a Project on Eclipse

Set up The Eclipse IDE for a Java Project

Once you have installed the required software, open the Eclipse IDE. Once started, it will ask you for a working directory. Select any empty directory and continue.

Now let's get to the programming!

How to create a Java Project

Right-click the Package Explorer (Left Panel of Eclipse) and create a new Java Project:

(Note: if you can't see any of the panels mentioned here, just go to Window>> Show View and select the missing panel. You can also relocate it by dragging and dropping wherever you want)

In the next menu I recommend no using the default location (it's just a personal preference) but instead saving your project to a different folder, this way you can keep all your projects organized:

Click next and again you can modify some of the specifics of the project. This time Check "Allow output folders for source folders" and click finish:

How to Create a Package and a Java Class

Now that we have a Java project, right-click on the src folder (the src or "source" folder will contain all our source code) and create a new package. This is for organization purposes.

Name it however you want, but remember that it should start with a non-capital letter to follow the Java Standards (this will make your code more readable to other programmers). Some suggestions are: "main" (maybe too generic), "world", "gui" (for Graphic User Interface). I will go with main.

Create a new Class by right-clicking your new package as shown in the image below:

Again you can name it however you want, this time it should start with a capital letter. Don't worry if you forget these Java standards because Eclipse will remind you and suggest you to change it if you do so:

Some suggested names are "MyFirstClass", "MainClass" or even "HelloJava". Again I will go with just "Main" (I like to keep it simple for small projects like this).

So here we have our first Java code. These three lines are the first lines you will see depending on the name of the package and the name of the class that you chose.

Please feel free to comment and ask if you have any questions, your feedback will be greatly appreciated.

No comments:

Post a Comment