Join Charles Kelly for an in-depth discussion in this video Creating a Java project, part of Up and Running with Eclipse.
In this movie, we'll take a first look at a Java-Editor. Note that we've copied this file HelloWorld.java into the Exercise Files from Chapter 2. Eclipse requires that all Java files being a Java project. To create a Java project, we use the context menu, New and Java Project. Give the Project a name and we'll select all the defaults, select Finish and we have a Project. A Java requirement is that all Java-class files exist within a namespace.
This namespace is encapsulated by a package. In order to create a package what we do is; we use the context menu, same New and Package, and we'll give this the name com.charleskelly.hello, select Finish. Now what we'll do is we'll take this HelloWorld.java file from our previous project, copy it, and paste it, into this package. If we expand the package, we see the HelloWorld.java file, we can double-click on it, and we can see the file.
We are not going to do any programming right now, but what we'd like to do is see if we have a file that contains a valid Java class file, we can run that from within Eclipse. In order to do this, we select the context menu, select Run As, and run this as a Java Application. And as you'll see, HelloWorld is printed here in the Console view. Alternatively, what we could've done is used these buttons here: Debug, Run, etcetera.
If we select Run, the same thing happens; HelloWorld is presented in the Console view. The idea of a HelloWorld program comes from the 1970s and the C language, when it's author Brian Kernighan established Hello World as a method of determining whether a valid file could be created, and whether that file could run on a particular computer. If you follow these steps and you see HelloWorld in your Console view, you'll know that your Eclipse version is properly configured and you can run Java programs.
- Downloading and installing Eclipse for Mac or Windows
- Exploring the toolbar
- Creating a new project
- Changing views and perspectives
- Using the editor
- Working with JUnit and templates
- Using Javadoc
- Using the code completion features
- Exploring syntax checking
- Getting help with Eclipse
- Extending Eclipse