Stage 1 — Create a New Project
- If you have not already done so, create a folder for your Java Projects for this course.
- I suggest C:\JavaProjects so that the pathname does not get too long.
- Open Eclipse and make sure that Package Explorer is visible in the left window.
- Just this once, confirm that you are in the workspace for your Java Projects, by doing:
File → Switch Workspace → Other
and browsing to the folder you created for your Java Projects for this course.
- Then press OK. Eclipse will shut down and restart.
- Hereafter, Eclipse will start out at this Workspace unless you tell it otherwise.
- From the menus, select File → New → Java Project. This will bring up the New Java Project Wizard.
- Name your project HelloWorld (no spaces, capitalized just as written).
Accept the defaults, but notice that you are choosing to Create a New Project in Workspace.
- If you don't know what a Workspace is, now is the time to find out (ask someone!).
- Choose Finish and you should be back at the Package Explorer.
Expand HelloWorld and notice what is different now in Package Explorer.
Stage 2 — Create a class with a main function
- Create a class with a main function by:
- Highlight the src folder in the Package Explorer and right-click to create a New → Class
- Name the class HelloPrinter (no spaces, capitalized just as written)
- In creating the new class, select the option to put a main method in your class.
- Just for practice, delete your newly-created class (right-click on it and ...) and then recreate it.
Stage 3 — Make your program print Hello, World and run your program
- Write the code for printing Hello, World inside main:
System.out.println("Hello, World");
- As you type, pause at the dots and notice how Eclipse gives you options for how to autocomplete.
- Run your program by selecting in Package Explorer the .java file containing main,
right-clicking, and choosing Run as → Java application.
- Notice where the output appears.
- If you have errors or don't see the output, get help now!
- Run the program again, this time using the Run button on the toolbar.
- Minimize Eclipse and go find the folders for HelloWorld, bin and src.
Unless you redirect your project workspace output, from now on all your projects will be created here.
Stage 4 — Add the project to Version Control
This step shows you how to put your project under version control;
then next stage will show you how to commit updates to the project.
- Right click on the HelloWorld project in Package Explorer, and choose Team → Share Project
- If asked, select SVN (not CVS -- Eclipse supports both version control systems, but SVN is the more modern one; Eclipse will remember the choice you make now)
and select Next
- If given a choice, select Create New Repository Location and select Next.
- If this is the first time you have used Subclipse, you won't see this dialog
because you have not told Eclipse about any existing repository locations yet.
- For future projects that are to be placed in your personal repository,
you can Use the Existing Repository Location.
- You have a personal repository for this class:
http://svn.cs.rose-hulman.edu/repos/csse220-200930-mutchler
where you replace mutchler in the above with your own Kerberos username.
In the Share Project dialog that you are now in, type the above (with your own username) as your URL.
Then choose Next.
- Type carefully! Case matters. No spaces.
- Accept the default to Use project name as folder name, and select Next.
- You are offered an opportunity to put a commit comment.
The default (Initial commit) is appropriate here.
- As your projects get more sophisticated,
make your commit comments more meaningful.
- Eclipse may ask you your SVN password. If you don't know it or have forgotten it,
ask your instructor to set it for you now.
After you choose Finish you should see log file notes in the Eclipse console window that verify your success.
If not, get help now.
- If you are in the Repository perspective,
return to the Java perspective by using the tab in the upper-right corner of Eclipse.
Stage 5 — Modify the project, then Commit the changes to Version Control
- Add another statement to main that prints Goodbye, World.
- Commit your changes to the repository by
right-clicking on the HelloWorld project in Package Explorer and choose Team → Commit.
- As before, enter a commit comment (any comment is OK for this; use meaningful comments as your projects become more meaningful).
- When you work with a team, you will use Team → Update to get updates to the project that your teammates have done.
Stage 6 — Learn how to fix errors in your program
- Make an error in your program. Then ask someone near you to use your keyboard and fix the error.
- Ask for her help only after you introduce the error; the goal is to help both of you start learning how to deal with error messages.
- Encourage her to use Quick Fix to diagnose and then fix the error, if Quick Fix is available for the error you introduced.
Stage 7 — Add a method to your program that uses a loop
- Add to your program a method that takes an integer n
and prints Hello, World n times, each on its own line.
Call the method from main, sending it 36 (so that 36 greetings are printed on the console).
- Suggestion: If you type the method call first, for example:
Main.manyGreetings(36);
then Quick Fix will offer to write a stub of the method for you! Try it!
Stage 8 — Make your program use good style
- In all your code throughout this term, fill in the Javadoc comments appropriately, at each of the places where the comment says TODO.
- We will see later how to generate HTML from those comments.
- In all your code throughout this term, use explanatory variable and method names.
- Use name completion in Eclipse, Ctrl-Space, to keep typing cost low and readability high.
- Review your code now; are there any variable or method names that you should change? If so, right-click on the name and choose
Refactor → Rename. Try refactor now, just for practice.
- In all your code throughout this term, type Control-Shift-F before you turn it in
(and occasionally throughout your coding).
- This formats your program to match a standard coding style for Java,
fixing indentation problems and the like.
- Do this step just before you commit any work;
formatting errors in your code are unacceptable,
given how easy it is to fix them.
Stage 9 — Commit the final version of this program to your repository
- Commit your changes to the repository by
right-clicking on the HelloWorld project in Package Explorer and choose Team → Commit.
- As before, enter a commit comment (any comment is OK for this; use meaningful comments as your projects become more meaningful).