Building Projects with Java IDEs

Eclipse

Creating a Project File for a simple Java application

  1. From the "File" menu, pick "New", then "Java Project". This opens a dialog box for you to select your settings
  2. Type a project name in the "Project Name" box
  3. Under Contents
  4. Default settings under "JRE" are fine
  5. Recommend choosing "Use project folder as root for sources and class files" at the start, for simple examples and assignments. This will place your resulting class files in the same folder as your source.
  6. Clicking "Next" will take you to another screen with other settings options. You shouldn't need those early in the course
  7. Clicking "Finish" will create your project file.

Creating source code files to add to your project

  1. "File" menu -- "New" -- pick the type of file to create. Usually this will be "Class"
  2. Dialog box will come up with some options. At the very least, you'll need to type thge name of the class into the "Name" box
  3. Other options will become more clear as we get to new topics
  4. If you want this class to have a "main()" in it, you can click the appropriate box under "Which method stubs would you like", and the framework of main() will be auto-inserted for you
  5. Once you click "Finish", the file will open in the built-in text editor. Type your code, and make sure to "Save"

Compiling and running

To compile and test run your project from within NetBeans:

NetBeans

First, you'll need to have the NetBeans program installed on your computer. Get this from sun.com:

Creating a Project File for a simple Java application

  1. From the "File" menu, select "New Project"
  2. You'll see a pop-up dialog window that asks what kind of project. For now, go ahead and pick "Java Application" (which should be the default selection. Click "Next".
  3. The next screen of the dialog gives you some choices to fill out. For the initial projects in this course, you don't need any overly advanced options. Here are the recommendations:
  4. IMPORTANT: IF you check this box (Create Main Class), JavaBeans will try to give you a recommended default name for the main class, usually something like "myproject.Main". The default usually places your code inside a "package". This is more complex than you need right now.
  5. Click "Finish" on the current dialog box
  6. NetBeans will open up your project. A window on the left will show files currently in your project. A window on the right will display source code files you have open. A starter code file will appear for you to start typing code in.

Adding more source code files to your project

Some programs will involve writing multiple classes, possibly in multiple files. To start a new code file within the currently open project:
  1. Select "New File" from the "File" menu
  2. In the dialog box that comes up, pick the type of file, then click "Next".
  3. On the next screen, type the class name in the appropriate box
  4. Other settings on this window
  5. This will open up another java code file for you to edit. Make sure to save after you add code (File menu, "Save")

Compiling and running

To compile and test run your project from within NetBeans: