com ompsci psci 201 201 arrays s arraylist ylist apis is
play

Com ompsci psci 201 201 Arrays, s, ArrayList yList, , APIs Is - PowerPoint PPT Presentation

Com ompsci psci 201 201 Arrays, s, ArrayList yList, , APIs Is Susan Rodger January 22, 2020 1/22/2020 Compsci 201, Spring 2020 1 Today is the last day of drop/add It is almost too late You cannot t switch your r section tion


  1. Com ompsci psci 201 201 Arrays, s, ArrayList yList, , APIs Is Susan Rodger January 22, 2020 1/22/2020 Compsci 201, Spring 2020 1

  2. Today is the last day of drop/add It is almost too late… • You cannot t switch your r section tion withou out t a perm rmission ission numbe mber. . • DO DO NOT drop rop your section tion until til you can get et a perm rm numbe mber r for the e ot other er section tion • Go Go to to https ps://w //www.cs.d s.duke.ed .edu/under /undergra rad/ d/registr egistrati tion on • Scroll oll down n belo low offic ice e hour ours s til til you u see Permis missi sion on numbe mber for Sprin ing 2020 course rses • Then en fill out that at form • You must t use e permi missi sion on numbe mber to toda day! y! • We will ll not ot be hand nding ng them em out t afte ter r 5pm 1/22/2020 Compsci 201, Spring 2020 2

  3. D is for … • Debugging • A key skill in making your programs correc ect , your program will run without this skill • Digital • All about the 1s and 0s 1/22/2020 Compsci 201, Spring 2020 3

  4. Plan for Today • What at work is here, what at work is coming ing • P0, P1, APTs • Unders rstanding tanding arra rays s and ArrayList List: : Trad adeoff eoffs • APTS always use arrays, convert to ArrayList? • Reaso soning ning empiric irically and analytic ticall ally • Working well enough and working at scale 1/22/2020 Compsci 201, Spring 2020 4

  5. Announcements • Assig ignment nment P0 due due las ast t week • No late penalty since first assignment til Jan 24 • APT-1 1 now du due e Thur urs, s, January nuary 23 23 • Can still turn in Friday til 11:59pm • Discussion cussion 3 o on January nuary 27 • Prediscussion, do before, out by Friday • APT-2 out to today, , du due January ry 28 (shor ort t 1 due due) • Assignme ignment t P1 o out t Frida iday, , du due e Thursd rsday, , Jan 30 • Readin ding on cal alen endar ar • Slowing down ….. • try to read by date posted, ok if you need a few more days 1/22/2020 Compsci 201, Spring 2020 5

  6. Visualizations Help Understanding? • Javatut utor to to visua uali lize e code: : http tp:// ://pytho thont ntut utor or.com/j com/java. a.html html • Using the java.awt.Color class • Both String and Color are immuta utable ble • Once created, cannot ever change 1/22/2020 Compsci 201, Spring 2020 6

  7. Arrays and APIs • Acces cessing ing a list st of sand ndwic ich h ingred edients ients https:/ ://w /www2. 2.cs. s.duk uke.e .edu du/cse /csed/ d/newapt/s t/sand ndwich ichbar.h .html tml • Ingredients specified as string "lettuce tomato" • String split method String[] d = "lettuce tomato".split(" ") 1/22/2020 Compsci 201, Spring 2020 7

  8. APTs: parsing/processing data • String <-> String[]: parameter and return types String s = "apple pear lemon orange"; String [] ar = s.split (" “); // ar is ["apple", "pear", "lemon", "orange"] • Bridge ge fro rom arra ray to to string? ring? String[] a = {"one", "two", "three"} String b = String.join(":",a); // b is "one:two:three" 1/22/2020 Compsci 201, Spring 2020 9

  9. Helper methods Creating your own API • Sand ndwic ichBar hBar APT writeup up https://www2.cs.duke.edu/csed/newapt/sandwichbar.html • Clue/hint that indexing loop appropriate • Helper er functi ction : array of strings contains all strings. Be creative in wanting an API for that 1/22/2020 Compsci 201, Spring 2020 11

  10. WOTO SandwichBar • How to to te test st locally? ally? • Write main method. Create new object … • Faster to debug locally, even use debugger? 1/22/2020 Compsci 201, Spring 2020 12

  11. Helper methods Creating your own API • Sand ndwic ichBar hBar APT writeup up • Helper er funct ctio ion : array of strings contains all strings. Be creative in wanting an API for that 1/22/2020 Compsci 201, Spring 2020 13

  12. Scoring WOTOs going forward • Each h regular gular WOTO O fo form is worth h 2 pts • If 2 WOTOs Os in a lect ctur ure, , each ch worth th 2 pt pts • Some e WOTO O fo forms ms correc ectne tness s will count nt and each ch pro roblem lem is worth th pts s (likel ely 1 pt pt each) ch) • We are dro ropping ping all WOTOs Os done befor efore e to today • SUBMIT MIT ALL WOTO O FORM RMS – they count! nt! • Work Together her with h ot others ers 1/22/2020 Compsci 201, Spring 2020 16

  13. WOTO (4 minutes) http:/ ://bit.l bit.ly/ y/201 201sp sprin ring20 g20-01 0122 22-1 1/22/2020 Compsci 201, Spring 2020 17

  14. Nancy Leveson: Software Safety • (@MIT) Mathematical and engineering aspects, invented the discipline • Air traffic control • Microsoft word “T here will always be another software bug; never trust human life solely on software ” huffington post? • Therac 25: Radiation machine • http://en.wikipedia.org/wiki/Therac- 25 • Paper on this: http://bit.ly/5qOjoH • Software and steam engines

  15. Source Code, Byte Code • High level el languages es compil mpiled d to to low level el lan anguages es • In C/C++ low-level specific ic to to platf tfor orm • In Java byte code is low-level • Exec ecute e by machin ine: : real al or virtual al • JVMs must t be ported ed to to plat atform orm • Andr droid oid doesn sn't use e JVM • Dalvik and now ARM • Be grat ateful!! l!!!! !!! • High level source code 1/22/2020 Compsci 201, Spring 2020 19

  16. From Hello.java to Hello.class public class Hello { public static void main(String[] args){ System.out.println("hello world"); } } Code: 0: aload_0 1: invokespecial #1 4: return Code: 0: getstatic #2 3: ldc #3 5: invokevirtual #4 8: return 1/22/2020 Compsci 201, Spring 2020 20

  17. Project P1 out soon • See e course rse websit ite fo for det etails ails, discus cussio ion n D3 • Not quite this , but … https://www.youtube.com/watch?v=DoLe1c-eokI • Read as assignment signment befo efore e star arting ting to to code • Think before fingers on keys • Use Piazza za and Helper er Hours 1/22/2020 Compsci 201, Spring 2020 21

  18. Projects in 201: Review • Start with th GitLab Lab pro rojec ect, t, fork k reposit ository ory • Starter code and cloud-based storage for projects • Clone repo to your machine: you need Git for this • You use Duke e Compsc sci GitLab ab websit site • You manage your code/projects with GitLab • Make e chan anges es, , comple mplete e pro roject ject • Push changes frequently using Git … hourly/daily 1/22/2020 Compsci 201, Spring 2020 22

  19. What is Git? • Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. https://git-scm.com/ • In teams, huge win. Individually, huge win • Git is complicated when it doesn’t work, lots of commands • Git relies on SSH to be secure 1/22/2020 Compsci 201, Spring 2020 23

  20. Assignments P0 and P1 • Simple le Java a class ass with driver er pro rogra rams ms • How is a program run? What is main? • Testing methods and testing classes • Examp mple le of 201 work-flow • GitLab for starter code and your code • Using SSH and GitLab together • Submitting via Gradescope, Analysis 1/22/2020 Compsci 201, Spring 2020 24

  21. What is a static method? • Objects ects are inst stance ances s of a class ss • Thus objects have instance variables • Typically private, accessed in methods • Static tic meth ethod d belongs ngs to to class ss, not ot obje bject ct • No instance variables • Accesses static variables and methods • More on this later, for now? … 1/22/2020 Compsci 201, Spring 2020 25

  22. Static Methods • The class ss Math ath has as many ny (java.lan .lang) • sqrt, cos, abs, … • The class ss Arrays s has as many ny (java. a.uti util) • sort, fill, toString, asList , … • Invoke as as Math.s ath.sqrt(2 (25.0 5.0) ) or String.j ring.join oin (…) • Math is a class. Convention for name? • There aren't different Math objects, none! • No state needed, all code in methods 1/22/2020 Compsci 201, Spring 2020 26

  23. WOTO: Correctness Counts http://b ://bit.l it.ly/201spr y/201spring20 ing20-0122 0122-2 1/22/2020 Compsci 201, Spring 2020 27

Recommend


More recommend