Showing posts with label Java 8. Show all posts
Showing posts with label Java 8. Show all posts

Tuesday, 10 June 2014

Java 8 Resources

This page mainly exists as a set of bookmarks for myself.

Java Magazine March/April 2014

Oracle Java tutorial
Online book
Third party blog posts
Videos

Monday, 9 June 2014

Deploying a Play application into Cloud Foundry

A week or so ago some colleagues gave a brief introduction to the local Cloud Foundry environment.

One of the main takeaways for me was that our application would need to be able to bind to a TCP port specified at runtime rather than have a statically defined one from a config file.

We spent some time looking into how to tell Play to listen on a provided port, and what might be involved in setting up a Cloud Foundry manifest file - then decided to just try deploying with something that we expected to fail.

We were pleasantly surprised to discover that the Java buildpack included enough logic to detect our application as being a Play application and looked after the port binding for us.

It wasn't a completely smooth process, as we did have to update the JDK version in the buildpack - which involved forking the Cloud Foundry github repository.  Three lines of text changes was enough to get it up and running.






Tuesday, 27 May 2014

A Java Refresher - some pain points and annoyances

With the recent release of Java 8 my new project team has chosen to take a look into Java as a viable alternative to the existing default language choice of Scala.

(In the interests of full disclosure we did originally opt for Scala, with a few caveats and a recommended reading list for the features to avoid or use sparingly).

I had already started reading Functional Programming in Java 8, but I think now is a good opportunity to look back over the features of the language and consider where there are particular strengths and weaknesses.

This post will only focus on Core Java - not Java Enterprise Edition, Swing or any frameworks.
  • Labeled break / continue
    • These expressions are the closest you can get to having a goto in Java
  • Checked Exceptions
    • I haven't quite convinced myself about this one yet, but I have a particular dislike for having to wrap a call with a try / catch block where the catch block only contains a comment like // can never happen
    • All too often exceptions are used to control flow for scenarios that aren't truly exceptional
  • Reflection
    • Generally prevents the compiler from having static access to the relationships between classes.
    • On the flip side, static analysis tools can be expected to make use of reflection.
  • Local classes
    • Did you know that you can declare a class inside any block?  Not just anonymous classes, but even fully fledged named classes.
  • instanceof
    • Whenever I find myself introducing an instanceof check in my code I feel like there must be a better way.
  • Restrictions on Generics

Runtime gotchas
  • Memory allocation
    • Out of memory exception - particularly PermGen space, and particularly when reflection or dynamic class loading is involved - before Java 8.
  • Garbage collection
    • Stop the world - collecting large accumulated garbage while blocking other progress.

Sorry for the lack of substance, but sometimes this blog exists as a checklist of reminders for myself.  I haven't Googled a problem and reached my own blog yet, but I can imagine it will only be a matter of time.