days
0
3
hours
1
3
minutes
3
1
seconds
2
4
search
And the increasing use of Java in finance

Take advantage of Java 8: The change is very much worth it

Stephen Colebourne
Java 8

Positive x Negative image via Shutterstock

The fact that Java is one of the hottest programming languages in finance is no secret. However, making the shift to Java 8 might not be so easy, especially since coding in Java 8 is different to coding in previous versions of Java. In this post, JAX Finance speaker Stephen Colebourne explains why developers *should* make the shift to Java 8.

The Java platform has always been widely used in finance, but there is no doubt that Java SE 8 has helped reinvigorate the platform. Through blogs and conference talks, I’ve been trying to help developers make the shift to Java 8, emphasising that coding in Java 8 is different to coding in previous versions of Java. Coding standards need to be reconsidered and design patterns altered. But that change is very much worth it.

Java 8 vs previous versions

The most visible change was the introduction of lambdas and the associated streams API. They have definitely changed the feel of the language, allowing code to be written in a much more functional style. Abstractions that used to be verbose can now be done with ease, and this changes the way code is written and designed. But like all new features, there is a balance to be struck. Not all code reads better or performs as well when written using the streams API and lambdas. But where it does work well, it can result in much clearer code.

When lambdas were added, an associated change was to allow methods in interfaces. Thus an interface can now have three kinds of method — abstract, default and static. Where lambdas change code at the micro-level, methods on interfaces change code at the macro-level. New designs for subsystems become possible, and it can take a while to understand that potential. As an example, one pattern I have used frequently is to have an interface with one or more package-scoped implementations. Previously, this would have needed a factory utility class to create the instances, but now a static method on the interface can do the job. This can greatly reduce the amount of public code in an API if used correctly.

java.time.*

Another feature of Java 8 is the date and time library java.time.* (JSR-310). As the co-spec lead and primary author, I based the design on the principles of Joda-Time, the de facto standard library for versions of Java prior to 8. My goal with java.time.* was to make Joda-Time obsolete. Developers migrating their code to Java 8 should adopt java.time.* classes and remove Joda-Time where possible.

The great part about the new java.time.* classes is that they map so well onto the concepts found in finance. The `LocalDate` class represents a date without time or time-zone, and as such is a perfect fit for many business concepts, such as trade date, effective date and settlement date. Whereas `LocalTime`, a time without a date or time-zone, is a perfect fit to describe when the LIBOR fixing takes place, 11:00. And `Instant` is ideal for collecting a timestamp in monitoring and performance code. The key point here is that Java 8 has made finance in Java much easier – no need for the Joda-Time library anymore.

SEE ALSO: The clock is ticking: The Java browser plugin will be deprecated soon

Java in finance

To take advantage of Java 8 and the increasing use of Java in finance, I have spent the past few years at my day job building an open source library for market risk in finance. Strata, from OpenGamma, is a standard Java library available in Maven Central that allows anyone to create and manage financial instruments for the purpose of pricing and analytics. It has the potential to be a key building block for many organizations in the world of finance, with its open source nature ideal for the standardized products that the industry trades since the 2008 crisis. Strata has been written in Java 8 from the ground up, and makes full use of all the new features, with a strong focus on immutability and functional design.

Looking forward, Java SE 9 is on the horizon with its focus on modularization. This will be another big change to Java for developers to learn, but it is great to see the platform in such good health!

Learn more about this topic
Stephen Colebourne will be delivering two talks at JAX Finance 2017:

 

To read more about the marriage between software and finance, download the latest issue of JAX Magazine:

Does working in the finance sector pay off for software developers? The answer is “yes”. IT is a must have for most banks these days – a massive change from its previous “optional” status. That being said, if banks are trying to win developers over, why shouldn’t the latter learn a bit about this sector?

The technological needs of the finance industry include aspects such as Continuous Delivery, Java, Big Data, machine learning, low latency etc. By embracing these elements, the finance sector can change the status quo and co-exist with what appears to be a fierce opponent: FinTech. How should banks respond to FinTech? We invite you to open the magazine and find out.

Author

Stephen Colebourne

Stephen Colebourne has worked with Java since v1.0. He is a Java Champion and JavaOne Rock Star speaker. At OpenGamma, he produces open source software for the finance industry, but is best known for his work on date and time in Java.


Comments
comments powered by Disqus