Download presentation
Presentation is loading. Please wait.
1
Some Tips for Using Eclipse
Creating and running a Java program Some Tips for Using Eclipse
2
Eclipse Eclipse is an Interactive Development Environment (IDE) for Java programmers It provides A project manager to manage all Java projects throughout the semester An code editor that helps write correct Java instructions (no need for NotePad++) An execution environment in which one can compile, test, and run Java programs without leaving Eclipse (no more Command Line use)
3
Eclipse Workspace An Eclipse Workspace is simply a folder where all Java projects for the semester will be stored You must remember where it is once you select it It must be a place where you have write access permissions It must be a place that you can access when you need it Example: thumb drive, Z:\ drive, portable hard drive, or cloud storage such as DropBox, OneDrive, Box, etc. Make sure there is enough space in the Workspace to hold all projects for the semester
4
Eclipse Java projects in your workspace Be sure Java is selected
Java editor – type code here Error messages and running program output display here
5
Create a New Java Project
Create new Java Project File/New/Java Project
6
Create New Project – Give it a name
Name the project
7
New Project in the Package Explorer
After creating a new project as on the previous slide, it will appear in the Package Explorer column on the left in Eclipse Project name Subfolder for .java files Java library – contains Java API classes such as String, Scanner, etc.
8
Add a class to the project
Right-click on src. Select New/Class New project is open
9
Adding a new Driver Class
Assign a package name Give the class a name If this is the driver class, add a main method Make sure this is checked Click Finish
10
Generated code Fill in class purpose Fill in method description
Fill in body of main method
11
Add Another Non-Driver class
Use same technique without a main method homework1 Class name
12
Add desired attributes
13
Generate Default Constructor
Deselect All to Generate Default Constructor Select both Select me
14
Default Constructor Fill in the Description
Fill in the body of the default constructor
15
Generate Parameterized Constructor
Follow the same process but do NOT deselect the attributes (fields) All of the following code is generated
16
Fill in parameter details
Resulting code so far . . . Fill in purpose Fill in parameter details
17
Generate Getters and Setters
Choose those you want Remember it is not always desirable to have getters and setters – depends on what needs to remain private Select me
18
Added Getters/Setters
Depending on which are selected in the previous dialog, a series of getters and setters like this is generated
19
Other code generators Comment out (or uncomment) the selected lines of code Add a block of comments to a method you have written Use the tostr template instead Generate hashCode ( ) and equals ( ) methods
20
Renaming an attribute or method
Use Refactor / Rename to change the name of a method or attribute of a class, a local variable, parameter, or even the name of a class. This changes the name everywhere it appears in the code.
21
Which import do I need? If you refer to a class that is not in your own project or in any imported class, Eclipse puts a red squiggly line underneath the reference
22
Let Eclipse help you select the right import
Hover the mouse cursor over the underlined word and a tool-tip will appear; choose what you want from the tool-tip and Eclipse does rest Click this choice
23
Alternatively, do this Press ctrl-shift-O (letter O, not zero) and Eclipse will fill in the correct import for you or it will list possible imports and let you choose one
24
Some other keyboard shortcuts
Description Ctrl-Numpad_Divide Collapse all code and comments to single lines Ctrl-Numpad_Multiply Expand all code and comments Ctrl-F Find and Replace Ctrl-Shift-F Format the code file according to Eclipse settings Alt-Shift-J Add a JAVADOC comment Ctrl-Shift-O Ask Eclipse to help determine needed “import”
25
Right-click on (or in) the driver (code)
Running a program Right-click on (or in) the driver (code) To run a program
26
Another way to run the program …
Click me
27
Submitting a project … from your workspace
28
Project Folder Contents in Workspace
Contains package(s) and .java files for your project Contains the compiled .class files
29
This folder contains the compiled .class files. Do NOT submit them.
The bin folder This folder contains the compiled .class files. Do NOT submit them.
30
The src Folder
31
The homework1 Package Folder
Zip ONLY package folder(s) and their .java file contents, naming the zipped folder appropriately. DO NOT zip the containing folders (src or DemoProject) If you are using a non-Windows machine such as a Mac or a Linux machine, it is your responsibility to be sure your system does NOT add extraneous folders and other items in your zipped folder.
32
Zipping the folders Select the folder(s) to be zipped and right-click
… some other archiving tool such as 7-zip Use Send To Compressed Folder or …
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.