c omp 110/401 a ppendix : i nstalling and u sing e clipse instructor: prasun dewan (fb 150,...

120
COMP 110/401 APPENDIX: INSTALLING AND USING ECLIPSE Instructor: Prasun Dewan (FB 150, [email protected])

Upload: stella-cannon

Post on 16-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Slide 1

Comp 110/401 Appendix: Installing and Using EclipseInstructor: Prasun Dewan (FB 150, [email protected])

#Scope: Basics and BeyondBasic use: CS 1Beyond basic use: CS2#Download from www.eclipse.org

#Extract All

#Select Destination Folder

#Create some kind of Shortcut for Eclipse.exe

#Run Eclipse.exe

#7Specify Projects Directory

#8Remove Welcome Tab if it Appears

#9Add a New Java Project

#10Enter Project Name

#11Switch to Java Perspective (May get this message)

#12Empty Project Created

#Add a Package to Selected Project

Select project and File Package#14Enter Package Name

#15Empty Package in Non Empty Project

#Add a Class

Select project and File Class#Name the Class

#18Empty Class in Non Empty Package

#19Edit 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:#20Save (and Compile) the File

FileSave or CTRL+S#21

Workspace, Project, Source Package FolderSource PackageProjectWorkspaceClass Source#22Workspace, Project, Binary Package Folder

Binary PackageProjectWorkspaceClass Object (Binary) Code#23Execute the Main Method on Selected Class

Right MenuDebug As Java ApplicationCan also select Run but Debug is more defensive#24View Output in Console Window

#25

Provide Input in Console Window#26The Output after Enter

#27Supply User Argument:

Right MenuDebug As Debug Configuration#28Select Main Class in Configuration

#29

Specify and Apply Argument in Argument Tab and Press DebugArgument must be in quotes. Args[0] = Ca VaWithout quotes Java will make each word a separate argument (args[0] = Ca, args[1] = Va

#30Execute with Supplied Arg

#31Arg Printed, Program, Still Running, Waiting for Input

PressButton available in both Debug and Java Perspective, only of them is active#32

Terminated ProgramInactive button#33Debug Last Main Launched: F11No need to select a main class#

Closing a Window perhaps accidentally Hide Console#35Vanished Console

#36WindowReset Perspective

#37

WindowShow ViewCan selectively remove and add sub-windows/views#38TargetBasic useBeyond basic use#Create A Project from Existing CodeUnzip the zipped directoryZipped DirectoryJavaToHTMLSource Code of Class Examples

Click on Zipper Directory Link in SlideShow ModeMake a Java project out of it by following the steps described#Create a Project out of Existing Code: FileNewJava Project

#41Uncheck Default Location Box

Uncheck#42Enter Location and Name

#New Project Created

But it will have errors because of missing ObjectEditor library#Library Location on the WebObjectEditorVersion 3 (used in comp110)oeall3ObjectEditorVersion 19 (used last year)oeall19ObjectEditorVersion 20oeall20DownloadsClick on the latest version to download the jar (same as zip) and do not unzip/unjar it#Download Library to Local Computer

Do not unzip/unjar it#46Select Project, and ProjectProperties

Must do this for each project!#Select Build Path, Add External Jar

#48Select Saved Jar

#49Press Done to Commit

#50Change the Java Version (if Necessary): WindowPreferences

#JavaCompiler Preferences

#Rebuild or Recompile All Classes

#Executing Code Gives Java, Javac Incompatibility Error

#Change the Java Version: WindowPreferences

#Press Search Browse Button

#Press Search Browse Button to Installed JDK (See Appendix on Installation)

#Jre added to Eclipse, Select it and Can Execute Without Errors

#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: PasteSelect package in destination project and package and press CTRL-V (or FilePaste right menu item)

#Copying Classes from One Package to Another: New Class in new Package and ProjectRepackaged type added (and its imports are changed to other copied types if multiple types are copied and pasted together)

Package name changed#Jumping to Identifier Definition and Navigation StackF3 when cursor is a start of an identifier

Makes Eclipse take you to the definition of the identifier in an edit window

Cursor positionALT + 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 pointsALT + Forward Arrow goes forwards in the navigation stack a la browser forward button#Find the Uses

CTRL-SHIFT-G when cursor is a start of an identifierCursor position

Makes Eclipse show the methods that reference the identifier in the search tabDouble clicking a method reference

Makes Eclipse show the method and highlight all references of the identifier#Multi File Text Search for Println

#Search Results

Text search, shows uncommented println() alsoUse CTR+SHIFT+G (shown earlier) to find active uses of the method#MenuRefactorRename Identifier: ALT + Shift + R

Select type, right menuRefactorRenameAll references will be updated!#66Complete Identifier: Ctrl + Space after Prefixpublic static final long NUMBER_OF_LARGE_FACTORIAL_COMPUTATIONS = 1000000;

Give file name#67Understand and Correct Errors

Hover to understand

Click for correction proposal#68Correct 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 importedIf class is in more than one package, Eclipse gives a choice All unused imports are also removedCan select multiple types or a project to refresh all imports in the selected types/project #69Set a Break Point or Tel Eclipse to Stop When it Reached some LineDouble click in the leftmost side bar of edit window to indicate where you want program to stop and a dot will appear to show the breakpointDouble clicking again will remove dot and break pointCan also use right menu in side bar to enable and disable break point

#70Debug Program and Enter Input

#71May Get This Message Before Break Point Hit

#72Debug Perspective and Stopping at Breakpoint

Debug PerspectiveNext statement to be executed#73RunStep Over to next statement (F6)

#74

Stopped at Next StatementLocal variable#75

Call stackCalled method parametersRunStep into SetNumber (F5)#76

RunStep Return or F7Call stack#77

Step over and Then Strep Into getFactorialElided (Collapsed) Instance Vars#78

Examine VariablesExpanded Instance Vars#79

Step Into recursingFactorial#

Step Over if#

Step Into Recursive Call#

Examine Parent Call#

Step Over if#

Step Into yet Another Recursive Call#

RunResume to Next Break Point or User Input (no more single stepping)#

Enter Negative Number to Terminate#

Stopping again at BreakPoint#

Terminated in Debug Perspective#

Return to Java Perspective#Junit: New Class without Main

#Junit: Install JUnit

#Junit added and imported

#Run Junit

#Junit Result

#Returning to Java Perspective

#96#Finding the Definition

Cursor positionCTRL + SHIFT + G before a identifier#Finding the Definition

Cursor positionF3 before a use#Examining Main Parameters

Main Parameters#100New Output and Local Variable

Index gets initializedprintln() executed#101Step Over

#102Step Into Next Line (Same as Step Over)

#103

Terminating Running ProgramPress

#104

Call stackCalled method parametersStep Into SetNumber (RunStep Into or F5)#105

Step Return Step Return or F7Call stack#106

Step over and Then Strep Into getFactorialElided (Collapsed) Instance Vars#107

Examining VariablesExpanded Instance Vars#108Step Into recursingFactorial

#Step Over if

#Step Into Recursive Call

#Examining Parent Call

#Step Over

#Step Into yet Another Recursive Call

#Resume to Next Break Point or User Input (no more single stepping)

#Enter Negative Number to Terminate

#Stopping again at BreakPoint

#Terminated

#Returning to Java Perspective

#Two Other useful but Complicated Refactor OptionsChange method signatureWill try to update references to match the signature, which can be erroneousMaybe better to get all references and update them individually for both purposesExtract interface of class CWill create interface of selected public methods and will make the interface the type of all variables declared to be of class typeAdds potentially unwanted comments to method headers and sometimes updates to references have not worked in the past for me#