JavaCro 2014

April 15th, 2014 No comments

I will be seeing some Croatian friends in May in Porec, thanks to the organisers JavaCro 2014, who kindly sent an invitation to come and speak at their conference. I will give two talks: one keynote and a technical session. The working titles are Digital Development with Java EE and Mixing Scala with Java EE 7.

(Full size poster)

I would like to specially thank Branko Mihaljević, who I met at JavaOne 2012 for the invite and the HUJAK (Croatian JUG).
JavaCro’14 conference (javacro.org) has live takes place on 12th and 13th of May 2014 in hotels near almost 2000 years old coastal town Poreč, which happens to be one of the top tourist destinations in Croatia (javacro.org/venue/). The program schedule is now live. HUJAK expect 250+ participants and more than 50 sessions in 3-4 parallel tracks.

If you are in Croatia then I will be pleased to meet you in Porec.

Cake Pattern, Self Types and Realistic Example

April 9th, 2014 No comments

Original drafted 17 March 2014 for an incomplete article.

The Cake pattern for Scala using a flaming cake as well.

This is the quasi-production code:

package uk.co.xenonique.learning.cake

/**
 * The type Cake
 *
 * @author Peter Pilgrim
 */
class Cake(val name: String) {
  def inspect(): String = {
    name
  }
}

trait Oven {
  def powerUp(): Unit
  def powerDown(): Unit

}
trait CakeMaker {
  def bake( cake: Cake )
}

trait CakeFactory {
  def produce( cakes: List[Cake] )
}

class CakeFactoryImpl extends CakeFactory {
  this: CakeMaker with Oven =>
  override def produce( cakes: List[Cake] ): Unit = {
    powerUp()
    for ( c <- cakes) {
      bake(c)
    }
    powerDown()
  }
}

This is the learning test code:

package uk.co.xenonique.learning.cake

import org.scalatest.WordSpec
import org.scalatest.matchers.MustMatchers
import org.scalatest.mock.MockitoSugar
/**
 * The type CakeSpec
 *
 * @author Peter Pilgrim
 */
class CakeSpec extends WordSpec with MockitoSugar with MustMatchers {

  trait Baker extends CakeMaker {
    override def bake(cake: Cake): Unit = {
      println(s"I'm a baker, baking a cake: "+cake.inspect())
    }
  }

  trait IndustrialOven extends Oven {
    override def powerUp() = {
      println("firing up the oven")
    }
    override def powerDown() = {
      println("venting the oven")
    }
  }

  "Cake" should {
    "understand the cake pattern" in {
      val factory = new CakeFactoryImpl() with Baker with IndustrialOven {
      }
      val cakes = List( new Cake("Battenburg"), new Cake("Cherry Madeira"), new Cake("Lemon and Lime"))
      factory.produce(cakes)
    }
  }
}

Assuming that you know what you are doing: insert this code into a test Scala project with a decent IDE. Run the test should demonstrate the results.

What is the benefit of this so-called Cake Pattern? Well in short, Scala allows self-type with multiple traits (the dependencies). See the definition of CakeFactoryImpl, which expresses a dependency on the type CakeMaker and an Oven traits being mixed-in to the final concrete class. In other words, the final CakeFactoryImpl is a type of CakeMaker (Baker) and also it is type of Oven (IndustrialOven). Therefore, it is a small exercise to write mock objects with these traits, hence the reason I demonstrated with the pattern using a ScalaTest. In fact, it is an exercise to the reader, to write Mockito mocks of this CakeFactoryImpl. Imagine if your Oven was a reference, wrapper or connection pool to a database.

Finally, to understand the cake pattern you have to comprehend the Scala self-types and annotations. Personally, I found this pattern a little convoluted, because of the traits tend to have partial implementations in a production work.

WildFly System V Initial Script

April 9th, 2014 No comments

Originally drafted on 21 February 2014

Here is WildFly application serverSystem V Initial Script that I quickly put together for a Centos 6 virtual machine.
Use it at your own risk, don’t call me if something goes wrong, because I assume that you are an experienced Web Ops (web operations) or Sys Admin (system administrator) and you definitely know what you are doing.

Here goes cat /etc/init.d/wildfly.sh:

#!/bin/bash

: ${JAVA_HOME:=/usr/lib/jvm/jdk-7u51}
export JAVA_HOME

: ${SCALA_HOME:=/opt/scala-2.10.2}
export SCALA_HOME

PROC_LOCATION=/opt/wildfly-8.0.0.Final
PROC_NAME='WildFly App Server'
PROC_USER=wildfly
PROC_APP=wildfly
SLEEPTIME=8

export WILDFLY_HOME=${PROC_LOCATION}

# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/${PROC_APP}.pid

PREFIX_CMD=
## PREFIX_CMD='echo =>'

SUDO_CMD=/usr/bin/sudo

case "$1" in
  start)
    echo "Starting service ${PROC_NAME}"
    ${PREFIX_CMD} mkdir -p /var/log/${PROC_APP}
    ${PREFIX_CMD} chown -R ${PROC_USER} /var/log/${PROC_APP}
    ${PREFIX_CMD} ${SUDO_CMD} -u ${PROC_USER} -E ${WILDFLY_HOME}/bin/standalone.sh  >> /var/log/${PROC_APP}/${PROC_APP}.log  &
    exit $?
    ;;

  stop)
    echo "Stopping service ${PROC_NAME}"
    ProcessId=`ps auwwx | grep -v awk | awk '/'${PROC_USER}'/ && /org.jboss.as.standalone/ { print $2 }'`
    ${PREFIX_CMD} kill ${ProcessId}
    exit $?
    ;;

  restart)
    $0 stop
    echo "Zzz ... $SLEEPTIME secs"
    sleep $SLEEPTIME
    $0 start
    ;;

  probe|status)
    ProcessId=`ps auwwx | grep -v awk | awk '/'${PROC_USER}'/ && /org.jboss.as.standalone/ { print $0 }'`
    if [ "x${ProcessId}" != "x" ]; then
        echo $ProcessId
    else
        echo "No process is running."
    fi
    ;;

  *)
    echo "Usage: $0   start | stop | restart | probe | status"
    exit 1
    ;;

esac

#End

Categories: Integration, JavaEE, javaee7, Linux, Ubuntu Tags:

European JUG Leaders BOF at Devoxx 2013

March 29th, 2014 No comments

Here it is, just in time for the weekend, a recording of the European JUG Leaders BOF from Devoxx 2013.

Devoxx 2013 European JUG Leaders BOF from Peter Pilgrim on Vimeo.

Enjoy ;-)

PS: read up on my report to last November’s conference.

Categories: community, Conference, Devoxx, Europe, Java, JUGS, Leaders Tags:

Get The JavaEE 7 Developer Handbook as a Packt Pub 2000 BOGOF

March 24th, 2014 No comments

Packt Publishing have launched a campaign to coincide with the release of their 2000th title. As a Packt Pub author, I can inform you, the reader, this is a superb chance to get your copy of the Java EE 7 Developer Handbook (eBook) for free, or you can get another title free. Hurry up now, because the campaign runs until 26th March 2014.

Follow the follow link to Buy One, Get One Free Packt Pub offer . Please note you are allowed to apply this offer unlimited number of times during the checkout. For instance, If you want to buy two e-books then actually you can choose four.

Here is that hyperlink again.

Finally, I have started work on a second book for Packt Pub. It will cover the web application and digital software development themes around the Java EE 7 platform. That’s all for now.

Categories: Digital, discourse, JavaEE, javaee7, learning, Writing Tags:

Getting a more updated GlassFish 4

February 25th, 2014 2 comments

I was asked by someone where can they download GlassFish. Of course, I pointed them to the official website. The site was revised in time for the Java EE 7 last year, and when I recently the ask advice that I passed on, then I realize the server download is old.

So do we get a more recent build of GlassFish 4? We can build the server ourselves from source code and I already documented this process. The most conveniently way is to download from the promoted directory, which is listing version 4.0.1

Categories: Enterprise Java, Glassfish, JavaEE, javaee7 Tags:

Discount Code for Java EE 7 Developer Handbook

January 14th, 2014 Comments off

Start your new year with Java EE 7 learning. Stay update on us. Packt Publishing have kindly offered me a discount code for my book Java EE 7 Developer Handbook for the New Year 2014. So I am passing this code directly to you, readers of my blog and the wider community.

You have less than a week to do it: apply the discount code. Don’t miss out!


 

Discount code: abcde18
Expiry date of code : 19/January/2014
Discount percent for eBook and print format : 18%

 

How do you get the discount? Please apply the promotion code directly at Packt Pub website on checkout.

 

;-)
+PP+

 

PS: My sincere thanks to Amol Bhosle for getting this organised at Packt Pub.

Categories: Book, community, Competition, Java, JavaEE, javaee7, Writing Tags:

#ITMustChange2014 – Market Risk Role Java Job Question 2011

January 12th, 2014 2 comments

This is one old Java question from 2011 that landed on my desk. Admittedly, at the time, I was really looking for permanent role, senior Java developer in investment banking in London. I had given up on searching for that perfect banking Scala programming role, I went back to job hunting on Java EE 6, Spring, whatever I could find and I sent my CV down for Java developer in Markets Risk at some big bank. The context here was I had to write a Java project before I could get a vital face-to-face interview. Here is the reveal:

#ITMustChange2014

Please see below test for Market Risk at INVESTMENT BANK in the CITY.

Imagine this is a tasks/features in your current job and do everything you would to make a real-world task complete (e.g. javadocs, etc.).

import java.util.Map;

/**
 * Design a class to implement the StringUtil interface
 *
 */
public interface StringUtil {

        /**
         * sortChars - return a string containing all the characters of the input string, sorted in ascending order
         */
        public String sort(String input);
       
        /**
         * reverse - return a string containing all the characters of the input string, in reverse order
         */
        public String reverse(String input);
       
        /**
         * distribution - return characters found in the input string, along with a count of their occurrence in the string (order is unimportant)
         */
        public Map&lt;Character, Integer&gt; getDistribution(String input);

        /**
         * distribution - sort the characters of the input string and return the first n
         */
        public String getFirstNSortedChars(String input, int topN);
       
        /**
         * get characters in input string ordered by frequency of occurrence
         */
        public String getUniqueCharsSortedByOccurrence(String input);

        /**
         * get the character(s) that occurs most frequently in the input string
         */
        public String getMode(String input);

}

Unfortunately, I did not get very far in the process. It transpired that they were after experts in multi thread programming. I wondered then why did they not say so on the job specification or why the Java test did not reflect the true duties of the role?

Addendum: This test was dated 5th July 2011. I had nothing against the validity of the test itself to demonstrate how a developer can code against an application programming interface. On the other hand, as a chief engineer, I must emphasize this test, and many questions that are very similar to it, are just one part of an interview process. For instance, an answer to this example question does not necessarily reveal how the developer communicates with others, plays well in a team, and handles variability in the working environment.

Patronising the experienced

As a seasoned Java EE contractor, I think that I might find the question to be now patronising. If I was asked to fill in a question like this one from 2011 before a telephone interview, I would think it would be unusual. It would take second priority to a job inquiry that was a face-to-face or a telephone interview. Granted, there are always candidates and low-end contractors who want to chance their arm in order to get a gig with an exorbitant contractor rate, when in fact, they are truly incapable of delivery on their promises. From my point of view, the recruitment process would be flawed and the client may be inexperienced in hiring an engineer or may be the human resources department do not know quite what they doing. The burden of the recruitment process is unfortunately the responsibility of the hirer. If your process is like this: a preamble Java programming test, then Java test, then a telephone interview and then 6 hour assessment in a team situation and then a face-to-face interview with the development manager and then another face-to-face with human resources or the final decision-maker, then think about how many contractors of decent quality you will eventually see? Do you actually think that you will see lots of them? In a recessed economy this sort of long hire-to-work process may work, indeed it may have worked last year, but now, in 2014, we expect the green shoots of recovery to prosper and in a very competitive economy, it is less affordable.

Kitchen fitting

When you want to hire a kitchen fitter to install a £15,000 kitchen, you hunt for good rated recommendations from other people who have had similar kitchens installed or even talk to the people who sell kitchens and get a list of recommended installers from them. You certainly never put the kitchen fitter through a basic test of do you know what is best screwdriver to remove this old 1980′s cabinet from a prefabricated wall? You never question his modus operandi and the number of tools inside his work boxes. You as the customer (the client) trust the fitter to do his or her job, they will complete the installation and usually everybody will be satisfied. This is my point.

Say No to Fake Jobs!

Aim for standards

The IT industry is a bit unusual in comparison to the physical world of labour, which invariably has a list of professional bodies to assert accreditation through guilds and apprentices; and also government licenses and (inter)national standards (e.g. Gas safe registration). I am definitely sympathetic to the hiring client who is going through grave difficulties getting the right sort of engineer at the right level and quality that understands them, their hot problem(s) and wants some co-operation on a project from day one. All I ask, and I probably speak for many professional Java contractors, and I have been loquacious enough in this post already, is that clients do not slap down the good in order to compensate for the pathetic.


#ITMustChange2014

January 8th, 2014 Comments off

Instead of moaning, groaning and whining about the frustration of job search in the industry like I did last year and the years before. I am doing something about it this year, #ITMustChange2014 is the start of the awareness campaign. Here is the media, which is Creative Commons Licensed 3.0, Share-A-Like, No-Derivatives and Non-Commercial. So you are allow to copy this set of files and share with other. Please do share, re-tweet and repost in order to educate the entire industry. Thank you.

 

 

This is the logo:

 

 

 

This is the initial poster:

 

 

 

Here are the files for public consumption. JPEG are full-size here or the half-size and don’t forgot the logo PNG 24-bitand PNG 8-bit files.

 

+PP+

 

09/Jan/2014 I fixed an imperfection in the poster image’s emblem. I add link to the CC license legal code.


My Interview with the Server Side

January 8th, 2014 2 comments

Jason Lee Cameron McKenzie of  The Server Side .COM recently interviewed me late last year about my experiences of writing the Java EE 7 Developer Handbook. I gave some advice on to how to get into Java EE 7 as well as promote my book! I was quoted with “What would be nice is if we could use annotations to create our own administrative objects for JDBC, JMS, or even a managed task executor”. By this I meant that although Java EE 7 made significant progress to moving all of us closer to a future Java enterprise Platform-as-a-Service standard, obviously we all expect bigger progress in the next revision. I believe that Java EE 8 should have a standard way in application code to automatically inform the underlying application server (or cloud provider) container the resources that are required at deployment time. You can find the full interview here.

PS: On the subject of interviews in 2014, I got into a Linked-In conversation with a certain Peter Lawrey, of Vanilla Java blog; his popular site all about high frequency trading, low latency and Java performance fame. We discussed how he got started with his relatively brand new  consultancy business. We both agreed to turn my questions and Peter’s answers into an interview. I definitely recommend that you go read that if you are into core Java.

+PP+

[It was Cameron McKenzie who interview me for The Server Side on Monday, 28th October 2013. Sorry about that Cameron, how could I have forgotten? My mind has been like a sieve.]