252-0027 Einführung in die Programmierung Ec Eclipse Overview Luca Della Toffola and Thomas R. Gross Department Informa:k ETH Zürich
To Today Eclipse overview Simple but effec.ve features you may benefit from while developing a program Eclipse debugger Catch your bugs using step-by-step explora.on of your program’s execu.on Debugging I/O + GUI Usage of the debugger with “complex” programs that you may develop for this course Ques:ons & answer(s) You ask I (try to) answer 1
Dem emo 2
Se Select ct w work orkspace ce 3
Ma Main w window 4
Ma Main w window Code editor 5
Ma Main w window Program’s I/O console 6
Ma Main w window Types and methods view 7
Ma Main w window Files view 8
Ec Eclipse light/dark 9
Ec Eclipse light/dark 10
Or Organize “Run Confi figu gura0ons” s” 11
Or Organize “Run Confi figu gura0ons” s” 12
Or Organize “Run Confi figu gura0ons” s” Set your program’s arguments Select tab and check next slide 13
Or Organize “Run Confi figu gura0ons” s” Write here the program’s arguments They will be set as the content of the method main parameter String[] args 14
Dem emo (do done) ne) 15
Eclipse debugger Catch your bugs using step-by-step explora7on of your program’s execu7on 16
Wha What is s a de debug bugger? A debugger is a program that allows a developer to inspect another program’s execu8on 17
Whe Where is s my y de debug bugger? 18
Wh Why y I ne need d a de debug bugger? 1 public class Main { 2 3 public static int maxOf(int[] values) { 4 int res = Integer.MAX_VALUE; 5 for ( int i = 0; i < values.length-1; i++) { 6 res = values[i] > res ? values[i] : res; 7 } 8 return res; 9 } 10 11 public static void main(String[] args) { 12 int[] inputs = readConsole(); 13 System.out.println(maxOf(inputs)); 14 } 15 < 1 16 } < 4 < 10 < 3 > 2147483647 19
Wh Why y I ne need d a de debug bugger? 1 public class Main { 2 3 public static int maxOf(int[] values) { 4 int res = Integer.MIN_VALUE; 5 for ( int i = 0; i < values.length-1; i++) { 6 res = values[i] > res ? values[i] : res; 7 } 8 return res; 9 } 10 11 public static void main(String[] args) { 12 int[] inputs = readConsole(); 13 System.out.println(maxOf(inputs)); 14 } 15 < 3 16 } < 1 < 4 < 10 > 4 20
Wh Why y I ne need d a de debug bugger? 1 public class Main { 2 3 public static int maxOf(int[] values) { 4 int res = Integer.MIN_VALUE; 5 for ( int i = 0; i < values.length; i++) { 6 res = values[i] > res ? values[i] : res; 7 } 8 return res; 9 } 10 11 public static void main(String[] args) { 12 int[] inputs = readConsole(); 13 System.out.println(maxOf(inputs)); 14 } 15 < 3 16 } < 1 < 4 < 10 > 10 21
What I can Wha n do do wi with h a de debug bugger? Pause/resume execu:on of the program at each line 1 public class Main { [ Breakpoint] 2 3 public static int maxOf(int[] values) { 4 int res = Integer.MAX_VALUE; 5 for ( int i = 0; i < values.length-1; i++) { 6 res = values[i] > res ? values[i] : res; 7 } 8 return res; 9 } 10 11 public static void main(String[] args) { 12 int[] inputs = readConsole(); 13 System.out.println(maxOf(inputs)); 14 } maxOf 15 16 } values [1, 3, 4, 10] Inspect content of variables res 2147483647 and object fields values main [] args [1, 3, 4, 10] inputs 22
Dem emo 23
Debug ebugger er vi view Method calls 24
Debug ebugger er vi view Code editor (as before) 25
Debug ebugger er vi view Variables inspector 26
Debug ebugger er vi view Program’s I/O console (as before) 27
Pa Pause/resume the debugger 28
St Step-in into/Step ep-over er/Step ep-re return Not needed for now! 29
Br Breakpoi oint types Field watchers Execution stops when field is accessed/modified Method entry/exit Execu1on stops at method boundaries Default Execu1on stops when breakpoint is reached 30
Br Breakpoi oint prop oper, r,es Write here stopping condition (as a simple program) 31
Br Breakpoi oint prop oper, r,es 32
Mod Modify l loc ocal v vari riables ( (pri rimi mi3ve) Change primi/ve value Double-click cell under Value column and write new value 33
Mod Modify l loc ocal v vari riables ( (pri rimi mi3ve) Change primi,ve value When value is modified line turns yellow 34
Mod Modify l loc ocal v vari riables ( (ob objects) Write here expression (as of simple program) 35
Re Refactor: rename variable Rename all usages of a variable at once Right-click on variable use 36
Re Refactor: extract method Extract expression to method Select expression in code + right-click 37
Re Refactor: generate constructor Generate constructor from fields Right-click on field 38
Re Refactor: generate constructor Generate constructor from fields Select fields and then Generate 39
Dem emo (do done) ne) 40
Debug ebuggi ging ng I/ I/O & & GUI UI Problem 3 : search the maximum value in linked-list Problem 2 : y-axis direc/on Problem 1 : read data from complex file 41
Debug ebuggi ging ng I/ I/O & & GUI UI file.csv … 2004-12-31 01:00:00 13478.0 2004-12-31 02:00:00 12865.0 2004-12-31 03:00:00 12577.0 2004-12-31 04:00:00 12517.0 2004-12-31 05:00:00 12670.0 2004-12-31 06:00:00 13038.0 2004-12-31 07:00:00 13692.0 2004-12-31 08:00:00 14297.0 2004-12-31 09:00:00 14719.0 2004-12-31 10:00:00 14941.0 2004-12-31 11:00:00 15184.0 2004-12-31 14:00:00 14522.0 … 42
Dem emo 43
Vi Visualize a program’s execu2on h#ps://cscircles.cemc.uwaterloo.ca/java_visualize/ 44
Us Useful l code e ed edit itor colo lor schem eme https://ethanschoonover.com/solarized/ 45
Dem emo (do done) ne) 46
Recommend
More recommend