Tuesday 25 August 2015

Java 8 - Nashorn

One of the new features in Java8 is Nashorn (JSR 292)
It is basically the introduction of an engine to execute javascript in the server side over the JVM.

Over the last years there have been many solutions to execute javascript in the server side. Originally Javascript was used exclusively in the client, but with the emergence of new technologies (some as successful and trendy as node.js) javascript executed in the server is a real option.

My first question when I read about the idea of develop javascript in the server was ... why? what could be the advantage of using javascript in the server side?
If you have been working in web application probably the idea is in your mind...validation. Making validation simple and simplify code could be one of the advantages of this approach. Take into account that one of the principles of a secure development is to validate the data in both client and server.
Another advantage could be the idea of a unique programming language, not splitting anymore in front end/ server side expertise. The third advantage I could think is in re-usability of code routines.

Ok,...and how does it works? Let's see

Calling Javascript function from Java

In this example we will use a javaScript function that validates email format

Now using the js function from java:

We can use javascript in java using these three basic steps:
  • Defining ScriptEngine (see argument "nashorn")
  • Reference our javascript file using eval method.
  • Using invokeFunction or invokeMethod methods from Invocable class to call our javascript.

Saturday 15 August 2015

OCEJWCD Preparing the exam - My experience

OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification

In this post I will try to summarize how I have completed this certification.

I had been preparing the certification since February. I sat the exam at the end of July, which means seven months preparing the exam. I have to say that it was far away of being full time, because generally I used free time in the weekends and sometimes some hours during the week. There were months I was more focused and others that hardly I could find time. I had previous experience in web applications but it was not an excuse I needed to study and practice.

Materials:

  • Book HeadFirst Servlets & JSP (O'Reilly). Authors: Bryan Basham, Kathy Sierra & Bert Bates.
  • Servlets 3.0 specification (JSR-000315)
  • Whizlabs: OCEJWCD practice test. These test include: Diagnostic test, Practice test(I,II,III) and Final test.

*Note: Initially I was planning to use Enthuware (because is a good relation quality-price, and many people in javaRanch recommends it), but finally I have been using Whizlabs because I had access provided by my company, which is a good point. 
Using whizlabs  you connect to a web platform and you can take the tests (5 mock tests in total, test by section and reporting result). I have to say this platform also helped me a lot in practicing OCPJP7 exam.

- Reading the book the first time:
Reading a chapter carefully until completion, and after that trying to do the questions suggested in the book at the end (generally 6-10 mock questions). Evaluate the errors and read carefully the explanations.
This task was completed intermittently, in several weeks.
The approximately grade of advance was 1 topic per week.
I realized that when I was completing the last sections I hardly remember some details for the firsts chapters, so the most sensible was to start again, so...

- Reading the book the second time:
I started to read the book again. This time I took notes in a notebook, something useful for a quick refresh. This time the reading was more fluent and help me to consolidate concepts.
This time I started to use Whizlabs mock exams by section at the same time I was advancing in studying.

- Further resources
new features included in Servlets 3.0 (annotations, asynchronous application, web fragments) are not included in the book. 

- Trying full mock tests from Whizlabs:
Between June and the beginning of July I completed Dignostic Test, Test1, Test2, Test3.

- Reading the book third time:
This time was a reading marathon. I re-read the entire book in one weekend(15 days before the exam).

- The last week:
I took again the demo test from Enthuware.  (I took the same by February the first time), because I wanted to compare results and progression. The score was good.
I completed the last Mock Test from Enthuware (good result). I focused in the question I failed, and I review the content.
I also reviewed my notes and summaries.

- The big day: 
I had the exam at 10.30, it is recommend to arrive to the Pearson Vue test center with enough time in advance, so I arrived at 10.00. After waiting I was conducted to the exam area. You have to sign a paper and also provide a proof of identity (passport). Then you are taken a picture (not the best face before the exam :) ). 

The exam: I found a different range of questions in terms of difficulty. Some of them quite obvious an other very complex. 
The good thing is that there is plenty of time to finish the exam (not like OCPJP7 that makes time a very important factor). I had enough time to review carefully full exam and also I had time left. 

I found it difficult (but much less than OCPJP7). 

I could check the results after 30 minutes approximately. I received a mail from Oracle, and then I could connect to Oracle CertView page and see the results. I was very nervous because I was not entirely happy with my performance during the exam. Fortunately I passed, not a very impressive result but very happy for passing (it is a big relief).
- Retrospective I can see the improvement after studying.

I decided to start publishing little summaries, diagrams and little pieces of code about the topics in the exam. I hope the posts can be useful but they are far away to be a complete guide to pass the exam. I think is a good way to see if you know the objectives of the exam. For example the book head first is structured in a different way of the current exam for OCEJWCD6

But independently of a test score I feel I have progressed a lot in web knowledge. I have learnt a lot of new things I did not know, even with experience in web applications. That is why my experience with certifications is positive because helps you to make a studying target, and the result is always rewarding.

In my opinion the actual value resides in the time spent reading, practicing and enjoying around areas specific in technology; not in the certification itself. Is a good way to be up to date and to refresh knowledge. I think also you can gain confidence as developer.

My next certification in mind.....probably Oracle certified Expert, Java EE6 Enterprise JavaBeans Developer.

I wish you all the best if you decide to prepare this certification and I hope any of these posts can be useful for you.

OCEJWCD (SCWCD) - 1Z0-899 - Web Component Developer Certification