Comp 110/401
Appendix: Installing and Using Eclipse
Instructor: (FB 150,
Copyright By PowCoder代写 加微信 powcoder
Shortcuts (MSFT)/Commands
Block quote/unquote (CTRL-/)
Run project (CTRL-F11)
Search project for strings (Select project, SearchFile)
Step into, over, return (F5, F6, F7)
Copy a project (CTRL-C, CTRL-V)
Copy a package, class file to another project (CTRL_C, CTRL-V)’
Show variable, class, interface (identifier) definition (click, F3 or Right Menu Open Declaration) and return back (ALT )
Find identifier (variable, class, interface) use (Click, CTRL-SHIFT-G, Right MenuReferences)
Refactor (Click, CTRL-SHIFT-R or Right MenuRefactor)
Complete identifier name (CTRL-Space)
Automatic imports (CTRL-SHIFT-O)
Change Method Signature (Click ALT_SHIFT-C, Right MenuRefactor)
Extract interface (Click ALT_SHIFT-C, Right MenuRefactor)
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Supply main argument
Create project from existing code
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Supply main argument
Create project from existing code
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Check with instructor which JDK version to get
Follow Download Link: Accept License Agreement, Find JDK for Appropriate Platform, and Click on exe Link to Download EXE in some temporary folder
Run Exe and Choose JDK Folder
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Download from www.eclipse.org (Windows)
Get the latest IDE for Java Developers, not Indigo
Download from www.eclipse.org (Windows)
Get the latest IDE for Java Developers, not Indigo
Extract All
Select Destination Folder
Create some kind of Shortcut for Eclipse.exe
Run Eclipse.exe
Specify Projects Directory
Remove Welcome Tab if it Appears
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Change the Java Version: WindowPreferences
Press Search Browse Button
Press Search Browse Button to Installed JDK
Jre added to Eclipse, Select it and Can Execute Without Errors
Some Explicit Instructions – for MAC (assume Java 7)
You can get that for mac here:
https://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html. Pick the Mac option and from there it should just be like installing any other application.
Or you can go here:
http://download.oracle.com/otn-pub/java/jdk/7u40-b43/jdk-7u40-macosx-x64.dmg
The problem is Eclipse won’t change the compiler to use 1.7 so you will have to specify that under:
Eclipse -> Preferences -> Java -> Installed JREs
Click “Add…” then choose “MacOS X VM”
Next, then under directory copy/paste this:
/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
Make sure it recognizes this as Java SE 7. Then name doesn’t really matter.
Now go to:
Eclipse -> Preferences -> Java -> Compiler
Change the compliance level to: “1.7”
Now it probably still won’t work (at least it didn’t on mine)
This is because your project is still set on 1.6
So, go to:
Project -> Properties -> Java Build Path -> Libraries
Add Library…
JRE System Library
“Workspace default” should be automatically there as the 1.7, but if not find the 1.7 library.
Then remove the 1.6 library
Also you need to change the compiler being used by the project:
Project -> Properties -> Java Compiler
and make sure everything is on 1.7
Now, if you’re getting an error about the main class not being found or working.
You may just want to create a new project and when you select the 1.7 JRE.
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Add a Project
Project Name and Separate Folders
The separate folder option puts .java source files in src folder and .class files in bin folder – required for the auto grader
Switch to Java Perspective (May get this message)
Empty Project Created
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Add a Package to Selected Project
Select project and File Package
Enter Package Name
Empty Package in Non Empty Project
Add a Class
Select project and File Class
Name the Class
Empty Class in Non Empty Package
Edit the File (Copy and Paste Code)
package warmup;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class AGreeter {
static BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) {
System.out.println(“Hello World”);
if (args.length > 0) {
System.out.println(args[0]);
System.out.println (inputStream.readLine());
} catch (Exception e) {
System.out.println(“Could not read line”);
e.printStackTrace();
Copy and paste code from:
Save (and Compile) the File
FileSave or CTRL+S
Workspace, Project, Source Package Folder
Source Package
Class Source
Workspace, Project, Binary Package Folder
Binary Package
Class Object (Binary) Code
Execute the Main Method on Selected Class
Right MenuDebug As Java Application
Can also select Run but Debug is more defensive
Find or Switch Workspace Folder: FileSwitch Workspace
Find Project Folder: Select Project, Right ClickPropertiesResource
View Output in Console Window
Provide Input in Console Window
The Output after Enter
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Closing a Window perhaps accidentally
Hide Console
Vanished Console
WindowReset Perspective
WindowShow View
Can selectively remove and add sub-windows/views
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
File Search in a Project (useful in Java Teaching and Your projects)
Suppose you want to search the entire project for some string such as some text in a Sakai question: such as “println(c) displays”
Select Project
Select project (not the src folder)
Suppose you want to search the entire project for some string such as some text in a Sakai question: such as “println(c) displays”
FileSearch
Search Dialog
Search string
Scope of search
Search Results
Search view shown, console in another tab
Search Results Zoomed
Look at all the tabs availalale here
Multi File Text Search for Println
Search Results
Text search, shows uncommented println() also
Use CTR+SHIFT+G (shown earlier) to find active uses of the method
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Setting a Break Point
Double click where you want program to stop
Starting the Debugger
Stopping at Breakpoint
Debug Perspective
Next statement to be executed
Examining Main Parameters
Main Parameters
Stepping to next statement
Next Statement
and Local Variable
Index gets initialized
println() executed
Call stack
Called method parameters
Step Return
Returning to Java Perspective
Debug Last Main Launched: F11
No need to select a main class
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Library Location on the Web
Click on the latest version (on my web page, not this page) to download the jar (same as zip) and do not unzip/unjar it
Download Library to Local Computer
Do not unzip/unjar it
Select Project, and ProjectProperties
Must do this for each project!
Select Build Path, Add External Jar
Select Saved Jar
Select Build Path, Projects
Remove Spurious Projects (if any)
Press Ok to Commit
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Create a Project out of Existing Code: FileNewJava Project
Uncheck Default Location Box
Enter Location and Name
But it will have errors because of missing ObjectEditor library
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Copying a Project
Select project, CTRL CTRL-V
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Copy Types (Classes, Interfaces, Enums) from Package to Another: Copy
Select type(s) in source project and package and press CTRL-C (or FileCopy right menu item)
Copy Types from One Package to Another: Paste
Select package in destination project and package and press CTRL-V (or FilePaste right menu item)
Copying Classes from One Package to Another: in new Package and Project
Repackaged type added (and its imports are changed to other copied types if multiple types are copied and pasted together)
Package name changed
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Deleting a Project
Right click project and delete. Usually not a good idea to delete project on disk, can always use the OS to do so, which will put it in the recycling bin
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Jumping to Identifier Definition and Navigation Stack
F3 when cursor is a start of an identifier
Makes Eclipse take you to the definition of the identifier in an edit window
Cursor position
ALT + Back Arrow takes you back where you came from, a la Browser back button, can execute multiple times to back in in the stack of visited points
ALT + Forward Arrow goes forwards in the navigation stack a la browser forward button
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Find the Uses
CTRL-SHIFT-G when cursor is a start of an identifier
Cursor position
Makes Eclipse show the methods that reference the identifier in the search tab
Double clicking a method reference
Makes Eclipse show the method and highlight all references of the identifier
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
MenuRefactorRename Identifier: ALT + Shift + R
Select type, right menuRefactorRename
All references will be updated!
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Complete Identifier: Ctrl + Space after Prefix
public static final long NUMBER_OF_LARGE_FACTORIAL_COMPUTATIONS = 1000000;
Give file name
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Understand and Correct Errors
Hover to understand
Click for correction proposal
Install JDK
Install Eclipse
Connect JDK to Eclipse
Create project
Edit project run project
Restore window
Search project for strings
Adding a library
Add an existing project
Copy a project
Copy a package, class file to another project
Delete a project
Show variable, class, interface (identifier) definition and return back
Find identifier (variable, class, interface) use
Complete identifier name
Understand, fix errors
Automatic imports
Change Method Signature
Extract interface
Correct All Import Errors in File: Ctrl + Shift + O
In Eclipse press CTRL-SHIFT-O to automatically import all used types that need to be imported but have not been imported
If class is in more than one package, Eclipse gives a choice
All unused imports are also removed
Can select multiple types o