Slide 1

Slide 1 text

@jeanneboyarsky Jeanne Boyarsky Wednesday, March 6, 2019 Dev Nexus Becoming the first Java 11 Certified Developer

Slide 2

Slide 2 text

@jeanneboyarsky At end of session 1.  https://speakerdeck.com/boyarsky 2.  https://github.com/boyarsky/2019-dev-nexus- java-11-cert 2

Slide 3

Slide 3 text

@jeanneboyarsky About Me 17 years as Java Developer 3 Book random giveway at end!!!

Slide 4

Slide 4 text

@jeanneboyarsky Disclaimer 1.  A bit of the material is from our first books. 2.  Some of the material in this presentation may appear in our upcoming certification books. 3.  Oracle can announce anything (I don’t work for Oracle.) 4

Slide 5

Slide 5 text

@jeanneboyarsky Introductions 5

Slide 6

Slide 6 text

@jeanneboyarsky Agenda 6 Module Topics 1 Intro, _, private methods in interfaces 2 effectively final try with resources, var 3 Collections and Strings 4 Single file execution, deprecation and JShell 5 Streams 6 Jigsaw, Multi release jar files 7 Study tips, harder questions/review

Slide 7

Slide 7 text

@jeanneboyarsky Module flow •  Review lab from previous module •  Lecture •  Practice questions as a group/discussion •  Hands on exercises •  10 minute break This means if a colleague needs to call you, the last 15-20 minutes of each hour is best. 7

Slide 8

Slide 8 text

@jeanneboyarsky Labs •  I will sprinkle in some concepts form earlier version of Java into the labs. (ex: reading from a file). •  If you are not familiar with these, it is fine to Google or ask me. 8

Slide 9

Slide 9 text

@jeanneboyarsky Focus •  Focus is Java 11 changes •  Will still throw in Java 8 and earlier content and tricks •  Pretend any Word smart quotes are normal double quotes. 9

Slide 10

Slide 10 text

@jeanneboyarsky Module 1 •  Intro •  _ •  private methods in interfaces 10

Slide 11

Slide 11 text

@jeanneboyarsky Exam History 11 + upgrade

Slide 12

Slide 12 text

@jeanneboyarsky Exam History 12

Slide 13

Slide 13 text

@jeanneboyarsky Cert Expectations •  Why helps your job •  Why helps your knowledge •  How relates to real world coding 13

Slide 14

Slide 14 text

@jeanneboyarsky Beta Cert Expectations •  More questions •  Sometimes no right answer •  Can leave comments •  Few study materials 14

Slide 15

Slide 15 text

@jeanneboyarsky Which version should I use? 15 Java Oracle JDK Open JDK New version Every 3 years Every 6 months Cost Paid Free Upgrade Options •  Next version •  Security patch •  Open JDK •  Interim security patch •  Next version

Slide 16

Slide 16 text

@jeanneboyarsky Expectations for Java 11 •  Two exams •  LTS versions of Java •  Cert site reorg – beta page gone 16

Slide 17

Slide 17 text

@jeanneboyarsky Dates from last time Java 8 Java 11 Release March 18, 2014 Sept 25, 2018 Objectives/beta announced August 31, 2014 March 2019? Beta opens April 28, 2015 ??? Retirement of previous Java exams Java 6 – May 31, 2018 Java 7 – Dec 30, 2018 Java 8 - ??? 17

Slide 18

Slide 18 text

@jeanneboyarsky Required Software for Today •  Java 11 – if don’t have: https://jdk.java.net/11/ •  Text editor of your choice •  No IDE! •  No syntax highlighting! 18

Slide 19

Slide 19 text

@jeanneboyarsky Optional: Aliases alias javac11=/Library/Java/JavaVirtualMachines/ jdk-11.0.2.jdk/Contents/Home/bin/javac alias java11=/Library/Java/JavaVirtualMachines/ jdk-11.0.2.jdk/Contents/Home/bin/java alias jshell11=/Library/Java/ JavaVirtualMachines/jdk-11.0.2.jdk/Contents/ Home/bin/jshell 19

Slide 20

Slide 20 text

@jeanneboyarsky Underscores •  Single _ no longer a valid identifier •  Double underscore valid •  Underscore and letters valid •  Why? Positioning for future 20

Slide 21

Slide 21 text

@jeanneboyarsky Private methods •  Private and private static methods allowed in interfaces •  Why? Can write other code so maintainability 21

Slide 22

Slide 22 text

@jeanneboyarsky Allowed in Interfaces Type Scope Constants Public Abstract Methods Public Default Methods Public Static Methods Public or private Instance methods Private 22

Slide 23

Slide 23 text

@jeanneboyarsky Module 1 – Question 1 Which of the following compile? A.  String abc = null; B.  String 123 = null; C.  String () = null; D.  String __ = null; E.  String _ = null; 23

Slide 24

Slide 24 text

@jeanneboyarsky Module 1 – Question 2 Which can fill in the blank? interface TheInterface { ____ int method() { return 1; } } A.  public B.  protected C.  no modifier 24 D.  private E.  None of the above

Slide 25

Slide 25 text

@jeanneboyarsky Module 1 – Question 3 Which can fill in the blank? interface TheInterface { ____ static void method() {} } A.  public B.  protected C.  no modifier 25 D.  private E.  None of the above

Slide 26

Slide 26 text

@jeanneboyarsky Module 1 – Question 4 Which of the following compile? A.  String _a = null; B.  String _1 = null; C.  String $ = null; D.  String _ = null; E.  String __ = 1; 26

Slide 27

Slide 27 text

@jeanneboyarsky Module 1 – Question 5 Which can fill in the blank? interface TheInterface { ____ default void method() {} } A.  public B.  protected C.  no modifier 27 D.  private E.  None of the above

Slide 28

Slide 28 text

@jeanneboyarsky Module 1 – Question 6 Which of the following compile? A.  double d = 1_0; B.  double d = 1.0; C.  double d_d = 1_0; D.  double _d_ = _1_; E.  double _ = 1_; 28

Slide 29

Slide 29 text

@jeanneboyarsky Module 1 – Question 7 How many identifiers could have independently been changed to _ in Java 10? A.  0 B.  1-2 C.  3-4 29 D.  5 or more E.  None – code does not compile

Slide 30

Slide 30 text

@jeanneboyarsky Lab & Break 30 See handout

Slide 31

Slide 31 text

@jeanneboyarsky Module 2 •  Review lab •  effectively final try with resources •  var 31

Slide 32

Slide 32 text

@jeanneboyarsky Review lab 1.  Why didn’t calling getRandom() work? 2.  How did you fix it? 3.  What version of Java disallowed _? 4.  When would you use private interface methods in real life? 32

Slide 33

Slide 33 text

@jeanneboyarsky Effectively Final Definition If typed final before param/local variable and it would still compile 33

Slide 34

Slide 34 text

@jeanneboyarsky Which are effectively final? public int numChairs = 4; public int numLegs = numChairs * 4; numChairs++; System.out.println(numChairs); 34

Slide 35

Slide 35 text

@jeanneboyarsky Try with Resources - Before Path path = Paths.get("file"); try(BufferedReader reader = Files.newBufferedReader(path)){ // read file } 35

Slide 36

Slide 36 text

@jeanneboyarsky Try with Resources - After Path path = Paths.get("file"); BufferedReader reader = Files.newBufferedReader(path); try(reader){ // read file } 36

Slide 37

Slide 37 text

@jeanneboyarsky What’s wrong here? Connection con = DriverManager.getConnection(url); PreparedStatement ps = con.prepareStatement(sql); ps.setInt(1, id); ResultSet rs = ps.executeQuery(); try (con; ps; rs) { while (rs.next()) { // process result set } } Resource leak!

Slide 38

Slide 38 text

@jeanneboyarsky String name = "Jeanne”; var name = "Jeanne"; List list = List.of(1, 2, 3); var list = List.of(1, 2, 3); •  Syntactical sugar/less boilerplate •  Not immutable (no val) 38

Slide 39

Slide 39 text

@jeanneboyarsky var name = "Jeanne"; String name2 = name; Compiled code same with var 39

Slide 40

Slide 40 text

@jeanneboyarsky List headers = thead.findElements(By.tagName("th")); VolunteerDashboardRow headerRow = new VolunteerDashboardRow(headers); vs var headers = thead.findElements(By.tagName("th")); var headerRow = new VolunteerDashboardRow(headers); 40

Slide 41

Slide 41 text

@jeanneboyarsky var csvPath = createAndGetFile(CSV_DATA); try (var csvWriter = Files.newBufferedWriter(csvPath); var csvPrinter = new CSVPrinter(csvWriter, CSVFormat.DEFAULT)); { } 41

Slide 42

Slide 42 text

@jeanneboyarsky Map productMap1 = new HashMap(); Map productMap2 = new HashMap<>(); var productMap3 = new HashMap(); 42

Slide 43

Slide 43 text

@jeanneboyarsky Where can we use? var name = "Jeanne"; var other = name + 2; var list = List.of(1, 2, 3); for (var num : list) {} 43

Slide 44

Slide 44 text

@jeanneboyarsky Where can’t we use? class Inner { var bad = "abc"; } var noGood; noGood = 4; Also instance variables, etc 44

Slide 45

Slide 45 text

@jeanneboyarsky Does this work? var var = "var"; 45

Slide 46

Slide 46 text

@jeanneboyarsky Pros Cons Less typing Loss of information Less redundancy Variable names matter more Can scan variable names Be careful! 46 http://openjdk.java.net/projects/amber/LVTIstyle.html

Slide 47

Slide 47 text

@jeanneboyarsky Lambdas Predicate pred1 = p -> true; Predicate pred2 = (String p) -> true; Predicate pred3 = (var p) -> true; 47

Slide 48

Slide 48 text

@jeanneboyarsky Annotations BiPredicate< Map, List> func = (@NotNull var map, var list) -> true; 48

Slide 49

Slide 49 text

@jeanneboyarsky All or nothing Good (var map, var list) -> true No good (var map, list) -> true (var map, List list) -> true 49

Slide 50

Slide 50 text

@jeanneboyarsky Module 2 – Question 1 Which are true if the resources are ResultSets? try (resource1; resource2) {} A.  Resource 1 is closed before resource 2 B.  Resource 2 is closed before resource 1 C.  Neither is closed since declared before try D.  The code does not compile 50

Slide 51

Slide 51 text

@jeanneboyarsky Module 2 – Question 2 What is the output? var a = 1; var b = a; int c = b; System.out.println(c); A.  a does not compile B.  b does not compile C.  c does not compile 51 D.  1 E.  None of the above

Slide 52

Slide 52 text

@jeanneboyarsky Module 2 – Question 3 Which are true if the resources are ResultSets? try (resource1, resource2) {} A.  Resource 1 is closed before resource 2 B.  Resource 2 is closed before resource 1 C.  Neither is closed since declared before try D.  The code does not compile 52

Slide 53

Slide 53 text

@jeanneboyarsky Module 2 – Question 4 What is the output? var a = 1; var b = a; double c = b; System.out.println(c); A.  a does not compile B.  b does not compile C.  c does not compile 53 D.  1.0 E.  None of the above

Slide 54

Slide 54 text

@jeanneboyarsky Module 2 – Question 5 Which is true at the end of the code block? A.  Reader is closed B.  Reader remains open C.  None; the code does not compile 54

Slide 55

Slide 55 text

@jeanneboyarsky Module 2 – Question 6 What is the output? var a = 1; var b = a; String c = b; System.out.println(c); A.  a does not compile B.  b does not compile C.  c does not compile 55 D.  1 E.  None of the above

Slide 56

Slide 56 text

@jeanneboyarsky Module 2 – Question 7 Which variable declarations compile? var a = null; var b = 1; var c; var var = 3; A.  a B.  b 56 C.  c D.  var

Slide 57

Slide 57 text

@jeanneboyarsky Module 2 – Question 8 Which variable declarations compile? var a; a = 1; static var b = 1; int x=1, var y=1; var VAR = 1; A.  a B.  b 57 C.  y D.  VAR

Slide 58

Slide 58 text

@jeanneboyarsky Module 2 – Question 9 Which allow using var? A.  Inner class instance variables B.  Lambda variables C.  Static variables D.  Try with resources 58

Slide 59

Slide 59 text

@jeanneboyarsky Lab & Break 59 See handout

Slide 60

Slide 60 text

@jeanneboyarsky Module 3 •  Review lab •  Collections •  Strings 60

Slide 61

Slide 61 text

@jeanneboyarsky Review lab 1.  How did it go? 2.  Anyone want to share their solutions? 3.  What did you think of the local variable type inference paper? 61

Slide 62

Slide 62 text

@jeanneboyarsky Creating a non-empty Set Set set = new HashSet<>( Arrays.asList("1","2", "3")); Set set = Stream.of("1", "2”, "3") .collect(Collectors.toSet()); Set set = Set.of("1", "2", "3");

Slide 63

Slide 63 text

@jeanneboyarsky For consistency Map map = Map.of("k", "v"); Up to 10 params, then varargs List list = List.of("1", "2", "3"); Up to 20 params, then varargs

Slide 64

Slide 64 text

@jeanneboyarsky Better Map Map map = Map.ofEntries( Map.entry(1, 10), Map.entry(2, 20) );

Slide 65

Slide 65 text

@jeanneboyarsky Lists •  Not equivalent! •  List.of(1, 2, 3) •  Arrays.asList(1, 2, 3) •  Only one is immutable •  Demo in JShell 65

Slide 66

Slide 66 text

@jeanneboyarsky Streams •  Terminal operators: •  toUnmodifiableList() •  toUnmodifiableSet() •  toUnmodifiableMap() 66

Slide 67

Slide 67 text

@jeanneboyarsky Whitespace •  trim() •  strip() •  stripLeading() •  stripTrailing() •  isBlank() 67 <-- Legacy – not Unicode aware

Slide 68

Slide 68 text

@jeanneboyarsky Repeating •  "123 ".repeat(3).length(); •  "".repeat(3).length(); 68

Slide 69

Slide 69 text

@jeanneboyarsky Streams "abc\n123" .lines() .count(); "abc".chars() .count(); 69

Slide 70

Slide 70 text

@jeanneboyarsky Module 3 – Question 1 What does the following output? Map map = Map.of(1, 2, 3, 4); System.out.println(map.get(2)); A.  1 B.  2 C.  null 70 D.  Code does not compile E.  Throws exception

Slide 71

Slide 71 text

@jeanneboyarsky Module 3 – Question 2 What does the following output? long count = "java\n".repeat(5).lines().count(); System.out.println(count); A.  4 B.  5 C.  6 71 D.  Code does not compile E.  Throws exception

Slide 72

Slide 72 text

@jeanneboyarsky Module 3 – Question 3 What does the following output? Map map = Map.of(1, 2, 3, 4); System.out.println(map.get(2)); A.  1 B.  2 C.  null 72 D.  Code does not compile E.  Throws exception

Slide 73

Slide 73 text

@jeanneboyarsky Module 3 – Question 4 What does the following output? long count = "\n".strip().repeat(5).lines().count(); System.out.println(count); A.  0 B.  1 C.  5 73 D.  Code does not compile E.  Throws exception

Slide 74

Slide 74 text

@jeanneboyarsky Module 3 – Question 5 What does the following output? Map map = Map.of(1, 2, 3); System.out.println(map.get(2)); A.  1 B.  2 C.  null 74 D.  Code does not compile E.  Throws exception

Slide 75

Slide 75 text

@jeanneboyarsky Module 3 – Question 6 Which can fill in the blank to print 0? System.out.println( "\t"._____().length()); A.  strip() B.  stripFirst() C.  stripLast() 75 D.  trim() E.  None of the above

Slide 76

Slide 76 text

@jeanneboyarsky Module 3 – Question 7 What does the following output? List list = List.of(1, 2, 3); list.remove(2); System.out.println(list); A.  [1, 2, 3] B.  [1, 3] C.  [1, 2] 76 D.  Code does not compile E.  Throws exception

Slide 77

Slide 77 text

@jeanneboyarsky Module 3 – Question 8 Which can fill in the blank to print 1? System.out.println( "a\t"._____().length()); A.  strip() B.  stripLeading() C.  stripTrailing() 77 D.  trim() E.  None of the above

Slide 78

Slide 78 text

@jeanneboyarsky Module 3 – Question 9 What does the following output? List list = Arrays.asList(1, 2, 3); list.remove(2); System.out.println(list); A.  [1, 2, 3] B.  [1, 3] C.  [1, 2] 78 D.  Code does not compile E.  Throws exception

Slide 79

Slide 79 text

@jeanneboyarsky Module 3 – Question 10 Which can fill in the blank to print 1? char whitespace = '\u001D'; String str = whitespace + "x"; System.out.println( str.________().length()); A.  stripLeading() B.  stripTrailing() 79 C.  strip() D.  None of the above

Slide 80

Slide 80 text

@jeanneboyarsky Module 3 – Question 11 What does the following output? List list = Arrays.asList(1, 2, 3); list.set(1, 0); System.out.println(list); A.  [1, 0, 3] B.  [1, 2, 3] C.  null 80 D.  Code does not compile E.  Throws exception

Slide 81

Slide 81 text

@jeanneboyarsky Module 3 – Question 12 Which can fill in the blank to print 1? char whitespace = '\t'; String str = whitespace + "x"; System.out.println( str.________().length()); A.  stripLeading() B.  stripTrailing() 81 C.  trim() D.  None of the above

Slide 82

Slide 82 text

@jeanneboyarsky Module 3 – Question 13 What does the following output? List list = List.of(1, 2, 3); list.set(1, 0); System.out.println(list); A.  [1, 0, 3] B.  [1, 2, 3] C.  null 82 D.  Code does not compile E.  Throws exception

Slide 83

Slide 83 text

@jeanneboyarsky Lab & Break 83 See handout

Slide 84

Slide 84 text

@jeanneboyarsky Module 4 •  Review lab •  Single file execution •  Deprecation •  JShell 84

Slide 85

Slide 85 text

@jeanneboyarsky Review lab 1.  Which operations succeeded on Arrays.asList? 2.  Did any operations succeed on List.of? 3.  Why do we need strip(), stripLeading() and stripTrailing()? 85

Slide 86

Slide 86 text

@jeanneboyarsky New java launcher mode Full command Shorthand javac HelloWorld.java java HelloWorld java HelloWorld.java Produces class file Fully in memory For any program For programs with one file 86

Slide 87

Slide 87 text

@jeanneboyarsky “Launch Single-File Source-Code” •  Designed to reduce ceremony •  For students learning Java •  Quick experiments •  Can have multiple classes in same file •  Can use built in Java classes 87

Slide 88

Slide 88 text

@jeanneboyarsky Simple Example 88 java HelloWorld

Slide 89

Slide 89 text

@jeanneboyarsky Multiple Classes 89 java SingleFile.java

Slide 90

Slide 90 text

@jeanneboyarsky Packages 90 java jb/HelloWorld.java

Slide 91

Slide 91 text

@jeanneboyarsky Deprecated (was on OCP) •  Finalize •  Constructor for wrapper classes •  (Nashorn) •  deprecated for removal/since 91

Slide 92

Slide 92 text

@jeanneboyarsky @Deprecated “Very few deprecated APIs were actually removed, leading some people to believe that nothing would ever be removed. On the other hand, other people believed that everything that was deprecated might eventually be removed, which was never the intent either.” From JEP 277

Slide 93

Slide 93 text

@jeanneboyarsky @Deprecated New Attributes Attribute Type Description forRemoval boolean Is the intent to remove API from Java at some point? since String Version of Java when API first became deprecated (not populated for all pre- Java 9 APIs) Only had for new APIs before

Slide 94

Slide 94 text

@jeanneboyarsky

Slide 95

Slide 95 text

@jeanneboyarsky @Deprecated Warning types •  Ordinary Deprecation •  Removal @SuppressWarnings("deprecation”) @SuppressWarnings("removal”) @SuppressWarnings({"deprecation", "removal"})

Slide 96

Slide 96 text

@jeanneboyarsky What is deprecated for removal? •  Unused code in AWT •  Some old security APIs •  Some thread and runtime APIs •  Some Jigsaw transition modules (but not classes) •  And…

Slide 97

Slide 97 text

@jeanneboyarsky Applets Finally deprecated! But… forRemoval=false Applet

Slide 98

Slide 98 text

@jeanneboyarsky JShell •  Probably not on exam •  You may (or may not) like it for prototyping •  Live demo

Slide 99

Slide 99 text

@jeanneboyarsky Module 4 – Question 1 Which is a valid way to run a Java program? A.  java HelloWorld B.  java HelloWorld.java C.  javac HelloWorld.java java HelloWorld D.  javac HelloWorld.java java HelloWorld.class 99

Slide 100

Slide 100 text

@jeanneboyarsky Module 4 – Question 2 Which of the following can run this program? public class Module4 { public static void main(String... args) {} } A.  java Test.java B.  java Test C.  Neither 100

Slide 101

Slide 101 text

@jeanneboyarsky Module 4 – Question 3 Which of the following can run this program? package x; public class Module4 { public static void main(String[] args) {} } A.  java Test B.  java x.Test.java C.  java x/Test.java 101 D.  java x/Test E.  None of the above

Slide 102

Slide 102 text

@jeanneboyarsky Module 4 – Question 4 Which of the following can run this program? public class Module4 { public static void main(String[] args) { java.util.List l = null; } } A.  java Test B.  java Test.java C.  Neither 102

Slide 103

Slide 103 text

@jeanneboyarsky Module 4 – Question 5 Which of the following can run this program? public class Module4 { public static void main(String[] args) { x.MyClass c = null; } } A.  java Test B.  java Test.java C.  Neither 103

Slide 104

Slide 104 text

@jeanneboyarsky Module 4 – Question 6 Which of the following can run this program? public class Module4 {} A.  java Test B.  java Test.java C.  Neither 104

Slide 105

Slide 105 text

@jeanneboyarsky Module 4 – Question 7 What are the default deprecation values? A.  forRemoval = false, since = null B.  forRemoval = true, since = null C.  forRemoval = false, since = 1.9 D.  forRemoval = true, since = 1.9 105

Slide 106

Slide 106 text

@jeanneboyarsky Lab & Break 106 See handout

Slide 107

Slide 107 text

@jeanneboyarsky Module 5 •  Review lab •  Streams 107

Slide 108

Slide 108 text

@jeanneboyarsky Review lab 1.  What error did you get running MathUtils? 2.  What error did you get running JavaDemo? 3.  What did you think of JShell? 108

Slide 109

Slide 109 text

@jeanneboyarsky Streams - ofNullable stream = dubiousObj == null ? Stream.empty() : Stream.of(dubiousObj); stream = Stream.ofNullable(dubiousObj); Optional.ofNullable() existed since Java 8

Slide 110

Slide 110 text

@jeanneboyarsky Streams - iterate Stream.iterate(10, i-> i-1) .limit(10) .forEach(System.out::println); Stream.iterate(10, i-> i>0, i-> i-1) .forEach(System.out::println);

Slide 111

Slide 111 text

@jeanneboyarsky Streams - takeWhile Stream.iterate(1, i-> i< 10, i-> i + 1) .takeWhile(i -> i < 5) .forEach(System.out::println); Assumes ordered stream. Takes all elements until one doesn’t match. So prints the numbers 1-4

Slide 112

Slide 112 text

@jeanneboyarsky Streams - takeWhile Stream.iterate( new SimpleEntry(1,1), e -> new SimpleEntry( e.getValue(), e.getKey()+e.getValue())) .map(Entry::getValue) .takeWhile(n -> n < 30) .forEach(System.out::println); How print all Fibonacci #s less than 30?

Slide 113

Slide 113 text

@jeanneboyarsky Streams - dropWhile Stream.iterate(1, i-> i< 10, i-> i + 1) .dropWhile(i -> i < 5) .forEach(System.out::println); Assumes ordered stream. Takes all elements until one doesn’t match. So prints the numbers 5-9

Slide 114

Slide 114 text

@jeanneboyarsky Streams - dropWhile Stream.iterate(new SimpleEntry(1,1), e -> new SimpleEntry( e.getValue(), e.getKey()+e.getValue())) .map(Entry::getValue) .dropWhile(n -> n < 30) .forEach(System.out::println); Note: This doesn’t work. takeWhile and dropWhile aren’t always opposites.

Slide 115

Slide 115 text

@jeanneboyarsky Module 5 – Question 1 What does the following output? long count = Stream .iterate(1; i-> i< 10; i-> i+2).count(); System.out.println(count); A.  0 B.  5 C.  10 115 D.  The code does not compile E.  None of the above

Slide 116

Slide 116 text

@jeanneboyarsky Module 5 – Question 2 What does the following output? Stream.iterate(1, i-> i< 10, i-> i++) .takeWhile(i -> i < 5) .forEach(System.out::println); A.  The numbers 1-4 B.  The numbers 5-9 C.  An infinite stream 116 D.  The code does not compile E.  None of the above

Slide 117

Slide 117 text

@jeanneboyarsky Module 5 – Question 3 What does the following output? long count = Stream .iterate(1, i-> i< 10, i-> i+2).count(); System.out.println(count); A.  0 B.  5 C.  10 117 D.  The code does not compile E.  None of the above

Slide 118

Slide 118 text

@jeanneboyarsky Module 5 – Question 4 What does the following output? long count = Stream.ofNullable(null).count(); System.out.println(count); A.  0 B.  1 C.  null 118 D.  The code does not compile E.  None of the above

Slide 119

Slide 119 text

@jeanneboyarsky Module 5 – Question 5 What does the following output? Stream.iterate(1, i-> i< 10, i-> ++i) .dropWhile(i -> i < 5) .forEach(System.out::println); A.  The numbers 1-4 B.  The numbers 5-9 C.  An infinite stream 119 D.  The code does not compile E.  None of the above

Slide 120

Slide 120 text

@jeanneboyarsky Module 5 – Question 6 What does the following output? long count = Stream.of(null).count(); System.out.println(count); A.  0 B.  1 C.  null 120 D.  The code does not compile E.  None of the above

Slide 121

Slide 121 text

@jeanneboyarsky Lab & Break 121 See handout

Slide 122

Slide 122 text

@jeanneboyarsky Module 6 •  Review lab •  Jigsaw •  Multi-release jars 122

Slide 123

Slide 123 text

@jeanneboyarsky Review lab 1.  Questions? 2.  What was hardest? 3.  Who wants to share their work? 123

Slide 124

Slide 124 text

@jeanneboyarsky Jigsaw basics •  Module system •  JDK is modularized 124

Slide 125

Slide 125 text

@jeanneboyarsky Simple module /src /package1 /module-info.class /MyClass.class 125

Slide 126

Slide 126 text

@jeanneboyarsky Module info module moduleName requires otherModuleName; exports packageName; 126

Slide 127

Slide 127 text

@jeanneboyarsky Base Module •  https://docs.oracle.com/en/java/javase/11/docs/api/ java.base/module-summary.html 127

Slide 128

Slide 128 text

@jeanneboyarsky Module graph •  https://docs.oracle.com/en/java/javase/11/docs/api/ java.logging/module-summary.html 128

Slide 129

Slide 129 text

@jeanneboyarsky Module file “commands” •  Requires – dependencies •  Requires transitive – grant to caller •  Exports – share package •  Opens – for reflection 129

Slide 130

Slide 130 text

@jeanneboyarsky Module implications •  java.base available by default •  Can have “private” package •  No circular dependencies 130

Slide 131

Slide 131 text

@jeanneboyarsky Sample •  https://docs.oracle.com/en/java/javase/11/docs/ api/java.base/module-summary.html 131

Slide 132

Slide 132 text

@jeanneboyarsky Multi-Release Jar /MyClass1.class /META-INF /MANIFEST.MF Multi-Release: true /versions /11 /MyClass1.class 132

Slide 133

Slide 133 text

@jeanneboyarsky Java Versions •  Override “default” files with latest version found •  Can specify Java 9+ explicitly •  If don’t specify, uses “default” files •  Java 8 will use “default” files 133

Slide 134

Slide 134 text

@jeanneboyarsky Multi Version Order Java 8 Java 9 Java 10 Java 11 Default 9 10 11 Default 9 10 Default 9 Default 134

Slide 135

Slide 135 text

@jeanneboyarsky Uses •  Alternate API •  More efficient implementations •  Not coupled to lowest version of Java in Prod 135

Slide 136

Slide 136 text

@jeanneboyarsky Module 6 – Question 1 What is the maximum number of multi-version folders you can currently have the are version specific? A.  1 B.  2 C.  3 136

Slide 137

Slide 137 text

@jeanneboyarsky Module 6 – Question 2 What is the name of the property to enable multi- release jars? A.  MultiRelease=on B.  MultiRelease=true C.  Multi-Release=on D.  Multi-Release=true E.  None of the above 137

Slide 138

Slide 138 text

@jeanneboyarsky Module 6 – Question 3 Which module command allows callers to access a package? A.  exports B.  opens C.  reflects D.  requires E.  None of the above 138

Slide 139

Slide 139 text

@jeanneboyarsky Module 6 – Question 4 What is the name of the folder for multi-release files? A.  files B.  multiRelease C.  multi-release D.  versions E.  None of the above 139

Slide 140

Slide 140 text

@jeanneboyarsky Module 6 – Question 5 How many modules are available by default? A.  0 B.  1 C.  2 D.  3 E.  4 140

Slide 141

Slide 141 text

@jeanneboyarsky Module 6 – Question 6 Which module command allows reflection? A.  exports B.  opens C.  reflects D.  requires E.  None of the above 141

Slide 142

Slide 142 text

@jeanneboyarsky Module 6 – Question 7 What is the name of the property to enable multi- release jars? A.  MultiRelease=on B.  MultiRelease=true C.  Multi-Release=on 142 D.  Multi-Release=true E.  None of the above

Slide 143

Slide 143 text

@jeanneboyarsky Lab & Break 143 See handout

Slide 144

Slide 144 text

@jeanneboyarsky Module 7 •  Review lab •  Study tips •  Harder questions 144

Slide 145

Slide 145 text

@jeanneboyarsky Review lab 1.  What did you observe creating the multi module jar? 2.  What flag did you use to specify version? 3.  How many modules are built in? Which look most useful? 4.  Did anyone succeed in packaging a module? 145

Slide 146

Slide 146 text

@jeanneboyarsky Preparing for the Exam •  Even if for Java 8 •  Study Guide (ex: Mine!) •  Mock Exams (ex: Enthuware) •  Study at least 15 minutes a day (advice courtesy of Bert Bates) •  Create a plan (even if don’t follow) 146

Slide 147

Slide 147 text

@jeanneboyarsky Preparing for the Exam •  Code snippets •  Memorize and write down that day •  How do use practice questions 147

Slide 148

Slide 148 text

@jeanneboyarsky Day of the Exam •  Writing instrument and materials •  Time management •  Flagging questions and multiple passes •  Don’t leave any blank! 148

Slide 149

Slide 149 text

@jeanneboyarsky After the Exam •  Celebrate! •  Tweet me your success J. 149

Slide 150

Slide 150 text

@jeanneboyarsky Almost the end... •  Ten more questions. •  Keep track of how well you do! 150

Slide 151

Slide 151 text

@jeanneboyarsky Module 7 – Question 1 Which is true? A.  Line x1 doesn’t compile B.  Line x2 doesn’t compile C.  Line x3 doesn’t compile D.  MAX is accessible to implementing classes E.  max2() is accessible to implementing classes 151

Slide 152

Slide 152 text

@jeanneboyarsky Module 7 – Question 2 What is output when run java Output.java? A.  5 B.  6 C.  Code does not compile D.  Code throws an exception at runtime 152

Slide 153

Slide 153 text

@jeanneboyarsky Module 7 – Question 3 Which is true of modules? A.  A single class can be exported. B.  A single package can be exported C.  They require a module-def file D.  They require a module-info file E.  None of the above 153

Slide 154

Slide 154 text

@jeanneboyarsky Module 7 – Question 4 What is output when run java Lists.java? A.  [x] B.  [y] C.  Code does not compile D.  Code throws an exception at runtime 154

Slide 155

Slide 155 text

@jeanneboyarsky Module 7 – Question 5 Where can you use var with try with resources? A.  For an effectively final variable used in a try with resources declaration B.  In the catch declaration C.  In an instance variable referenced by the body of the try with resources D.  In a try with resources declaration 155

Slide 156

Slide 156 text

@jeanneboyarsky Module 7 – Question 6 What is output when run java Lists.java? A.  [x] B.  [y] C.  Code does not compile D.  Code throws an exception at runtime 156

Slide 157

Slide 157 text

@jeanneboyarsky Module 7 – Question 7 Which is true of multi-release jars? A.  An older version of Java will ignore folders for newer versions. B.  Newer versions are designated with a version folder in the root directory C.  They can be unzipped in WinZip D.  You can create a “8” folder for Java 8 projects. 157

Slide 158

Slide 158 text

@jeanneboyarsky Module 7 – Question 8 What is output when run java Output.java? A.  5 B.  6 C.  Code does not compile D.  Code throws an exception at runtime 158

Slide 159

Slide 159 text

@jeanneboyarsky Module 7 – Question 9 Which are true statements? A.  If strip() returns true, trim() will always return true. B.  If stripLeading() returns true, trim() will always return true. C.  If trim() returns true, strip() will always return true. D.  If trim() returns true, stripLeading() will always return true. 159

Slide 160

Slide 160 text

@jeanneboyarsky Module 7 – Question 10 What is output when run java Lists.java? A.  [x] B.  [y] C.  Code does not compile D.  Code throws an exception at runtime 160

Slide 161

Slide 161 text

@jeanneboyarsky Book giveway 161