Eclipse is an integrated development environment (IDE) which includes several tools to enable you to create, edit, compile, run and debug programs.
Eclipse is one tool we use in this course for writing programs in Java.
Follow these steps:
Start Using Eclipse
- Eclipse stores multiple classes together in a project. I recommended making a new project for each new zyLabs chapter typically. Create a new project with "File > New > Java Project"
- Enter a project name (i.e. Chapter 5 zyLabs), under project layout select "Use project folder as root for source and class files" and click finish.
- Click "don't create" if asked about module-info.java. If this file gets created, you should delete it.
-
On the left side, there should be a tab labeled "Package explorer". If this ever does not show up, go to "Window > Show View > Package Explorer. You can expand the folders within it. Here is where your class files will be stored.
- In the project explorder, right click on your project name, and click "New > Class". Then enter your class name and click finish.
- Now you would edit this file as needed.
- To run a class, click the green play button on the toolbar (when you hover over it, it says "run"). If your code has any compile errors, your file will not run. If your java file is not within a project, you will get an error when trying to run it.
Eclipse tips and tricks
- Lines in the editor with red underlines signify errors. If you hover over these, it will give you details about the error
- Lines with yellow underlines are warnings. You do not have to fix these, but they can be helpful reminders.
- Auto format code: Press (ctrl + shift + f) or on the menu bar, click "Source > Format"
- Add imports automatically: Press (ctrl + shift + o) or on the menu bar, click "Source > Optimize imports"
- Suggestions: Press (ctrl + space) to eclipse to print up code completion suggestions while typing. Select one with the arrow keys and press enter to use it.