Ec Eclipse Overview Luca Della Toffola and Thomas R. Gross - - PowerPoint PPT Presentation

ec eclipse overview
SMART_READER_LITE
LIVE PREVIEW

Ec Eclipse Overview Luca Della Toffola and Thomas R. Gross - - PowerPoint PPT Presentation

252-0027 Einfhrung in die Programmierung Ec Eclipse Overview Luca Della Toffola and Thomas R. Gross Department Informa:k ETH Zrich To Today Eclipse overview Simple but effec.ve features you may benefit from while developing a program


slide-1
SLIDE 1

Ec Eclipse Overview

Luca Della Toffola and Thomas R. Gross

252-0027 Einführung in die Programmierung Department Informa:k ETH Zürich

slide-2
SLIDE 2

To Today

1

Simple but effec.ve features you may benefit from while developing a program

Eclipse overview

Catch your bugs using step-by-step explora.on of your program’s execu.on

Eclipse debugger

Usage of the debugger with “complex” programs that you may develop for this course

Debugging I/O + GUI

You ask I (try to) answer

Ques:ons & answer(s)

slide-3
SLIDE 3

Dem emo

2

slide-4
SLIDE 4

Se Select ct w work

  • rkspace

ce

3

slide-5
SLIDE 5

Ma Main w window

4

slide-6
SLIDE 6

Ma Main w window

5

Code editor

slide-7
SLIDE 7

Ma Main w window

6

Program’s I/O console

slide-8
SLIDE 8

Ma Main w window

7

Types and methods view

slide-9
SLIDE 9

Ma Main w window

8

Files view

slide-10
SLIDE 10

Ec Eclipse light/dark

9

slide-11
SLIDE 11

Ec Eclipse light/dark

10

slide-12
SLIDE 12

Or Organize “Run Confi figu gura0ons” s”

11

slide-13
SLIDE 13

Or Organize “Run Confi figu gura0ons” s”

12

slide-14
SLIDE 14

Or Organize “Run Confi figu gura0ons” s”

13

Set your program’s arguments

Select tab and check next slide

slide-15
SLIDE 15

Or Organize “Run Confi figu gura0ons” s”

14

Write here the program’s arguments

They will be set as the content of the method main parameter String[] args

slide-16
SLIDE 16

Dem emo (do done) ne)

15

slide-17
SLIDE 17

16

Catch your bugs using step-by-step explora7on of your program’s execu7on

Eclipse debugger

slide-18
SLIDE 18

Wha What is s a de debug bugger?

A debugger is a program that allows a developer to inspect another program’s execu8on

17

slide-19
SLIDE 19

Whe Where is s my y de debug bugger?

18

slide-20
SLIDE 20

Wh Why y I ne need d a de debug bugger?

public class Main { public static int maxOf(int[] values) { int res = Integer.MAX_VALUE; for (int i = 0; i < values.length-1; i++) { res = values[i] > res ? values[i] : res; } return res; } public static void main(String[] args) { int[] inputs = readConsole(); System.out.println(maxOf(inputs)); } }

19

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

< 1 < 4 < 10 < 3 > 2147483647

slide-21
SLIDE 21

Wh Why y I ne need d a de debug bugger?

public class Main { public static int maxOf(int[] values) { int res = Integer.MIN_VALUE; for (int i = 0; i < values.length-1; i++) { res = values[i] > res ? values[i] : res; } return res; } public static void main(String[] args) { int[] inputs = readConsole(); System.out.println(maxOf(inputs)); } }

20

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

< 3 < 1 < 4 < 10 > 4

slide-22
SLIDE 22

Wh Why y I ne need d a de debug bugger?

public class Main { public static int maxOf(int[] values) { int res = Integer.MIN_VALUE; for (int i = 0; i < values.length; i++) { res = values[i] > res ? values[i] : res; } return res; } public static void main(String[] args) { int[] inputs = readConsole(); System.out.println(maxOf(inputs)); } }

21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

< 3 < 1 < 4 < 10 > 10

slide-23
SLIDE 23

Wha What I can n do do wi with h a de debug bugger?

public class Main { public static int maxOf(int[] values) { int res = Integer.MAX_VALUE; for (int i = 0; i < values.length-1; i++) { res = values[i] > res ? values[i] : res; } return res; } public static void main(String[] args) { int[] inputs = readConsole(); System.out.println(maxOf(inputs)); } }

22

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

maxOf

values res [1, 3, 4, 10] 2147483647

Inspect content of variables and object fields values Pause/resume execu:on

  • f the program at each line

[ Breakpoint]

main

args inputs [] [1, 3, 4, 10]

slide-24
SLIDE 24

Dem emo

23

slide-25
SLIDE 25

Debug ebugger er vi view

24

Method calls

slide-26
SLIDE 26

Debug ebugger er vi view

25

Code editor (as before)

slide-27
SLIDE 27

Debug ebugger er vi view

26

Variables inspector

slide-28
SLIDE 28

Debug ebugger er vi view

27

Program’s I/O console (as before)

slide-29
SLIDE 29

Pa Pause/resume the debugger

28

slide-30
SLIDE 30

St Step-in into/Step ep-over er/Step ep-re return

29

Not needed for now!

slide-31
SLIDE 31

Br Breakpoi

  • int types

30

Execution stops when field is accessed/modified

Field watchers

Execu1on stops at method boundaries

Method entry/exit

Execu1on stops when breakpoint is reached

Default

slide-32
SLIDE 32

Br Breakpoi

  • int prop
  • per,

r,es

31

Write here stopping condition (as a simple program)

slide-33
SLIDE 33

Br Breakpoi

  • int prop
  • per,

r,es

32

slide-34
SLIDE 34

Mod Modify l loc

  • cal v

vari riables ( (pri rimi mi3ve)

33

Double-click cell under Value column and write new value

Change primi/ve value

slide-35
SLIDE 35

Mod Modify l loc

  • cal v

vari riables ( (pri rimi mi3ve)

34

When value is modified line turns yellow

Change primi,ve value

slide-36
SLIDE 36

Mod Modify l loc

  • cal v

vari riables ( (ob

  • bjects)

35

Write here expression (as of simple program)

slide-37
SLIDE 37

Re Refactor: rename variable

36

Rename all usages of a variable at once

Right-click on variable use

slide-38
SLIDE 38

Re Refactor: extract method

37

Extract expression to method

Select expression in code + right-click

slide-39
SLIDE 39

Re Refactor: generate constructor

38

Generate constructor from fields

Right-click on field

slide-40
SLIDE 40

Re Refactor: generate constructor

39

Generate constructor from fields

Select fields and then Generate

slide-41
SLIDE 41

Dem emo (do done) ne)

40

slide-42
SLIDE 42

Debug ebuggi ging ng I/ I/O & & GUI UI

41

Problem 2: y-axis direc/on Problem 1: read data from complex file Problem 3: search the maximum value in linked-list

slide-43
SLIDE 43

Debug ebuggi ging ng I/ I/O & & GUI UI

42

… 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 …

file.csv

slide-44
SLIDE 44

Dem emo

43

slide-45
SLIDE 45

Vi Visualize a program’s execu2on

44

h#ps://cscircles.cemc.uwaterloo.ca/java_visualize/

slide-46
SLIDE 46

Us Useful l code e ed edit itor colo lor schem eme

45

https://ethanschoonover.com/solarized/

slide-47
SLIDE 47

Dem emo (do done) ne)

46