Friday, 24 January 2014

Live Coding on Java 8 Date Time API

Yesterday I recorded a live coding session on java.time. Below is all the information so you can code along if you like:

The Video


The Source Code

All the source code is freely available on github you can get this running the following command:

The (brief) details for setting up the IDE can be found in the readme.

The Slides


Monday, 20 January 2014

Java 8 Date Time: Happy Martin Luther King Day

Today is Martin Luther King Day in the US. I had totally forgotten about this holiday until I saw a few tweets this morning about it. The interesting thing about this holiday is that rather than being on a specific day, it is on the third Monday of January.

As I'm currently preparing some JSR-310 material, I thought it would be interesting to share (and discuss) TemporalQuery - a new interface in Java 8 that makes it possible to write custom queries against the new DateTime classes. There is often a use case in business that an event happens that is unique to a particular domain, an example would be Futures market rolls of contracts or time periods of validity.

TemporalQuery allows us to capture the logic to perform an operation against a temporal class and return an object representing what we were querying. The interface is generic so we can choose what we return. This is a really neat design feature in Java 8 allowing us to externalise logic outside of the core API, but encapsulate the functionality as a data operation.

TemporalQuery is also a FunctionalInterface so it can be used as a lambda on a stream of temporals. In the example below we just consider one date. To find the next Martin Luther King day we can take the current date and perform the following:

LocalDate.now().query(new NextMartinLutherKingDayQuery());

The NextMartinLutherKingDayQuery is our implementation of a TemporalQuery:

Here are some things to note about the implementation:

  • In the private method I take a date at the beginning of January of the year passed. Using a TemporalAdjuster I manipulate that date to cycle it forward to where I want to be. TemporalAdjusters add more power than just plusDays or minusMonths to allow us to work on more expressive situations with date and time. 
    • The TemporalAdjusters class has some really nice methods as used here, or you can write your own TemporalAdjuster if it doesn't exist. 
    • NextOrSame is useful for this type of operation where we don't know what day we are on, but if it's the day we are querying we don't want to advance the day. We use it to iterate to the third Monday of the month of January in the year in question.
  • I then use a the Period class to find out from the date passed whether Martin Luther King Day has passed, or it is today. If it has passed I return next year's date, otherwise returning this year's date. Period is a nice abstraction so I don't have to start subtracting millisecond values etc - yes we've all seen it. 
If you're interested in playing around with this I suggest downloading the latest Java 8 beta and having a go. 

Happy Martin Luther King Day!

Saturday, 18 January 2014

User Group Visit to San Francisco

Why am I in San Francisco? 

Is it:
  • A micro brewery pub crawl?
  • The fact it's almost 20°C tomorrow?
  • To attend a Brazilian BBQ in January? 
These things are certainly going to be a nice bonus of being here, however that's not the main reason. I'm here representing the London Java Community at Oracle's big annual user group leaders convention. The purpose of the conference is to bring leaders of a variety of different Oracle user groups together to discuss best practices and drive improvement of communities and involvement for all those concerned. Particularly this year the topics I am interested in and will be participating in are:
  • Using social media - I'm particularly interested in discussing handling negative discussion and feedback via this extremely public forum.
  • Turning members into leaders and growing speaker talent. This has been an active stream in the LJC and Trisha Gee and team have been doing a fantastic job of running workshop and helping people gain the courage to make that first talk. 
  • Gamifiying your user group experience and improving user group content. I'm mainly interested in this because I get motivated by badges and awards for certain things. I think it could put a fun spin on how we run certain events in the LJC.
I plan to blog about interesting conversations and what comes out of these themes over the course of the week. The summit will only be the beginning of the discussions and I look forward to seeing more about what our members think to some of the ideas and which may work for us. 

When discussing any kind of conference and benefits of conferences I always say that it doesn't have to be a specific talk that motivates you but a catalyst to change. All the major turning points in my career have been down to ideas gained at conferences. It will be interesting to be involved in a non technical conference across a range of different products, experiences and backgrounds. 

I have very kindly had partial sponsorship from the LJC and the JCP Program Office to be here this week and I can't thank them both enough for the opportunity. 

I am now a JCP Executive Committee Representative

Why are the JCP helping to sponsor my visit here? After 3 years of working on JSRs with the London Java Community with the LJC JCP committee I have now stepped up my involvement and represent the LJC directly with other JCP executive committee members. I am attending my first face-to-face meeting at the end of this week. I'm really thrilled to be working with so many fantastic organisations and individuals to help maintain and form standards within Java. As the meeting has official minutes it's unlikely I will post anything further. 

Wednesday, 27 November 2013

Contributing to Java

I have just written a post on contributing to Java for the London Java Community's JCP Panel. You can find the full post here:



Sunday, 24 November 2013

The LJC Open Conference 2013

Yesterday I attended my 5th LJC open conference, and as always it is one of my favourite times in the year. Most of the major conferences have been and gone and people are winding down ready for Christmas. However, the combined knowledge and enthusiasm of the community doesn’t reflect this slower time of year. 

This year I got a lot more involved with helping in set up and planning board activities, as well as giving a talk on TDD primer. The session board looked like this first thing in the morning:


There are roughly 5 streams of topics at the conference, what interested me was the focus on development of people skills and testing of code - there was definitely a strong feel of craftsmanship in the air. 
  • Core Java
  • Java EE/Application Servers
  • Testing tools and processes
  • Community and soft-skills
  • Workshops
The slides I gave for my talk are below, it's based on a longer talk I gave at JAX London. The idea was to give people who haven't tried Test Driven Development before some guidance in getting started and what some of the pitfalls can be. Sadly I had a Mavericks and projector based issue, which meant I lost about 10 minutes of the talk. However, the show must go on so I covered the first slides without a project whilst the hero of the day John Stevenson fixed the projector. Minstrels will write songs about this day...


Test Driven Development Primer LJC Open Conference from jpgough

I got some good feedback on the talk - I need to refactor the examples in the slides a fair bit, this will be done when I put the information I presented at JAX into a blog series.

I also went to a talk on testing with Spock. It's not usually something I'd be particularly interested with it not being core Java, however it was interesting to see a different take on testing. I quite liked the way you can be verbose in your tests and get a lot of boilerplate you require in JUnit for free. The final talk I went to was on progressing your career without losing technical focus. A lot of people looking for mentorship and guidance at a senior level on how to remain technical. It was a good session, but only touched on a few issues in the time - it looks like something that could be run as a bigger round table.

It was great to catch up with old friends and people I've worked with in the community over the years, especially now I am not in London as often. It's also helped me start to focus on my own learning plan for next year. It's always a motivating weekend and if you didn't get chance to go this year I can't recommend it enough. As always thanks to the sponsors IBM for a great venue and beer from Zero Turnaround and some dodgy car salesman Simon Maple for organising the event.



Tuesday, 3 September 2013

Leaving London and keeping in touch

At the beginning of the beginning of the year Megan and I had our first child Emily and moved to Bedford. This sounds more severe than it actually was, the commute down from Bedford to Kings Cross is only around 40 minutes. It's been a busy 6 months since then working on multiple projects with Stackthread, getting promoted to Vice President at the firm and as you can imagine not too much sleep.

As a family, we have decided to take a step which will involve us spending a lot more time together - but sadly means that I will be leaving London as a work hub. Having just completed major project milestones at the bank I work for, I decided it was time for a change of roles and found an exciting opportunity in Milton Keynes. From a personal perspective this also cuts down a 2 hour commute (each way to Canary Wharf) to 20 minutes, and reduces my outgoing costs on expensive rail tickets.

This has left me with many decisions to make about what projects to keep working on in London and how to keep in touch with specifically the London Java Community and the London Java Community Process Committee. For now, I'm not going to make any rash decisions and see how things pan out in terms of time available and what I realistically commit to. With ever limited time, I am trying not to spread my contributions too thinly and want to ensure that whatever I do chose to work on in the next few years has a solid impact.

Currently, I next plan to be in London on:

  • 29th-30th October for JAX London.
  • One Saturday towards the end of November for the LJC Open Conference

JAX London 2013 - TDD: The Benefits are more than just the tests

An introduction to my talk at JAX 2013 - also published here.

Back when I first started my career as a developer following University I was unleashed with little training in best practices, development methodologies or what to expect from the uncertainties in real world development. Before I could start to learn all these things I was quickly placed in my first job. The type of role I was placed into was fix problems and develop new features - with only guidance relating to the specific tasks at hand. There was no training on industry best practices, which underpin the quality of the software as professionals we strive to deliver - my own development languished.

Several years on, in my own time and through quizzing various industry leading technologists like Sandro Mancuso (at JAX London 2012) and Martijn Verburg (at numerous beverage centric establishments) I started to discover my personal points of improvement. I realised that there were steps I could take to improve the approaches I had in my toolbox for software problems. I took a look at my peers and people that were applying for job roles. Many listed Test Drive Development (TDD) as something that they used on a regular basis. I very quickly realised that a lot of people claim to practice TDD, but either don't do this at all or write integration tests rather than unit tests, as well as other ideas about what TDD is.

My talk at JAX London 2013 is designed for developers who have been too busy to appreciate the less obvious benefits of TDD, particularly the side effects and task breakdown from a cognitive perspective. The session will cover the basics of TDD, the use of mocking and how this helps break up the coding complexity using code and architecture examples. I will also convey my own experience of converting to TDD along with the benefits I have realised and how to convince developers who don't want to test the approach has merits outside of just high test coverage. The talk does not aim to sell TDD, but instead present facts and experiences that I have gained over the last year so developers can form their own opinions.

From taking these steps myself I produce code closer to the requirements, more maintainable code that is able to respond quickly to changes and my colleagues can look at the code and tests and quickly understand what is going on. Conferences are often the catalyst for personal improvement, and people interested in this space but haven't had time to explore it themselves will get some good practical advice on how to get going and what to expect.