Friday, September 20, 2013

Building a Simple Java Program Part 2: Setting Up the Java Enviroment

          In the last Blog, we looked at setting up Java in the OS and installing Eclipse.  Make sure you have gone through those instruction before you continue.  It will get frustrating when things wont work because something isn't set up correctly.  Now, let talk about what Eclipse is going to do for us.  Eclipse is going to color code and auto format the code.  It will also provide shortcuts for auto filling in code.  I will touch on some of that as I go.  Eclipse will provide the compiling of Java code and automatically separate the source from the java binaries.  There are a lot more it can do, but for our purposes, we will stick with just a few. The first thing we are going to do is decide what our program is going to do.

         What we are going to do is create a Car.  That's right, we are going to create a virtual car that is going to have properties.  This will give you an idea of why object oriented programming (OOP) is one of the best things that has happened to programming.  There is plenty on the internet about what OOP so I'm not going to go into details.  I will tell you when you are working with it.  Also, there is a lot of formatting that is required in Java.  I will explain when formatting is required.  Let's get started by setting up Java packages in Eclipse.

          Packages in Java help us by organize our code or objects.  To start, lets get to the Eclipse workbench.  If you haven't already, click on the workbench on the Eclipse welcome page.  If you already clicked it once before, you should be at the workbench already.  Eclipse should look like this:


To get started, right click the mouse in the 1 area on Eclipse shown as an example below:


Hover mouse over new and left click Java Project:



Within the Project name text box, give your project a name.  I named mine training, but you can name it whatever you want.  This name is so you can identify it.  It wont effect Java.  You can also chooses your JRE environment. However for what we are doing here, it's not needed.  Leave everything else at defaults.  When you open the new package, you'll see an src and JRE System Libary drop down.  If you don't, try clicking the small triangle to expand the project:


We are only going to work in the src folder.  Next, we are going to create some packages within the src folder.  These packages will effect how Java operates.  I will explain whats going on as we move through the tutorial. Let's create three packages.  They are going to be called test.example.car, test.example.car.parts, and test.example.models.  Do this by right clicking on the src folder, hovering over New, then selecting package:



Click finish and do this two more times until you get all three packages into the src folder (As shown below).


 Now we are ready to start getting into the meat of making a Java program.  These packages we just made here will help us organize our virtual car.  If your new to Java, this probably doesn't make sense yet.  Don't worry, it will once we get to the coding.





No comments:

Post a Comment