Some Tips for Using Eclipse
description
Transcript of Some Tips for Using Eclipse
![Page 1: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/1.jpg)
SOME TIPS FOR USING ECLIPSECreating and running a Java program
![Page 2: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/2.jpg)
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)
![Page 3: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/3.jpg)
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
![Page 4: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/4.jpg)
Eclipse
Be sure Java is
selectedJava editor –
type code here
Error messages and running program
output display here
Java projects in your
workspace
![Page 5: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/5.jpg)
Create a New Java Project
Create new Java Project
File/New/Java Project
![Page 6: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/6.jpg)
Create New Project – Give it a name
Name the project
![Page 7: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/7.jpg)
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.
![Page 8: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/8.jpg)
Add a class to the project
Right-click on src. Select New/Class
New project is open
![Page 9: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/9.jpg)
Adding a new Driver Class
Give the class a name
If this is the driver class, add a main method
Make sure this is checked
Click Finish
Assign a package name
![Page 10: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/10.jpg)
Generated code
Fill in class purpose
Fill in method description
Fill in body of main method
![Page 11: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/11.jpg)
Add Another Non-Driver class Use same technique without a main method
Class name
hw1
![Page 12: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/12.jpg)
Add desired attributes
![Page 13: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/13.jpg)
Generate Default Constructor
Select me
Deselect All to Generate Default
Constructor
Select both
![Page 14: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/14.jpg)
Default Constructor
Fill in the Description
Fill in the body of the default constructor
![Page 15: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/15.jpg)
Generate Parameterized Constructor Follow the same process but do NOT deselect
the attributes (fields) All of the following code is generated
![Page 16: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/16.jpg)
Resulting code so far . . .
Fill in purpose
Fill in parameter details
![Page 17: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/17.jpg)
Generate Getters and Setters
Select me
Choose those you want
Remember it is not always desirable to have getters and
setters – depends on what needs to remain
private
![Page 18: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/18.jpg)
Added Getters/Setters
Depending on which are selected in the previous
dialog, a series of getters and setters like this is
generated
![Page 19: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/19.jpg)
Other code generators Comment out (or uncomment) the
selected lines of code
Add a block of comments to a method you have
written
Generate a toString method for your class
Generate hashCode ( ) and equals ( ) methods
![Page 20: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/20.jpg)
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.
![Page 21: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/21.jpg)
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
Which import do I need?
![Page 22: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/22.jpg)
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
![Page 23: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/23.jpg)
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
![Page 24: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/24.jpg)
Running a program
To run a program
Right-click on (or in) the driver (code)
![Page 25: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/25.jpg)
Another way to run the program …Click me
![Page 26: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/26.jpg)
… from your workspace
Submitting a project
![Page 27: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/27.jpg)
Project Folder Contents in Workspace
Contains .java files for your
project
Contains the compiled .class files
![Page 28: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/28.jpg)
The bin folder
This folder contains the compiled .class files. Do NOT submit them.
![Page 29: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/29.jpg)
The src Folder
.java files for the project
Zip ONLY these files, naming the zipped folder appropriately. DO NOT zip the containing folder
(src or DemoProject1)
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
to your zipped folder.
![Page 30: Some Tips for Using Eclipse](https://reader035.fdocuments.in/reader035/viewer/2022062813/56816556550346895dd7d555/html5/thumbnails/30.jpg)
Zipping the files
Use Send To Compressed Folder
or …
… some other archiving tool such as 7-zip
Select the files to be zipped and right-click