Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2019-DevNexus-Java-11-cert-workshop.pdf

Jeanne Boyarsky
March 06, 2019
740

 2019-DevNexus-Java-11-cert-workshop.pdf

Note this was presented before the exam objectives came out. While it might help you learn some Java 11 material, it will *not* prepare you for the exam.

Jeanne Boyarsky

March 06, 2019
Tweet

Transcript

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

    View Slide

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

    View Slide

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

    View Slide

  4. @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

    View Slide

  5. @jeanneboyarsky
    Introductions
    5

    View Slide

  6. @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

    View Slide

  7. @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

    View Slide

  8. @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

    View Slide

  9. @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

    View Slide

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

    View Slide

  11. @jeanneboyarsky
    Exam History
    11
    + upgrade

    View Slide

  12. @jeanneboyarsky
    Exam History
    12

    View Slide

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

    View Slide

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

    View Slide

  15. @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

    View Slide

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

    View Slide

  17. @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

    View Slide

  18. @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

    View Slide

  19. @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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  23. @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

    View Slide

  24. @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

    View Slide

  25. @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

    View Slide

  26. @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

    View Slide

  27. @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

    View Slide

  28. @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

    View Slide

  29. @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

    View Slide

  30. @jeanneboyarsky
    Lab & Break
    30
    See handout

    View Slide

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

    View Slide

  32. @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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  37. @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!

    View Slide

  38. @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

    View Slide

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

    View Slide

  40. @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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  46. @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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  50. @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

    View Slide

  51. @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

    View Slide

  52. @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

    View Slide

  53. @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

    View Slide

  54. @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

    View Slide

  55. @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

    View Slide

  56. @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

    View Slide

  57. @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

    View Slide

  58. @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

    View Slide

  59. @jeanneboyarsky
    Lab & Break
    59
    See handout

    View Slide

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

    View Slide

  61. @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

    View Slide

  62. @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");

    View Slide

  63. @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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  70. @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

    View Slide

  71. @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

    View Slide

  72. @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

    View Slide

  73. @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

    View Slide

  74. @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

    View Slide

  75. @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

    View Slide

  76. @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

    View Slide

  77. @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

    View Slide

  78. @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

    View Slide

  79. @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

    View Slide

  80. @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

    View Slide

  81. @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

    View Slide

  82. @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

    View Slide

  83. @jeanneboyarsky
    Lab & Break
    83
    See handout

    View Slide

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

    View Slide

  85. @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

    View Slide

  86. @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

    View Slide

  87. @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

    View Slide

  88. @jeanneboyarsky
    Simple Example
    88
    java HelloWorld

    View Slide

  89. @jeanneboyarsky
    Multiple Classes
    89
    java SingleFile.java

    View Slide

  90. @jeanneboyarsky
    Packages
    90
    java jb/HelloWorld.java

    View Slide

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

    View Slide

  92. @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

    View Slide

  93. @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

    View Slide

  94. @jeanneboyarsky

    View Slide

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

    View Slide

  96. @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…

    View Slide

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

    View Slide

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

    View Slide

  99. @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

    View Slide

  100. @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

    View Slide

  101. @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

    View Slide

  102. @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

    View Slide

  103. @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

    View Slide

  104. @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

    View Slide

  105. @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

    View Slide

  106. @jeanneboyarsky
    Lab & Break
    106
    See handout

    View Slide

  107. @jeanneboyarsky
    Module 5
    •  Review lab
    •  Streams
    107

    View Slide

  108. @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

    View Slide

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

    View Slide

  110. @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);

    View Slide

  111. @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

    View Slide

  112. @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?

    View Slide

  113. @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

    View Slide

  114. @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.

    View Slide

  115. @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

    View Slide

  116. @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

    View Slide

  117. @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

    View Slide

  118. @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

    View Slide

  119. @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

    View Slide

  120. @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

    View Slide

  121. @jeanneboyarsky
    Lab & Break
    121
    See handout

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  133. @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

    View Slide

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

    View Slide

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

    View Slide

  136. @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

    View Slide

  137. @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

    View Slide

  138. @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

    View Slide

  139. @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

    View Slide

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

    View Slide

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

    View Slide

  142. @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

    View Slide

  143. @jeanneboyarsky
    Lab & Break
    143
    See handout

    View Slide

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

    View Slide

  145. @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

    View Slide

  146. @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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  151. @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

    View Slide

  152. @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

    View Slide

  153. @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

    View Slide

  154. @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

    View Slide

  155. @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

    View Slide

  156. @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

    View Slide

  157. @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

    View Slide

  158. @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

    View Slide

  159. @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

    View Slide

  160. @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

    View Slide

  161. @jeanneboyarsky
    Book giveway
    161

    View Slide