Sunday, 19 April 2015

Java 8 - Beta Exam Attempt

Well, last Wednesday, 15 April 2015, I tried to get certified in Java 8 by taking the Upgrade to Java SE 8 Programmer Exam. It contained 126 questions and I was given 3 hours to provide all the answers.

For more information on what topics are required reading, see reference [1].

Given the fact that I am not yet comfortable with the new features of Java 8, answering the questions took a lot of time. I was unable to complete the last 12 questions due to this.

The beta exam is now no longer available.

I'll have to wait approximately 11 weeks for a result, though. A long time to wait, but that's always the case with Beta exams.

At least it's behind me now. Next up is trying to get certified with Scrum.

Thoughts

Here are some of my thoughts:
  • there were a number of 'trick' questions
  • learn the method signatures of java.util.function, luckily the naming scheme is extremely consistent
  • learn the difference between the source of stream, the intermediate operations, and the terminal operations. Here's some pointers:
    • a stream, once evaluated, can no longer be used. Trying causes an InvalidStateException.
    • omitting a terminal operation, causes the Stream to not be evaluated at all.
    • using two terminal operations, of course, causes a compile error
    • a stream doesn't change the underlying source
  • learn the additional operations now available (using Lambdas) on the already existing Collections of the Collection framework
  • learn when an interface is a functional interface. Here's some pointers:
    • @FunctionalInterface is not a requirement
    • what happens when you add default methods?
    • what happens when you add an abstract method?
    • what happens when you add an abstract method, whose signature is equivalent to an existing method in the Object class?
    • what happens when you add a static method?
    • what happens to a functional interface that inherits from another interface
  • Remember what Daylight Saving Time is, the clock is advanced by one hour during summer months (in March), the clock is returned to normal time (turned back one hour) during the winter months (in October)
  • practice,... a lot ([2] is a good reference with exercises)

References

[1] 1Z1-810 Upgrade to Java SE 8 Programmer
https://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-810
[2] Java SE8 for the Really Impatient
Cay S. Horstmann

Monday, 16 March 2015

Javascript "let" keyword vs "var" keyword

One of the differences between JavaScript and Java, is regarding variable scope.

In JavaScript there are two kinds of scope, global scope and function scope. Any local variable declared in a function, is visible everywhere in the function.

In the example above, both secondCarName and thirdCarName are local variables, only accessable within the function.

Note that, though the thirdCarName is declared inside an if-then block, this matters naught.

A gobal variable is visible everywhere. In the example above, this would be firstCarName.

Java

In contrast, in Java, scope can be within a method (sort of the equivalent of function), but also in block scope.

Therefore, netherlands is only available within the if statement.

let vs. var

Apparently, ECMAScript saw fit to provide JavaScript with a way to also support the Java-way of scope using the new let keyword.

But be wary, there will probably always be situations where Java and JavaScript will display different behaviour.

With let, it is possible to create a variable that obscures the variable in the higher block. This is in contrast with Java, where a error is thrown during compiling.

Disclaimer

My experience with JavaScript is spotty at best. The intricacies of scope in Java and JavaScript are more subtle than the isolated examples described here. And the new let keyword makes the scope in JavaScript even more subtle.

References

Stackoverflow - Javascript - “let” keyword vs “var” keyword
http://stackoverflow.com/questions/762011/javascript-let-keyword-vs-var-keyword
JavaScript|MDN - let keyword
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let
Hangar.Runway 7 - The Javascript Guide to Objects, Functions, Scope, Prototypes and Closures
http://hangar.runway7.net/javascript/guide