Using an Integrated Development Environment
Duration: 30 to 40 minutes.
Integrated Development Environments, or IDEs, can greatly
facilitate the task of creating applications. Mid-level code editors,
such as Crimson Editor, TextPad, or Edit-Plus, provide syntax highlighting,
automatic indenting, parentheses and curly-brace matching, and may
have tools to compile and execute programs.
High-end environments, such as Eclipse, NetBeans, or JDeveloper, offer
many additional features, such as project management, automatic deployment
for web applications, code refactoring, code assist, etc. But, these
additional capabilities come with the price of additional complexity
in the environment, particularly because they force you to create projects for even the simplest applications.
To use the class files in these environments, we must first have a workspace,
which is a collection of projects. Workspaces have various configuration
settings that will cut across all projects within all projects they
contain, such as which version of Java is in use, any added libraries,
etc. (a project is usually one application).
Both Eclipse and NetBeans use the workspace concept, but you can start
with any empty directory - the IDE will add its own special files as
you create projects.
In the Windows Explorer, navigate to your ClassFiles directory. If it does not contain a Workspace subdirectory, create it.
To use Eclipse with the class files, you can direct it to the workspace
(ClassFiles/Workspace) when it opens (if it asks), or use
if Eclipse is already running. Each chapter's
demo folder should be treated as a project, as should each Solution folder.
One limitation of these environments is that no project can contain
the same Java class twice, so our progressive versions of the Payroll
application solution require their own individual project. Also,
due to the way Java's package structures work, each Demo folder must
be a separate project, as with each subdirectory under Solutions.
To use the Exercises folder as an Eclipse project:
Select File > New > Java Project
Exercises for the project name
- In the
Package Explorer pane, right-click on the
src folder under the
Import from the context menu
File System from the tree in the
Select dialog box
- Using the
Browse button, navigate to and select
c:/ClassFiles/Exercises. (Note: this path might be different depending on where you extracted the class zip file)
- Make sure the
Exercises check box is selected and click
- Expand the
src folder in the
Package Explorer and then expand the
default package folder
- Right-click on the file
- From the context menu select
Run As... > Java Application
- Note the output is displayed in the
Console at the bottom of the Eclipse workbench
As we encounter each chapter, we can create a project using the Demos
directory for that chapter the same way we just created the Exercises project..
To create a Java class within a project, use
, and then
if that is available, or
. Provide a name and
In general, with the several applications that we will build upon progressively
(Game and Payroll), you can continue to work with the same files, and
add to them as we cover additional topics. If you want to check the
solutions, you can either open those files in a separate editor, like
Notepad, or create a project for that Solutions subdirectory. If you
wish to save a particular stage of the application for future reference,
you can just make a copy of the Exercises directory.
The examples and instructions provided use a more basic text editor (Chrimson) and an OS console for clarity. You are free to choose which tool to use. If Eclipse becomes a problem, move to a simple editor. The focus of this course is on the Java Programming Language and not a particular tool.