r/programming • • Mar 31 '21

Java still rocks the finance industry. Here’s why Java 16 makes it even better.

https://blogs.oracle.com/javamagazine/finance-quant-forex-java16
0 Upvotes

17 comments sorted by

1

u/ragnese Mar 31 '21

I've heard a few times now that Java is popular in finance. I'd love to see a Java codebase that's used by finance people. I see the article has some links to libraries- I'll check those out soon.

But I bet it's very different than what most of us are used to seeing in Java code bases.

Java adds so much memory overhead to every object, that I wonder how many custom classes and/or standard Java types these programs actually use. Is everything just static methods on long[]? Is it a problem that Java doesn't have (real) unsigned numbers? That it silently wraps around numbers on overflow?

Or are my ideas about the requisite performance and/or arithmetic accuracy at odds with reality?

12

u/pazvanti2003 Mar 31 '21

I actually work on a finance project that is built in (mostly) Java. I am not referring to a simple wallet app, but a full-on platform that handles payment processing for thousands of merchants. I can definitely say that it is NOT just static methods on long[], but we have well-structured projects and services (some micro...some a monolithic) and well-organized classes with complex data-types. While there can be (and definitely are sometimes) performance issues, the biggest problem is not the Java part (usually), but database access. At least after the improvements that were done in the past years. This is simply because you can mostly add new instances of the application if needed, but there is still only one (active) database.

2

u/ragnese Mar 31 '21

Thank you for the insight. Fair point about DB access. Likewise, I'm sure network overhead also still accounts for a fair amount of latency.

I guess I was thinking more about HFT than just the broader finance industry. I guess a bank doesn't even need to instantly reconcile every check deposit, etc...

2

u/ragnese Mar 31 '21

Also: can you tell me more about the service?

I assume you use a specific money-handling library for any money math, right? Or is Java's BigDecimal good enough?

Is there anything about Java that you really have to work against in your industry, like the fact that there are no unsigned numbers or built-in types for e.g., NonEmptyString?

Would you say that there are features of Java-the-language that actually make it better suited to your domain than other languages, or is it (as it usually is) all about the library ecosystem and developer availability?

2

u/pazvanti2003 Apr 01 '21

I actually worked on two financial products (3 years on the first, 4 on the second). The first one was written in C++. I was younger and less experienced back then, but as far as I remember, it wasn't necessarily better. There are indeed parts that were better, but some are definitely worse. The problem, though, is not the actual programming language. The C++ one had the first lines of code almost 30 years prior to the Java one and the difference in architectures and technologies is clearly visible. Both are still actively maintained and new features and improvements are constantly being added, but it is not easy to completely change the architecture.

One thing that I feel makes a big improvement on the Java project is the testing part. While there are C++ testing libraries and frameworks, in the C++ monolithic project, they are really hard to integrate. jUnit and TestNG are easier on the Java one.

In the end, I don't think that the language itself makes it better for the project, but the fact that there are more modern frameworks (like Spring and Hibernate) available with a wider selection of developers that knows them. Still, the fact that you don't have to constantly remember to remove memory you allocated and no work with pointers also helps :)

1

u/ragnese Apr 01 '21 edited Apr 01 '21

Thanks for the info.

I know exactly what you mean about working on an old C++ codebase. I spent many years working on a project that started in the mid-late 90s, so there were lots of "naked" pointers and implied ownership relationships, and inheritance hierarchies that "modern" best practices would frown at, etc.

May I ask how "critical" it was that these products had no bugs (of a particular kind)? And what techniques were used to mitigate them, if any, beyond what a typical C++ or Java codebase would (unit tests, etc)?

The reason I'm asking all these probing questions is because I've been working on JVM backend projects for years now and I've just found that trying to do almost anything in a robust way is really hard. The vast majority of projects I've seen (even simple CRUD) have plenty of holes for bad data to get in or out. Some examples I run into repeatedly:

  • In JDBC, if a database column is a nullable integer type and you call RowSet.getInt() when the column was null, you'll get 0- not null. You have to explicitly check if the column was null with a different call to RowSet. This is more "low level" than e.g., Hibernate, but Hibernate has a similar footgun in that marking an Entity field as @NonNull is not good enough- you also have to annotate the field as @Column(nullable = false) or some such. It can cause similar issues.

  • The validations annotations, including the built-in Java ones and the JPA/HibernateValidation ones don't truly prevent malformed objects. There are various ways to mark a field of a class as @NonNull and still end up with a null there.

  • MySQL, at least, is perfectly happy to silently truncate your data for you when you send, e.g., a BigDecimal in. Then when you read it out, you'll have a different value than what you put in!

  • I really like unsigned integers :(. I'd be such a happy camper if most languages had NonEmptyString, UInt, PositiveInt, etc, as built-in, optimized, types. Most of the time I don't actually want empty strings or negative numbers pretty much anywhere.

  • Global timezone nonsense. Java's Date and Time types are still crap, even after Java 8. Between the JVM's bad date handling and MySQL's bad date handling, I'm surprised anyone ever actually gets it correct. I'm this close to just always using long unixtimes for everything if I'm ever in charge of another JVM backend project. This also includes JacksonXML automatically ignoring timezone info by default on incoming JSON. WTF!

So that's why I ask. I'm not "hating" on Java, really, since most popular languages share most of these headaches, but I am a little surprised that we aren't using stricter languages when dealing with peoples' money, you know?

2

u/pazvanti2003 Apr 01 '21

There is no magic solution (sadly) for making it robust. I can't speak of other companies, but where I work we have code review for EVERYTHING. And I don't mean "check that the code is properly aligned". This obviously is not bulletproof, but in many scenarios it catches bad behavior. Nothing gets into production without at least another developer looking over it. More critical stuff even has a third person. For some components (that are REEEEAAAALLLYYYY critical) only a select few have access to edit them. Next is testing. Unit tests, integration tests, end-to-end tests. Some automatic, some manual. And in case anything goes bad, there is always revert to the previous version of the code. here the release process helps. But to be fair, sometimes it amazes even me that the product not only works, but it does the job well. Yes, we have problems (sometimes more often than we would like to admit), but never something catastrophically.

1

u/ragnese Apr 01 '21

Thanks for answering all of my prying questions.

It's a little disappointing that our industry still relies so heavily on humans just not making mistakes or overlooking something. That might have been good enough in the 80s when a code base was <10,000 lines of code, but I feel like it's totally untenable today with how complex software is.

Then we just pile on extra complexity when we do try to tackle correctness/robustness: annotations, static analyzers, code review, CI/CD, etc, etc, when I feel like we could tackle a lot of the problem much lower in the stack...

Sorry for rambling... xD

/rant

1

u/pazvanti2003 Apr 01 '21

Not a problem. Glad I could be of help. Keep in mind that, even though I consider myself an above average programmer, I am no genius and maybe a bit stuck with the same (oldish) tech. So there may be better ways of doing it and maybe other companies actually use them.

1

u/ragnese Apr 01 '21

Eh. I'm probably an average programmer myself. I'm just a programming language nerd and I'm always looking for that silver bullet that will let me and my forgetful brain write robust code. :)

1

u/pron98 May 07 '21 edited May 07 '21

Java's Date and Time types are still crap, even after Java 8

Are you talking about the old Date class or the java.time package?

2

u/ragnese May 07 '21

I specified "after Java 8", so I'm referring to the java.time package that was inspired by Joda.

And I was feeling a little extra harsh when I made the comment. Java's date stuff isn't horrible, but dealing with TimeZones is really awkward and bug-prone. The fact that there is a global, mutable, timezone variable at all is pretty disturbing. But then all of the stringly-typed junk around ZoneId, TimeZone, Offset, etc is BLEH.

Also, the whole TemporalAccessor interface is super-frustrating. I often have near-zero idea which methods will throw what for a given date-time type.

It's just hard to write robust date-time manipulations. Or maybe I'm just incompetent. That's certainly likely.

1

u/stronghup Apr 01 '21 edited Apr 01 '21

I think Java has a few things going for it for financial software.

First it is statically typed which gives its apps stability and maintainability. Static typing can prevent many errors that could otherwise creep in during maintenance. Financial applications need longevity. Yes many other languages have static typing too, but I think it is a requisite. It is a must-have for financial applications.

Secondly it makes it easy to model financial concepts like contracts as a tree of subclasses, and keep your program understandable on a modeling level.

Third it is a proven workhorse, many people know it. A financial institution does not want to rely on exotic languages that few people can understand.

So I think it is the "practicality" of Java that makes it a good fit for financial institutions. Not too crazy not too dumb just a good Goldilocks fit. I think Java is the new Cobol, the previous favorite of many financial institutions.

1

u/ragnese Apr 01 '21

Without sounding too negative and contrarian, this is kind of why I was curious. Java's type system has a lot of issues that make it bug-prone: nullable references, silent integer overflow, unchecked exceptions, primitive/error-prone concurrency, etc. I would have thought that the standard for financial stuff would have to be quite high and I don't see Java as being a good representative of what's possible with static typing. Pretty much every numeric operation you could possibly do in Java is a minefield of either a runtime crash or data corruption.

Also, the fact that interfaces must be implemented at class definition means that we can't extend other classes with our own concepts without wrapping them in another class ("the adapter pattern") which is cumbersome and makes for extra maintenance burdens. In fact, much of the "Gang of Four" design patterns are just a result of the limitations of Java's type system. It's mostly fine, but there are definite parts that make it non-trivial to model even basic things like an either-or concept (it's better now with sealed classes and the fancy new switch expression).

Then there's equality/identity issues. Did you know that BigDecimal(0).equals(BigDecimal(0.0)) is false?

Hell, you can't even reliably make copies of objects in many cases because Clone is weird.

I think your last point is likely the real reason. Basically... it's old and popular. Which is fine. But I'm still a little surprised.

1

u/stronghup Apr 05 '21

Definitely there is much room for improvement in Java. But I am sure there is even much more room for improvement in Cobol. Yet the financial industry has been a big user of Cobol for ages, I think.

2

u/ragnese Apr 05 '21

I actually have never even seen COBOL. One of these days I should actually play with it just for curiosity's sake.

1

u/quackquackgo Jun 01 '22

Maybe a little late but on my prev job we used Java for a banking system. As the other comment said, the bottleneck was the db.

Before that, on another job (also finance related), my boss wanted us to use Java because from his experience it was used for finance applications.