How to register for the OCA 8 or OCP 8 study guide online materials

Wiley/Sybex recently redid their website. One of our readers (and I), didn’t find it that intuitive how to register the book to gain access to the practice materials. Their tech support was excellent and now I know what to do!

It’s actually the same as the old procedure. I just had trouble finding the links

Step 1 – Get an access code

  • Go to the registration URL
  • Choose the OCA 8 or OCP 8 book from the pull down
  • Fill out the form. Note that you’ll need the book handy to answer one question about it. Don’t worry. The question will be something like “what is the caption of Figure 1.2” and not something that requires understanding the material

Step 2 – Get the access code.

Wait until you get an access code in your email. The instructions say it takes up to 24 hours, but I got it within 5 minutes.

Step 3 – Add code on the new test bank website

If you bought our OCA/OCP Practice Exam book, you already have an account on this site. If so:

  • Log in
  • Click redeem access code
  • Copy/paste the access code from the email

If not, sign up for an account now.

  • Go to the test bank site
  • Click create account
  • Copy/paste the access code from the email
  • Filll out the other fields

DevNexus 2019 – Alternatives to Java Reflection and Unsafe Usage – Chandra Guntur

See the table of contents for my other blog posts from the conference

This presentation is a lot of live coding with this kata.

JSR 292

  • Multi Language VM proposed in 2016
  • Code named Da Vinci Machine project
  • Gained ability to change classes and methods at runtime

Issues with reflection

  • Performance overhead
  • Security restrictions
  • Exposes internals – breaks abstractions and encapsulation

Method handle

  • Goal is to make as fast as a statically linked Java call
  • Mainly same since Java 7
  • More verbose than reflection
  • Performance benefit because only checks accessibility the first time you use it
  • Main APIs:
    • MethodHandles.Lookup – searches for a method handle
    • MethodHandle – execution logic
    • MethodType – represents return type and input parameters of a method. Immutable

Katas

  • Call constructor using a method handle
    • MethodHandles.publicLookup() – gives a loop reference
    • MethodType.methodType(void.class) – constructors don’t have return types so void
    • lookup.findConstructor(DemoClass.class, methodType) – actually get the MethodHandle
    • handle.invokeExact() – invoke method (well, constructor) with no parameters. Need to cast result so correct type.
  • Pass in parameters
    • handle.invokeExact(“paramValue”) – note that the parameters are bound at runtime. If call with wrong params, get runtime exception
  • Call a public method
    • MethodType.methodType(String.class, String.class) – a method that takes a string and returns a string
    • lookup.findVirtual(DemoClass.class, “methodName”, methodType) – call public method with findVirtual
    • handle.invoke(demoClass, “param”)
  • Call a private method (protected and package private work the same way)
    • DemoClass.class.getDeclaredMethod(“name”, String.class)
    • privateMethod.setAccessible(true) – just like with reflection
    • lookup.unreflect(method) – creates lightweight version
    • handle.invoke(demoClass, “param”)

VarHandle

  • Unsafe still deprecated (but not removed) in Java 12
  • VarHandle replaces Unsafe in many cases
  • Standard replacement for some features for atomic concurrency and Unsafe
  • Can use to access field/array index elements
  • Memory fences for fine grained control of memory ordering
  • A strong readability fence
  • Improves safety – requires content types to match/be castable. Also requires array indexes to exist
  • Improves integrity – Follows field access rules including honoring final
  • Performance equivalent to Unsafe
  • API more usable than Unsafe because intended to be an API
  • Uses coordinates since fields are referenced by name.

My take

I like reflection so this was a good opportunity to learn about it’s “successor”. I enjoyed seeing the live coding. In addition to Method Handles code, it was nice to see the callouts to some IntelliJ features. Chandra did a kata on VarHandles. I didn’t take notes on that since I was reviewing my presentation which is next.

DevNexus 2019 – java things that make you go huh – Bob Paulin and Freddy Guime

See the table of contents for my other blog posts from the conference

Scene 5 – singleton makes spring factory return same object each time

Scene 6 – multi release – showed exploring a jar and the alternate files. Which shows a jar can have different behavior. Nice demo of a new way to shoot yourself in the foot!

My take

I misssed 2/3 of the session. I like that each scene stood alone so I could enjoy those parts. And enjoy I did. Their costumes and characters were awesome!