Friday, 29 April 2016

Order in Initialization

Do you know what the following piece of code will print?




The answer is:

MyClass
Parent
MyClass
Test

Now can you tell which instance (instance1 or instance2) prints the first "MyClass" string?
 
Uncomment the commented lines and see for yourself!

http://stackoverflow.com/questions/14805547/are-fields-initialized-before-constructor-code-is-run-in-java

http://stackoverflow.com/questions/17806342/order-of-constructor-calls-in-multilevel-inheritance-in-java

Tuesday, 26 April 2016

Java EE Servlets

Introduction

I've been taking a short break before moving on to new challenges. With this occasion I'm tidying several older personal projects. Among these, my Haiku Gallery.

I resumed the review from watching again "Intro to Java. Unit 14. Intro to Java EE. GlassFish. Servlets." by Yakov Fain:



After reading Lesson 26 of Java Programming 24-Hour Trainer I wrote the vote servlet, adapted the client side of my application, packed everything in a WAR file using Eclipse IDE, and uploaded the archive to the Azure Cloud. As illustrated below.

The Client Side of VoteMyHaiku App


The Servlet


Vote My Haiku in the Azure Cloud:

http://votemyhaiku.azurewebsites.net/

Conclusions

1. I love Visual Studio Online "Monaco"!
2. Adam Bien is right: Java EE is easier than Javascript.

Homework (to self)

1. Warming up: Respond with beautiful HTML from the Vote Server Servlet.
2. Advanced: Persist votes in an SQL database. Re-order haiku pieces dynamically, based on voting results, and create a 'Top 3' section on the page.