Recipe 1.10 Running Your Code


1.10.1 Problem

How do you run Java code from Eclipse?

1.10.2 Solution

Select Run Run As. In the list that appears, select one of the following items: Java Applet, Java Application, JUnit Test, or Run-time Workbench.

1.10.3 Discussion

To run the code developed over the previous few recipes, select Run Run As Java Application (Eclipse will prompt you to save the file if you haven't already done so). Figure 1-13 shows the results, with the output of our code, Stay cool ., appearing in the Console view at the bottom.

Before running a Java program for the first time, it's a good idea to check if Eclipse is using the JRE or JDK you want it to use. By default, Eclipse locates an installed JRE or JDK, but it might not be the one you want to use (for example, Eclipse might have located the JRE installed for a browser you're using). To check which JRE or JDK Eclipse is using, select Window Preferences to open the workbench preferences. Select Java Installed JREs in the tree pane on the left to display the Installed Java Runtime Environments preference page. The JRE or JDK Eclipse is using is checked; you can check other JREs or JDKs to make Eclipse use them instead. We'll discuss adding other JREs and JDKs in the next chapter.

Figure 1-13. Running Java code

And that's ityou've developed and run your first Java example.

Eclipse Cookbook
Inside XML (Inside (New Riders))
ISBN: 596007108
EAN: 2147483647
Year: 2006
Pages: 232
Authors: Steve Holzner

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: