PowerPoint - UNC Computer Science
Download
Report
Transcript PowerPoint - UNC Computer Science
COMP 110/401
APPENDIX: INSTALLING AND
USING ECLIPSE
Instructor: Prasun Dewan (FB 150, [email protected])
SCOPE: BASICS AND BEYOND
Basic use: CS 1
Beyond basic use: CS2
2
DOWNLOAD FROM WWW.ECLIPSE.ORG
3
EXTRACT ALL
4
SELECT DESTINATION FOLDER
5
CREATE SOME KIND OF SHORTCUT FOR
ECLIPSE.EXE
6
RUN ECLIPSE.EXE
7
SPECIFY PROJECTS DIRECTORY
8
REMOVE WELCOME TAB IF IT APPEARS
9
ADD A NEW JAVA PROJECT
10
ENTER PROJECT NAME
11
SWITCH TO JAVA PERSPECTIVE (MAY GET THIS
MESSAGE)
12
EMPTY PROJECT CREATED
13
ADD A PACKAGE TO SELECTED PROJECT
Select project and
File Package
14
ENTER PACKAGE NAME
15
EMPTY PACKAGE IN NON EMPTY PROJECT
16
ADD A CLASS
Select project and
File Class
17
NAME THE CLASS
18
EMPTY CLASS IN NON EMPTY PACKAGE
19
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]);
}
try {
System.out.println (inputStream.readLine());
} catch (Exception e) {
System.out.println("Could not read line");
e.printStackTrace();
}
}
}
Copy and paste code from:
20
SAVE (AND COMPILE) THE FILE
FileSave or CTRL+S
21
WORKSPACE, PROJECT, SOURCE PACKAGE
FOLDER
Workspace
Project
Source
Package
Class Source
22
WORKSPACE, PROJECT, BINARY PACKAGE
FOLDER
Workspace
Project
Binary
Package
Class Object
(Binary) Code
23
EXECUTE THE MAIN METHOD ON SELECTED
CLASS
Right MenuDebug As Java
Application
Can also select Run but Debug is more
defensive
24
VIEW OUTPUT IN CONSOLE WINDOW
25
PROVIDE INPUT IN CONSOLE WINDOW
26
THE OUTPUT AFTER ENTER
27
SUPPLY USER ARGUMENT:
Right MenuDebug As Debug Configuration
28
SELECT MAIN CLASS IN CONFIGURATION
29
SPECIFY AND APPLY ARGUMENT IN ARGUMENT
TAB AND PRESS DEBUG
Argument must be in
quotes. Args[0] = “Ca
Va”
Without quotes Java
will make each word a
separate argument
(args[0] = “Ca”, args[1]
= “Va”
30
EXECUTE WITH SUPPLIED ARG
31
ARG PRINTED, PROGRAM, STILL RUNNING,
WAITING FOR INPUT
Button available in
both Debug and Java
Perspective, only of
them is active
32
TERMINATED PROGRAM
33
DEBUG LAST MAIN LAUNCHED: F11
No need to select a
main class
34
CLOSING A WINDOW PERHAPS ACCIDENTALLY
35
VANISHED CONSOLE
36
WINDOWRESET PERSPECTIVE
37
WINDOWSHOW VIEW
Can selectively remove and
add sub-windows/views
38
TARGET
Basic use
Beyond basic use
39
CREATE A PROJECT FROM EXISTING CODE
Source Code of Class Examples
Zipped Directory
JavaToHTML
Click on Zipper Directory Link
in SlideShow Mode
Unzip the zipped directory
Make a Java project out of it
by following the steps
described
40
CREATE A PROJECT OUT OF EXISTING CODE:
FILENEWJAVA PROJECT
41
UNCHECK DEFAULT LOCATION BOX
42
ENTER LOCATION AND NAME
43
NEW PROJECT CREATED
But it will have errors because of missing
ObjectEditor library
44
LIBRARY LOCATION ON THE WEB
Downloads
ObjectEditor Version 3 (used in
comp110)
ObjectEditor Version 19 (used last
year)
ObjectEditor Version 20
oeall3
oeall19
oeall20
Click on the latest version to
download the jar (same as zip) and
do not unzip/unjar it
45
DOWNLOAD LIBRARY TO LOCAL COMPUTER
Do not unzip/unjar it
46
SELECT PROJECT, AND PROJECTPROPERTIES
Must do this for each project!
47
SELECT BUILD PATH, ADD EXTERNAL JAR
48
SELECT SAVED JAR
49
PRESS DONE TO COMMIT
50
CHANGE THE JAVA VERSION (IF NECESSARY):
WINDOWPREFERENCES
51
JAVACOMPILER PREFERENCES
52
REBUILD OR RECOMPILE ALL CLASSES
53
EXECUTING CODE GIVES JAVA, JAVAC
INCOMPATIBILITY ERROR
54
CHANGE THE JAVA VERSION:
WINDOWPREFERENCES
55
PRESS SEARCH BROWSE BUTTON
56
PRESS SEARCH BROWSE BUTTON TO INSTALLED
JDK (SEE APPENDIX ON INSTALLATION)
57
JRE ADDED TO ECLIPSE, SELECT IT AND CAN
EXECUTE WITHOUT ERRORS
58
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)
59
COPY TYPES FROM ONE PACKAGE TO ANOTHER:
PASTE
Select package in destination
project and package and press
CTRL-V (or FilePaste right
menu item)
60
COPYING CLASSES FROM ONE PACKAGE TO
ANOTHER: NEW CLASS 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)
61
JUMPING TO IDENTIFIER DEFINITION AND
NAVIGATION STACK
ALT + Forward Arrow
goes forwards in the
navigation stack a la
browser forward
button
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
F3 when cursor is a start
of an identifier
Makes Eclipse take you to
the definition of the
identifier in an edit window
62
FIND THE USES
CTRL-SHIFT-G when cursor is a
start of an identifier
Double clicking a method
reference
Makes Eclipse show the
methods that reference the
identifier in the search tab
Makes Eclipse show the method
and highlight all references of
the identifier
63
MULTI FILE TEXT SEARCH FOR PRINTLN
64
SEARCH RESULTS
Use CTR+SHIFT+G (shown earlier) to find
active uses of the method
65
MENUREFACTORRENAME IDENTIFIER: ALT +
SHIFT + R
Select type, right
menuRefactorRename
All references will be updated!
66
COMPLETE IDENTIFIER: CTRL + SPACE AFTER
PREFIX
public static final long NUMBER_OF_LARGE_FACTORIAL_COMPUTATIONS
= 1000000;
Give file name
67
UNDERSTAND AND CORRECT ERRORS
68
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 or a project to
refresh all imports in the selected
types/project
69
SET A BREAK POINT OR TEL ECLIPSE TO STOP
WHEN IT REACHED SOME LINE
Double clicking again will remove dot and
break point
Can also use right menu in side bar to
enable and disable break point
70
DEBUG PROGRAM AND ENTER INPUT
71
MAY GET THIS MESSAGE BEFORE BREAK POINT
HIT
72
DEBUG PERSPECTIVE AND STOPPING AT
BREAKPOINT
73
RUNSTEP OVER TO NEXT STATEMENT (F6)
74
STOPPED AT NEXT STATEMENT
Local variable
75
RUNSTEP INTO SETNUMBER (F5)
Call stack
Called method
parameters
76
RUNSTEP RETURN
OR
F7
Call stack
77
STEP OVER AND THEN STREP INTO GETFACTORIAL
Elided (Collapsed)
Instance Vars
78
EXAMINE VARIABLES
Expanded Instance
Vars
79
STEP INTO RECURSINGFACTORIAL
80
STEP OVER IF
81
STEP INTO RECURSIVE CALL
82
EXAMINE PARENT CALL
83
STEP OVER IF
84
STEP INTO YET ANOTHER RECURSIVE CALL
85
RUNRESUME TO NEXT BREAK POINT OR USER
INPUT (NO MORE SINGLE STEPPING)
86
ENTER NEGATIVE NUMBER TO TERMINATE
87
STOPPING AGAIN AT BREAKPOINT
88
TERMINATED IN DEBUG PERSPECTIVE
89
RETURN TO JAVA PERSPECTIVE
90
JUNIT: NEW CLASS WITHOUT MAIN
91
JUNIT: INSTALL JUNIT
92
JUNIT ADDED AND IMPORTED
93
RUN JUNIT
94
JUNIT RESULT
95
RETURNING TO JAVA PERSPECTIVE
96
97
FINDING THE DEFINITION
CTRL + SHIFT + G
before a identifier
98
FINDING THE DEFINITION
F3 before a use
99
EXAMINING MAIN PARAMETERS
Main
Parameters
10
0
NEW OUTPUT AND LOCAL VARIABLE
Index gets
initialized
println()
10
1
STEP OVER
10
2
STEP INTO NEXT LINE (SAME AS STEP OVER)
10
3
TERMINATING RUNNING PROGRAM
10
4
STEP INTO SETNUMBER (RUNSTEP INTO OR F5)
Call stack
Called method
parameters
10
5
STEP RETURN STEP RETURN OR F7
Call stack
10
6
STEP OVER AND THEN STREP INTO GETFACTORIAL
Elided (Collapsed)
Instance Vars
10
7
EXAMINING VARIABLES
Expanded Instance
Vars
10
8
STEP INTO RECURSINGFACTORIAL
10
9
STEP OVER IF
11
0
STEP INTO RECURSIVE CALL
11
1
EXAMINING PARENT CALL
11
2
STEP OVER
11
3
STEP INTO YET ANOTHER RECURSIVE CALL
11
4
RESUME TO NEXT BREAK POINT OR USER INPUT
(NO MORE SINGLE STEPPING)
11
5
ENTER NEGATIVE NUMBER TO TERMINATE
11
6
STOPPING AGAIN AT BREAKPOINT
11
7
TERMINATED
11
8
RETURNING TO JAVA PERSPECTIVE
11
9
TWO OTHER USEFUL BUT COMPLICATED
REFACTOR OPTIONS
Change method signature
Will try to update references to match the signature,
which can be erroneous
Extract interface of class C
Will create interface of selected public methods and
will make the interface the type of all variables
declared to be of class type
Adds potentially unwanted comments to method
headers and sometimes updates to references have
not worked in the past for me
Maybe better to get all references and update them
individually for both purposes
12
0