[2019 oracle code one] AMA Java

Everything You Ever Wanted to Know About Java and Didn’t Know Whom to Ask 

Speakers: Everyone 🙂

For more blog posts, see The Oracle Code One table of contents


Q&A

  • What is the best way to get a new method/feature into Java?
    • Discuss, open JEP, debate. Search Thread.onSpinWait() for an example
    • Discussion first is important. Starts discussion about problem. The code provided isn’t always the best way to solve it.
    • The thing that ends up happening is not what you started with
  • How to integrate collection PL/SQL in Java?
    • <missed answer>
  • Why is TreeMap implemented as a red black tree?
    • best/only way to do it
    • balanced tree
  • Is Java too slow?
    • Always want faster
    • Not too slow for a language with a statically compiled language
    • Tune for use case
    • Java will work faster on CPU don’t have yet. JIT compilers will optimize for it.
  • Is String interpolation coming?
    • Java 12 “briefly” had raw string literals
    • Recognize sprint interpolation is valuable
    • Need to figure out a way to do cleanly
    • Need to get multi line done. Then escape sequences. Then string interpolation
  • How move past Java 8?
    • Business and technical question
    • First step: will it compile/run
    • Don’t need to rewrite everything with new features
    • Business might not want to spend money on technical problem
    • A handful of people have only Java 11 in prod. Many people have one app/POC in prod. A lot of people only Java 8.
    • Java 9 and 10 is irrelevant. Nobody supports. Binaries not rebuilt with security updates.
    • The technical challenges are libraries that used Unsafe or assumed version strings begin with 1.x.
    • Evangelism message: upgrading to a higher version of Java is just like upgrading to a later version of 8.
    • Counterpoint: People have jars that don’t run on 11.
    • Sometimes features or APIs are removed.
  • How do you look at OSGi?
    • Nobody does anymore
  • Are you happy with the new release cycle?
    • Bruno interviewed Brian Goetz who said he was skeptical at first, but now done four times and smooth.
    • Java 13 came out this week. Brian was at Code One. Not managing process. No longer have months of meetings about release.
  • Deprecate serialization?
    • No plans
    • Many problems.
    • There is a need for something like serialization.
    • Brian wrote up ideas: http://cr.openjdk.java.net/~briangoetz/amber/serialization.html (Not a proposal for replacing serialization)
  • How do we keep up with six month releases?
    • Try when come out.
    • We know when they come out
    • Not a lot will break if do each time
    • Counterpoint: Play on laptop, but don’t use features until LTS comes out. If using 12.0.2 and security issue, you have to run 13 when it is 3 weeks old. Going to prod on feature release is risky.
  • Real tuples in Java?
    • Proposal for records in Java
  • Is it possible to break a nested loop in Java?
    • Yes with labels. [but please don’t].
  • Fixing exception handling on lambdas
    • Aware of issues
    • Not convenient to deal with
    • Ideas, but no current plans
  • Map on how to choose a JDK for a given use case
    • AdoptOpenJDK and Java Champions discussing how to create that map
  • New features we are looking forward to
    • Value types
    • Pattern matching
    • Generic specialization
  • How long will Unsafe be around
    • However long it takes to pull out all the useful features
    • ex: Java 9 var handles
    • Will take years
  • Low level libraries that are useful
    • ASM
    • Byte Buddy
  • Type extraction on return values
    • Return a tuple and set to multiple variables
    • “Let’s compare Java to Kotlin”
    • Could write something like it with pattern matching
  • Why are Strings in Java harder than other languages?
    • Strings have evolved
    • Unsolved problem
    • Changed a lot underneath
    • String concatenation now performed by invoke dynamic

My take

I like how he accepted questions both verbally and via Twitter. The variety of questions was fun. I like that Gil asked the “who is on Java 11” question well. He asked granularly enough to answer honestly and realistically. Stuart did a great job with his Dr Deprecator character when there was discussion about APIs being removed.

[2019 oracle code one] collections corner cases

Collections Corner Cases

Speaker: Stuart Marks @StuartMarks #CollectionsCornerCases

For more blog posts, see The Oracle Code One table of contents



General

  • Covers things in collections framework a long time. Not well known
  • Good mix of PowerPoint and JShell

JShelll

  • If don’t assign an expression to a variable goes in $1, $2, etc
  • /var $1 – prints type of variable (yes the slash is intentional, it is a JShell command.)
  • /open abc.jshell – “imports” file

View Collections

  • Don’t contain their own elements. Instead the elements are stored elsewhere
  • ex: Arrays.asList(array) – creates list backed by array. If change list, the array gets changed to and vice versa.
  • map.keySet(), map.values() and map.entrySet(). If change these three collections, underlying map changes too.
  • Map.Entry – has setValue() method. Can call setValue() on on entry set to change underlying map

Performance/Clarity

  • values() is O(n) on a Map
  • Creating a temporary HashSet for the values makes in O(1)
  • retailAll() – set intersection
  • Don’t always need streams. [My logic is if you wouldn’t have needed a loop, you don’t need streams]

Sorted Collections & Comparators

  • Interfaces: SortedSet, SortedMap, NavigableSet, NavigableMap
  • Implementations: TreeSet, TreeMap, ConcurrentSkipListSet, ConcurrentSkipListMap
  • Ordering provided by Comparator. Could be natural order or Comparable. May or may not be consistent with equals.
  • HashSet and Set.of() – iteration order undefined. For SortedSet, iteration order is well defined – sorted order
  • Comparator rules
    • <0, 0, >0 for less than, equal and greater than
    • Must provide a total ordering. Any two values must return result
    • reflexive, transitive, etc
  • Spent a while on set vs list (unique elements) – don’t forget what type you are working with
  • HashSet – doesn’t allow duplicates using equals()
  • TreeSet – doesn’t allow duplicates where compare(a,b) ==0
  • String class has built in comparator: String.CASE_INSENSITIVE_ORDER. Inconsistent with equals(). So using case insensitive order with a TreeSet and adding ‘a’ and “A’, doesn’t add ‘A’ to list. Also tree.contains(“A”) returns true if “a” in set. If have HashSet with ‘A’ and TreeSet with ‘a’, tree.equals(hash) returns true but hash.equals(tree) returns false.

My take

I learned something new under 5 minutes in. (keySet()/values() and entrySet() are backed.). I was also pleasantly surprised to learn new shell commands. The rest was good too :).

Also, I was reminded that I hate Map.of(). I fell for misreading them because I didn’t parse properly as alternating keys and values.

My Experience taking the new Java SE 11 Programmer II 1Z0-816 Exam

Update (11/05/2020): Read The 1Z0-819 Exam page to learn how you can easily our Java 11 Study Guides to prepare for Oracle’s 1Z0-819 Exam, as well as the 1Z0-817 Upgrade Exam.

Back in March, I took the new Java SE 11 Programmer I 1Z0-815 Exam only 2 days after it was released. Going into the exam blind, I wasn’t too worried because the previous OCA 8 1Z0-808 exam had been such a breeze. Boy was I surprised! While I passed with a decent margin, I was shocked the level of difficulty of the Programmer I 1Z0-815 exam. It was nothing like the 1Z0-808 exam it inherits from, especially in terms of question difficulty!

This past month, Jeanne and I finished writing our new Java OCP 11 Programmer I Study Guide (now available for preorder), which meant it was time to turn our attention to our upcoming Java OCP 11 Programmer II Study Guide. Rather than go in blind, and especially given all of the new material, I decided to spend some time studying *before* taking the 1Z0-816 exam. Well, it paid off because I passed today with a quite a wide margin. Below are some of my impressions of the exam.

Level of Difficulty

This might sound crazy, and I’m sure I’m biased, but overall I found the 1Z0-816 OCP11 exam less difficult than the OCP 8 1Z0-809 exam it inherits from. Don’t get me wrong, it was a difficult exam, but I felt like there were so many topics and they were so broad, the exam rarely went into especially deep detail on some of them. For example, many of the questions regarding SQL injection had pretty clear answers. In most of the questions, I was able to eliminate completely “ridiculous” answers right away, getting the answer choices down to 2 (or 3 if it was pick 2, or 4 if it was pick 3, etc). In fact, some questions I didn’t even need to read the text to whittle down the answer choices. For example, if an answer choice is an invalid lambda expression, it clearly cannot be a valid answer. With that in mind, most questions boiled down eliminating bad answers, then reading the question text to know which of the two remaining choices was correct.

Better Focused

One of the best changes they made in the new 1Z0-815/1Z0-816 exam series was to move most of the core Java syntactical questions to the first exam. While they made the 1Z0-815 exam harder, it made the 1Z0-816 exam a lot clearer. For example, if a question appears to be about NIO.2 on the 1Z0-816 exam, then it’s about NIO.2! On the older 1Z0-809 exam, I always felt like they mixed common Java topics with advanced ones. For example, a question that appears to be about NIO.2 on the 1Z0-809 exam might actually be about constructor overloading or overriding methods. In other words, the 1Z0-816 exam is better because the questions are derived from the objectives more cleanly, and there aren’t as many trick questions. You still have to know a lot to pass, but at least they aren’t mixing topics as much as they did in previous exams.

Streams, Streams, Streams

While the exam seemed reasonable to me, I’m also very proficient in streams. It is an understatement to say they are all over the exam. If you don’t use them regularly, you’ll need a lot of practice before taking the exam. Remember, they can show up in almost any topic like NIO.2, Concurrency, Collections, etc.

Modules

Modules are on the exam but I found the questions a lot more straight-forward than the module questions I saw on the 1Z0-815 exam. I had a lot of trouble with the module questions on the 1Z0-815 exam, in part because a lot of them didn’t make sense or didn’t appear to have a correct answer. Given how early I took the exam, Jeanne suspects I might have been exposed to beta/experimental/broken questions. That said, I thought the module questions on the 1Z0-816 exam were a lot more fair than they were on the 1Z0-815 exam. You need to know a lot about modules, of course, but the topics the questions were testing were a lot clearer.

Still a Very Broad Exam

While questions within a topic were relatively straight-forward, the amount of topics you had to know for the 1Z0-816 exam dwarfs the 1Z0-809 exam. Annotations, Security, Local Type Inference, Private/Static Interface Methods, and Modules are completely new. You should read the Secure Coding Guideline and Annotations Trail prior to taking the exam. Unfortunately, there’s not one single source of material for modules so you have to study from what you can piece together on the web… that is until our new 1Z0-816 study guide is released!

So You Want to Take the Exam?

Great! If you’re not in a hurry, I would wait for our new study guides to come out. The first book is already on its way to print and the second book will be available early next year. You can use our OCP 8 Study Guide to take exam, but you will have to supplement it with a lot of reading from a dozen different sources. And as I said earlier, if you’re not using streams regularly, you will definitely need a lot of practice. Regardless of which path you take, we wish you the best in studying!