Introduction
If you're a Java programmer,Eclipse is the best thing since sliced bread. Eclipse not only takesthe rough edges off Java development better than any other product,but also it's a free download!
Even if you develop with just the Java compiler, javac , Eclipse can make life easier for you. Infact, Eclipse's Integrated Development Environment(IDE) makes the development process as close to fun as it can get:the first time that Java programmers fire up Eclipse and start to useit, they often find themselves thinking, This isgreat!
As with any extensive programming tool, however, Eclipse has alearning curve. In this chapter, we will brush up on fundamentalEclipse skills, from installing Eclipse to creating a simple Javaapplication. Some of these skills are covered for the sake ofreference, and you already might be adept at them, while others mightbe new to you. The goal with this book is to push the Eclipseenvelope; to do that, you must have the solid foundation this chapterprovides.
Recipe 1.1 Getting Eclipse
1.1.1 Problem
You want to tryoutEclipse.
1.1.2 Solution
Eclipse is a free download, and you can pick it up at http://www.eclipse.org. Just click the Downloads link located on theleft side of that page.
1.1.3 Discussion
The current download URL is .
Figure 1-1. The Eclipse download page
Click a mirror site close to you, choose the version of Eclipse youwant, and then select your operating system (Eclipse works witheverything from Linux to AIX to Windows). The download startsautomatically.
You can download fourdifferent versions of Eclipse:
Release builds
These releases are for general use. In most cases, when youdownload Eclipse you'll use one of the releaseversions. These builds have been tested, and the chance of comingacross serious bugs is minimal. If Eclipse were for sale, this is theversion that would be selling.
Stable builds
Stable builds are much like beta versions. The Eclipse teamtreats this build as relatively stable, but you might run acrossproblems, as in any beta version. If you'reinterested, this is where you'll find forthcomingEclipse features.
Integration builds
These are a step below stable builds; their components have beenfairly well tested, but the way they operate together still might beproblematic. If things work out OK for an integration build, it mightbe made into a stable version.
Nightly builds
The most experimental and risky of all publically availableEclipse builds, these are created every night by the Eclipse team,and they come with virtually no guarantee. My experience with thesebuilds suggests that you can run into substantial problems, so bewarehere.
Usually, you'll pick the most recent release versionof Eclipse. Allow some time for the download; depending on youroperating system, most current release versions are more than 60 MB.
1.1.4 See Also
Chapter 1 of Eclipse (O'Reilly); the Eclipse site, http://www.eclipse.org; the technicalarticles at www.eclipse.org/articles/index.html; thenewsgroups at http://www.eclipse.org/newsgroups/index.html;the current and upcoming versions page at http://www.eclipse.org/eclipse/development/main.html.
Recipe 1.10 Running Your Code
1.10.1 Problem
How do you run Java codefrom Eclipse?
1.10.2 Solution
Select Run Run As. In the list that appears, select one ofthe following items: Java Applet, Java Application, JUnit Test, orRun-time Workbench.
1.10.3 Discussion
To run the code developed over the previous few recipes, selectRun Run As Java Application (Eclipse will promptyou to save the file if you haven't already doneso). shows the results, with the outputof our code, Stay cool ., appearing in the Consoleview at the bottom.
Figure 1-13. Running Java code
And that's ityou'vedeveloped and run your first Java example.
Recipe 1.11 Running Code Snippets
1.11.1 Problem
You want to test just asection of code, without having to get awhole program to run.
1.11.2 Solution
There's another convenient way to runJava code inEclipse: you can use a scrapbook page. Scrapbookpages enable you to execute code, even partial programs, on the fly.Using scrapbook pages isn't an essential skill inEclipse, but it's a useful thing to know.
1.11.3 Discussion
After you've created a scrapbook page, you can copyand paste code to that page and run it. Create a scrapbook page byselecting File New Scrapbook Page. Enter a namefor the page, such as ScrapPage , in the File box,and click Finish. The new scrapbook page is stored in the PackageExplorer as ScrapPage.jpage, as shown in .
Figure 1-14. Using a scrapbook page
Enter the code you want to run in this new page. For instance, to runthe example code in the FirstApp project we justran, enter the following code in the scrapbook page; note that toreach the main method of our example, you have toqualify its name with the name of the package it'sin:
String[] args = {};org.cookbook.ch01.FirstApp.main(args);You select the code you want to run in the scrapbook page byhighlighting it. In this case, select all the code in the scrapbookpage, right-click it, and click Execute, or select RunExecute. (If you need imports for the code in the scrapbook page,right-click the scrapbook's code, and select SetImports in the context menu.)
| Execute runs the code in a scrapbook page, but another option alsoexists. If you select Display instead, the net return value of thecode you've selected appears in the scrapbook. Thistechnique is useful if you don't want to stud yourcode with println statements. |
|