r/java • • Oct 21 '20

What are some great Java libraries I'm probably not using but I should?

334 Upvotes

252 comments sorted by

70

u/cinlung Oct 21 '20

HikariCP Database pool. Check it out.

28

u/CaptainKvass Oct 21 '20

I found out at some point that the database driver we were using, C3P0, hasn't been updated in years, and switching to HikariCP improved the responsiveness of all API interfaces significantly.

6

u/coder111 Oct 21 '20

Funny story. I had a use case and did a POC recently for when you want to use a connection pool, but connect with different username/password depending on context to enable some database-level security.

Only C3P0 actually has support for this feature.

5

u/malbone Oct 21 '20

I did this with hikari and spring jdbc some time ago. Check https://www.baeldung.com/spring-abstract-routing-data-source

3

u/coder111 Oct 21 '20

Meh, kinda, if you want to bootstrap multiple HikariCPs yourself depending on context I guess you can do it. AFAIK C3P0 already has this specifically for usernames/passwords, out of the box, and with configuration managing both total connections and connections for each user etc.

That being said, I much prefer HikariCP to C3P0 if you don't need this particular feature.

1

u/zynasis Oct 21 '20

Database level security is so archaic

5

u/coder111 Oct 21 '20

It depends. Having layered security sometimes is a good idea. If all your security stuff is on one layer, and that gets compromised, you're completely screwed.

3

u/zynasis Oct 22 '20

I usually just have app accounts and polices. Rather than user accounts authenticated by the database

5

u/coder111 Oct 22 '20

Which means that you have one username accessing the database for all your users/customers.

Which means that if one of your users gains direct database access via your app account (say via SQL injection which is very real), information for ALL users can be accessed and leaked.

If you are building a multi-tenant application where your users are companies and potential competitors, this is absolutely not acceptable. Hence added layer of security.

→ More replies (1)
→ More replies (6)

51

u/GuyWithLag Oct 21 '20
  • immutables.io for automatically generating builders for your immutable objects

  • https://mapstruct.org/ for automatically generating mappings between different domains

  • retrofit for proper java REST APIs.

  • JDBI for plain-SQL database access that is slightly higher-level than JDBC.

3

u/michaelloo35 Oct 22 '20

Immutables are so awesome imho they made lombok deprecated

5

u/VincentxH Oct 21 '20

Use mapstruct with caution if you don't know what hibernate does :p

60

u/_INTER_ Oct 21 '20

Use Hibernate with caution if you don't know what Hibernate does

57

u/wildjokers Oct 21 '20

Use Hibernate with caution even if you do know what Hibernate does.

23

u/_INTER_ Oct 21 '20

I think noone knows that Hibernate really does, except maybe Vlad Mihalcea

5

u/general_dispondency Oct 22 '20

That's really sad if true. How query derivation and execution work in hibernate isn't really that complicated. Learning how hibernate works has 100% made me a better developer. Especially with regard to generic api development. I wrote a similar framework a couple of years ago that does something similar to hibernate but it abstracted away rules engines. We had integration for ODM and Drools. Clients would just decorate their domain model with annotations that described their facts and rules and we handled the rest. 10/10 would reuse that pattern.

0

u/[deleted] Oct 21 '20

[deleted]

→ More replies (3)

11

u/rootException Oct 21 '20

I wrote a book on Hibernate and could not agree with this more.

Use Spring Data and KISS instead.

1

u/batinex Oct 21 '20

isn't spring data an abstraction on hibernate?

4

u/rootException Oct 21 '20

More of an abstraction over all kinds of data:

https://spring.io/projects/spring-data

The JDBC repositories are much simpler than full Hibernate/JPA

https://docs.spring.io/spring-data/jdbc/docs/2.0.4.RELEASE/reference/html/#reference

→ More replies (5)

1

u/franky_mctankerson Oct 22 '20

immutables.io

Use Spring with Caution even if you think you think what Spring does!

6

u/Scarfior Oct 21 '20

Are you referring to lazy loading or something else?

2

u/VincentxH Oct 22 '20

Yeah and the proxy collections, especially newbies I recommend logging the SQL statements so they can see what they are implicitly doing.

0

u/[deleted] Oct 21 '20

[deleted]

4

u/wildjokers Oct 21 '20 edited Oct 21 '20

You should be doing DTO Projections to just query the data you need for read-only queries. Querying for entities for a read-only query and then mapping the entity to a DTO with mapstruct/orika/whatever is just wrong in almost all cases (I will say almost because I am sure someone will chime in with a case where it seems reasonable).

This is probably the biggest mistake people make when using Hibernate. It shines in the create/update cases. Entities simply aren't needed for read-only.

2

u/rbygrave Oct 22 '20

For people using Ebean ORM note that per query we can turn off lazy loading as needed (or use DtoQuery of course).

5

u/GuyWithLag Oct 21 '20

I prefer not to use Hibernate. The amount of time needed to investigate issues is far more than the time needed to implement per-object mappers in f.e. JDBI.

56

u/shubham_2206 Oct 21 '20

7

u/awesomeusername2w Oct 21 '20

Also, there is jOOL from the same guys. It provides some neat functional utilities.

1

u/Charliejfg04 Oct 21 '20

Glancing at the code examples, is it only for selects? No inserts, updates, deletes?

8

u/shubham_2206 Oct 21 '20

It supports all database operations.

8

u/lukaseder Oct 21 '20

It's for selects, and 1 or 2 other things

60

u/[deleted] Oct 21 '20

Not sure whether this is a popular library. But I use https://github.com/tomakehurst/wiremock for mocking dependent webservices responses in my Unit Tests

3

u/SomethingMor Oct 21 '20

Can confirm we use wiremock extensively.

1

u/stfm Oct 21 '20

It's also fantastic for creating test data for API responses, or decoupling development from an externally operated interface.

1

u/Cpowel2 Oct 21 '20

A million times this. Isolated functional testing is such a time saver

1

u/franky_mctankerson Oct 22 '20

Forget mocking - use testcontainers and use the actual service itself! :-)

2

u/foreveratom Oct 22 '20

TestContainers requires a full blown Docker install on the host. It's not always convenient.

20

u/cyrusomega Oct 21 '20

Eclipse Collections: https://www.eclipse.org/collections/. Easily the best implementations of primitive and high performance data structures that I've ever used. It can make a *huge* difference in GC times and performance of high throughput pipelines.

1

u/MmmmmmJava Oct 22 '20

+1

This library is one of the best in this thread.

10

u/kapta Oct 22 '20

LWJGL Excellent library not only for games but also desktop applications. It provides access to many low level libraries and features which are not typically available to Java, such as EGL, OpenCL, OpenGL, OpenGL ES, Vulkan, GLFW, JAWT, nfd, tinyfd, OpenAL, Opus, Assimp, bgfx, DriftFX, LibOVR, meshoptimizer, NanoSVG, NanoVG, Nuklear, par_shapes, par_streamlines, OpenVR, Shaderc, SPIRV-Cross, Tiny OpenEXR, Tootle (AMD), Vulkan Memory Allocator, Yoga, stb, Bullet Physics, CUDA, dyncall, jemalloc, libdivide, LLVM, LMDB, LZ4, ODBC, Remotery, rpmalloc, xxHash, Zstandard.

Its highly performant and a completely modular (so you can download a version with only the features you need).

28

u/DJDavio Oct 21 '20

Pitest for mutation tests. Don't just unit test for coverage, but make sure that you are asserting useful stuff. Pitest messes with your code like a gremlin would and checks if the tests break (they should). If tests don't break, you might have good coverage, but still potentially a lot of bugs.

3

u/yawkat Oct 21 '20

Great library. I probably wouldn't use it for everything but it's super useful for testing data structures with lots of complicated code.

1

u/supercargo Oct 22 '20

Pitest is a great concept and a really powerful approach to getting more meaningful metrics about test “coverage”. I find it isn’t quite as “free” as basic line/branch coverage tracking since I usually have to manually contain its scope to keep runtime under control, but I can reliably find test flaws with this tool. And a significant portion of the time those flaws are covering for true bugs.

16

u/mbazos Oct 22 '20

My new favorite project https://www.testcontainers.org/

1

u/franky_mctankerson Oct 22 '20

Easily a top-5 best of all time open source project (and I go back all the way to JUnit/Ant in 2003!)

8

u/magicfoodhand Oct 22 '20

Retrofit, http client - https://github.com/square/retrofit

Javalin, http server - https://github.com/tipsy/javalin

HikariCP, database connection pool - https://github.com/brettwooldridge/HikariCP

Dagger, compile time dependency injection - https://github.com/google/dagger

20

u/King5lay3r Oct 21 '20

https://github.com/dhatim/fastexcel

For generating and reading Excel files. So much faster and much easier to use than "Apache POI: the memory hog".

3

u/audioen Oct 22 '20 edited Oct 31 '20

Thanks for that. I'll throw POI to the river. I hate that library.

Edit: now merged into one project. Project deployment file is 25 % smaller. I already dropped poi-ooxml for being 20 MB large, but even the older Excel format support is still 5 MB, in compared to this which seems to be like 100 kB. I doubt there is any impact on performance as the Excel files are not large.

Also, this fastexcel is the most straightforward, abstraction-free implementation imaginable. You look at this code and it spews XML straight out using string concatenation from its POJOs, which are very simple too. It's a different style from your usual fare, but I like it. I'm sure that it performs extremely well because you couldn't push abstraction level at implementation much lower than this.

2

u/SomberGuitar Oct 22 '20

POI was my money maker for a few years. Definitely a memory hog.

14

u/rstartin Oct 21 '20

Roaringbitmap https://github.com/RoaringBitmap/RoaringBitmap

After a while every problem starts to look like it can be solved with bitmaps.

7

u/maxandersen Oct 22 '20

I'm biased here but https://jbang.dev is a great thing to use to check out all these nice suggested libraries without having to deal with a lot of setup.

See https://github.com/jbangdev/jbang/tree/master/examples for examples.

Any of these you can directly using jbang, ie.

a jfx app:

jbang https://github.com/jbangdev/jbang/blob/master/examples/jfxtiles.java

or try out java 14 records

jbang https://github.com/jbangdev/jbang/blob/master/examples/records.java

or even a Quarkus app:

jbang https://github.com/jbangdev/jbang/blob/master/examples/quarkus.java

17

u/_predator_ Oct 21 '20
  • AssertJ for fluent assertions

  • WireMock for testing interactions with APIs locally

  • Failsafe for easy retrying & circuit breaking logic

There are a lot more, but I don‘t remember them all right now.

2

u/SixBucksAGallon Oct 21 '20

I was about to suggest Hamcrest, but AssertJ seems nice. Well, maybe next project.

6

u/coder111 Oct 21 '20

Depends on what you're trying to do. I'll add my favourite:

MapDB or LMDB with Java wrapper. Off heap Map in memory mapped files. Very fast, persistent, able to store millions of entries with meager memory requirements without overhead.

6

u/_soundvibe Oct 22 '20

Just a few from the top of my head:

  • vavr

  • testcontainers

  • resilience4j

  • caffeine

6

u/ReasonableClick5403 Oct 22 '20

MockWebServer from okhttp deserves its own mention. it is so great for testing stuff on the wire. miss it every time im not writing java.

okhttp for http client.

resilience4j for 'things'

caffeine for caching. greatest caching library i ever touched.

bigger projects:

Apache Tika is incredible.

more controversial: protoc and protobuf.

5

u/Shnorkylutyun Oct 21 '20

JUnit/TestNG ;) (tongue in cheek, at times it seems like nobody is using unit testing) Quarkus as an alternative to spring boot

13

u/wsppan Oct 21 '20 edited Oct 21 '20

Assertj, Mockito, BeanIO, logback, Jackson, JaxB, Apache Commons,

8

u/friekert Oct 21 '20

Yeah, Apache Commons. Came here to say that 🙂

2

u/fujohnwang Oct 22 '20

commons-lang3

4

u/markopi Oct 22 '20 edited Oct 22 '20

http://h2database.com/html/mvstore.html

Great if all you need is a (sorted) Map that's persistent on disk. This is the default storage engine for H2 database, but comes in a separate lightweight jar.

4

u/[deleted] Oct 22 '20

Eclipse Collections. Free. Gives us immutable lists and sets next to mutable ones, with built-in support for mapping, reducing, filtering, zipping, and other collection operations.

There's some pretty good tutorials available, and that is necessary, for the documentation itself is lacking.

Immutable and unmodifiable lists give you all the guarantees you need to process data in parallel free of common parallelism problems.

24

u/inspectedinspector Oct 21 '20

Guava. Tons of capabilities but the ones I use and like:

Immutable collections
Useful collection utilities beyond java.util.Collections
Guava cache is very nice

30

u/cogman10 Oct 21 '20

Check out Caffeine for a better more Java 8 friendly cache.

As for the collections stuff, IMO, if you are running on java 11+ there's not much reason to want them. You can do unmodifiable collections for everything.

5

u/inspectedinspector Oct 21 '20

if you are running on java 11+

Soon...

Appreciate the tip on Caffeine

5

u/TheOccasionalTachyon Oct 21 '20

I like the ImmutableCollection subclasses because they make explicit that the object is immutable.

List.copyOf is great, except that it doesn't give me a way to promise, in a compiler-checked way, that, say, a method ending in return List.copyOf(foo); returns an immutable value that's safe to use as a constant.

1

u/-jp- Oct 22 '20

They're also nice for interoperability, since your code can accept a regular Java Platform collection, use Guava to make the usual defensive copy, and it will only actually do the work of copying the collection if it needs to. If it's something that Guava recognizes is already immutable it just returns the argument unchanged.

5

u/sureshg Oct 22 '20

java 11+ there's not much reason to want them

This..more over it's a huge dependency (~ 3 MB)

13

u/nutrecht Oct 22 '20

Guava is very prone to giving you nasty version conflicts due to the way they handle versioning. IMHO stuffing everything into one big library is such a bad idea that I tend to completely avoid Guava if possible.

It should be split up, like apache commons is.

5

u/VincentxH Oct 22 '20

So common that it's used in many gradle and maven demos on how to deal with version conflicts.

4

u/nutrecht Oct 22 '20

Pretty much the only way to use it properly in a library is to shade it to prevent conflicts, but who wants to shade a 30MB+ library.

0

u/[deleted] Oct 21 '20

[deleted]

10

u/inspectedinspector Oct 21 '20

I don't know if that's a constructive assessment but sure, understand what you're signing up for. It used to be way more useful when Java lacked Optional and some of the collection utils.

4

u/ReasonableClick5403 Oct 22 '20

Yeah, I have enormous respect for Guava and their efforts. Nowadays I will however use vavr and caffeine for immutables and caching, respectively.

2

u/_litecoin_ Oct 21 '20

I'm curious if there is more that you use besides immutable collections and cache?

6

u/riawot Oct 21 '20

I agree that Guava isn't as useful as it was pre-Java 8.

However, I've still gotten a lot of mileage out of the multimaps, and also the multiset greatly simplified an unusual requirement we had. Not that stock Java couldn't handle it, but those two collections made it much more straightforward and readable. I still use them even though I'm on Java 11.

Also the string splitter has been useful for some ETL loads from a 80s legacy system

2

u/inspectedinspector Oct 21 '20

I guess maybe it's just that at this point... we started using Guava with Java 7 and got more mileage out of the collections and Optional. Looks like it might be time to re-evaluate.

7

u/sureshg Oct 21 '20

https://jodah.net/failsafe/ - for handling failures

1

u/waka-chaka Oct 22 '20

Can you tell me how would this and resilience4j compare? I couldn't much info online.

9

u/kag0 Oct 21 '20

Immutables.io and vavr.io Immutability massively cuts down on bug potential and immutable persistent collections make some algorithms much easier.

13

u/VincentxH Oct 21 '20

Vavr, lots of datastructures for advanced functional programming patterns in Java

0

u/[deleted] Oct 21 '20

[deleted]

1

u/VincentxH Oct 22 '20

Because Optional is enough to replace the Either, Try and more?

1

u/jeenajeena Oct 22 '20

Meaning that most of the functionalities of vavr are already provided by Java11, which makes vavr way less useful?

12

u/supercargo Oct 21 '20

Guice for dependency injection. You're "probably" not using it since you are "probably" using Spring...but if you aren't using Spring or only use Spring for DI, Guice is nice and much less "magical" than Spring.

6

u/thephotoman Oct 21 '20

Or you're in JavaEE land and using Weld.

6

u/angryundead Oct 21 '20

I like Weld enough to have used it outside of EE as a standalone thing.

Don’t do that.

2

u/vips7L Oct 25 '20

I've used Weld for SE and it was pretty easy.

1

u/angryundead Oct 25 '20

Yeah it’s pretty easy but I would say it’s fairly unexpected to come across. I like the CDI implementation of Weld better than the others.

5

u/angry_corn_mage Oct 22 '20

Have you tried Dagger? I did and never looked back

3

u/MmmmmmJava Oct 22 '20

If you’re willing to trade features for speed, Dagger is an amazing choice.

Compile time/codegen DI utterly stomps runtime and reflection DI in initialization speed, which makes worlds of difference in short lived JVMs (like AWS lambda or any other Function as a Service).

3

u/rbygrave Oct 22 '20

Add in https://avaje.io/inject for a more server side orientated dagger style DI (source code generation). Has lifecycle support etc

1

u/supercargo Oct 22 '20

Looks interesting, I will have to try it out on a smaller project where I follow the IoC pattern without even bothering to use a DI framework. In that case I have about half a dozen lines of “wiring” code in the app bootstrap which should be equivalent to what dagger generates.

For my day job, dagger doesn’t appear to offer any benefits I’d need. Reflection for DI is really a minuscule fraction of startup time for long lived server apps. Also, we have a whole array of multi-tenancy extensions built using Guice scopes, not sure how that would translate to dagger. Looks great for mobile development though!

3

u/-jp- Oct 22 '20

Speaking of, there's a good presentation by Brian Clozel and Stéphane Nicoll that lays out how Spring does its magic in a nice, clear way. Like most magic, it's actually fairly straightforward once you know the trick. It's fairly long though--you'll want popcorn.

https://www.youtube.com/watch?v=jDchAEHIht0

2

u/wildjokers Oct 22 '20

Guice is nice and much less "magical" than Spring.

What is even less magical than both of them is just passing the collaborators to a class via its constructor. No framework needed.

6

u/W1z4rd Oct 21 '20

Here is a great list of java libraries https://github.com/akullpp/awesome-java

6

u/Dexior Oct 21 '20

Testcontainers definitely revolutionized my integration testing.

8

u/[deleted] Oct 21 '20

Vavr - https://www.vavr.io/

Big fan on some of the types like Validation which allows u to chain validations in a very nice functional way.

Way to many apis that gives you one error at a time and you have to trial and error which Validation solves for you.

3

u/vmcrash Oct 21 '20

SWT for being able to create good looking, fast graphical user interfaces. Also can be easily compiled to native executable (with swt.dll dependency) using GraalVM.

6

u/rootException Oct 21 '20

Have you compared SWT with the latest JavaFX stuff?

1

u/vmcrash Oct 24 '20

No, I haven't looked at JavaFX - can it also be compiled to native code? I just have looked at GUI libraries of other programming languages (Go, Rust, Nim, ...). None came close to SWT. Swing also is a decent framework compared to the other ones I've seen.

1

u/rootException Oct 24 '20

The short version is yes, you can compile to native. I have found wrapper libraries that also add automatic updating and crash reporting. It’s a work in progress for me right now, integrating the pieces.

Biggest problem is that ideally I’d like to use Java modules to build a slim app (eg closer to 30mb than 300mb), but the modules ecosystem is still very primitive. Going to look at Graal.

Hoping to post a summary once I (knock on wood) get it all working.

3

u/Hakky54 Oct 22 '20

I could recommend this page on GitHub https://github.com/akullpp/awesome-java it contains a list of java framework and libraries including categorized into different use cases

3

u/marcelofrau Oct 22 '20

Do you know awesome java? https://github.com/akullpp/awesome-java

"A curated list of awesome Java frameworks, libraries and software."

2

u/cezarAug Oct 22 '20

Happy cake day

3

u/spamthemoez Oct 22 '20

https://github.com/jhalterman/failsafe

Failsafe is a lightweight, zero-dependency library for handling failures in Java 8+, with a concise API for handling everyday use cases and the flexibility to handle everything else. It works by wrapping executable logic with one or more resilience policies, which can be combined and composed as needed. Current policies include Retry, Timeout, Fallback, and CircuitBreaker.

3

u/rbygrave Oct 22 '20

For source code generation approach to DI and jax-rs have a look at https://avaje.io/inject and https://avaje.io/http - targets javalin and helidon se.

3

u/G0nz0e Oct 22 '20
  • lombok - for boilerplate stuff like getters/setters/toString/builders etc. , had no major problems when using it so far,

  • vavr - functional candy, love working with Either and Try

  • StreamEx - functional candy for streams, when you are using java8

  • jclouds - file store which can be switched to different providers when deploying to cloud

  • jolt - transforming / cleaning json (think of xslt for json), i recommend reading the introduction (https://docs.google.com/presentation/d/1sAiuiFC4Lzz4-064sg1p8EQt2ev0o442MfEbvrpD1ls/edit#slide=id.gd6a76464_02)

  • jsoniter - fast json processing, nice api

  • jhipster - crud spring boot application generator

  • spotbugs maven plugin - really prevents mistakes

  • testcontainers - for real integration tests

  • https://github.com/dorkbox/MessageBus - lightweight message bus based on MBassador

3

u/DJDavio Oct 22 '20

Another one: https://github.com/lukas-krecan/ShedLock

We use this for scheduled tasks in a cloud environment with multiple instances where only 1 of the running instances needs to perform the task. It's like a cronjob, but you can do it from within a normal application instead of having to create a special cronjob application.

1

u/pgris Oct 22 '20

Shedlock is awesome. I can't believe it is not already included with Spring.

I see a progression Shedlock -> Quarz -> SpringBatch in both functionality and complexity, and Shedlock is often all you need.

3

u/Gleethos Oct 22 '20

Idk if it counts but: The spock testing framework! :)

5

u/guss_bro Oct 21 '20

TestContainers, Beanmother, javafaker, Zip4j, openpdf, etc

36

u/vallyscode Oct 21 '20

This one I think is a must have https://projectlombok.org/

20

u/balajikrb Oct 21 '20

Agreed its a good one. But with Java records I think it will have less impact or need.

6

u/riawot Oct 21 '20

agree

We heavily use lombok, but it's almost entirely for areas that records will cover. We're on Java 11, and records is like to be the single biggest driver to migrate to a newer version.

The second biggest driver, of course, is fear that if we fall too far behind we'll get stuck like those poor bastards that are stuck on Java 7

edit:

when records drop and get integrated into the codebase, we will reevaluate our lombok usage

4

u/CaptainKvass Oct 21 '20

True to some extent. Lombok provides refactoring-safe equals and hashcode methods as well.

1

u/balajikrb Oct 21 '20

Agree. Hope to see similar improvements in java records in future

8

u/krzyk Oct 21 '20

Java records already provide those (equals and hashcode and toString is generated out of the box).

1

u/vallyscode Oct 21 '20

We use aws coretto 11 distribution, so not that many fancy things. I saw 15 on the branch but not yet a release

1

u/aykutaknc Oct 26 '20

Corretto for java 15 has been released btw

55

u/wildjokers Oct 21 '20

Lombok has saved me almost no time, my IDE can generate all that boilerplate with a few keystrokes. But lombok has definitely cost me a lot of time figuring out issues a few times.

11

u/vallyscode Oct 21 '20

Forme one side it hides all that boilerplate so that code is readable, from the other side there can be some unexpected surprise. Something for something.

39

u/coder111 Oct 21 '20

I'd have to disagree.

I have spend more time troubleshooting cases where people added another property and forgot to regenerate equals/hashcode/toString than I spent troubleshooting Lombok.

1

u/VandaL-van-Doge Nov 18 '20

Maybe the right way to fix this would be to have a test rather than depend on Lombok. Just my two cents. Cheers!

3

u/coder111 Nov 18 '20

Dude, are you seriously proposing unit testing all the getters and setters and hashcode/equals? That's a bit extreme/expensive, don't you think?

2

u/VandaL-van-Doge Nov 18 '20

If you unit test your functions alone well enough, this shouldn’t be a problem from what I’ve seen. Besides, might be my inexperience, I haven’t really encountered any use cases where there was ever a need to rely on Lombok generated setters or hash codes to the point of it causing that many issues. The few times we have encountered such cases they seem to ultimately be symptomatic of bigger issues like an anemic domain or god classes.

-3

u/[deleted] Oct 21 '20

+1

10

u/Akthrawn17 Oct 22 '20

Amen to that. Lombok is overrated and can cause unforseen problems with the magical generation of code

→ More replies (2)

4

u/SomethingMor Oct 21 '20

We used to use Lombok before it became a huge pita. Now it’s like a 4 letter word on our team.

4

u/chacs_ Oct 21 '20

You forgot the /s

0

u/[deleted] Oct 21 '20

[deleted]

3

u/Hinigatsu Oct 21 '20

Can you explain some controversy?

14

u/wsppan Oct 21 '20

It munges the byte code after you have compiled the code. Your JVM does all the steps of error checking, optimization, etc to give you byte code that is guaranteed to reflect your source code and then hands off to lombok to change. That is a lot of black magic and trust in order to avoid boilerplate code that your IDE can auto-generated for you.

3

u/nutrecht Oct 22 '20

everybody needs to be on board.

Meh. Whenever this gets discussed it's generally the people who haven't used it who are against it. In such a situation I don't quite agree with "everyone needs to be on board".

0

u/[deleted] Oct 21 '20

[deleted]

1

u/Akthrawn17 Oct 22 '20

Kotlin for the win on data classes.

4

u/riawot Oct 21 '20

most of the usual suspects have been named, so I'll recommend Spring Data JDBC

It uses the typical Spring Data concept, you annotate some POJOs, you define a repository interface, you add derived queries on the interface. Same as typical Spring Data JPA

But! But! Instead of doing a lot of hibernate bs, it just runs a jdbc query to build an object graph of what you want. You get a bunch of POJOs, all loaded up, no lazy loading, no weird layered caches that work great till they don't. You don't need to build your db for hibernate, you just need to build it in a sensible way.

You can do whatever you want to the objects, but no changes are written back unless you explity save the object back to the repository. So no unexpected surprises on when the data gets to the db, especially since different components and services are querying the database, it's not just one big ass monolithic application.

We've been thrilled with it, it gives pretty much everything we want out of Spring Data JPA. It's limited outside of CRUD scenarios, but honestly, being able to talk to the database with a quick interface definition and some derived queries is we all really want out of an ORM. We can use actual SQL via JOOQ or Spring jdbcTemplate for reporting or other non-CRUD scenarios

2

u/sureshg Oct 22 '20

I would also recommend micronaut data - https://micronaut-projects.github.io/micronaut-data/latest/guide/#introduction

  • No runtime model

  • No query traslation

  • No reflection

  • Type Safety

2

u/digitizemd Oct 22 '20

I've worked with Spring JDBC template (a coworker had written a nice layer on top of it) that I loved and I highly recommend it. I will give Spring Data JDBC another look, though. How do you find mixing the two? Pretty straight forward?

0

u/maxandersen Oct 22 '20

You are describing what Hibernate StatelessSession does.

runs queries (using native sql or hql) build a object graph with pojos - things only saved/updated when you call.

5

u/ranger403 Oct 21 '20 edited Oct 21 '20

Apache commons(lang,file etc)..amazing library with lots of helper methods we use day to day!

https://commons.apache.org

Bouncy castle for cryptography

2

u/jconcode Oct 21 '20

You may miss DataMelt - https://datamelt.org -a Java program for visualization and data science. This program was first created in 2005 (but lately rebranded with a different name).

2

u/jconcode Oct 21 '20

another idea - https://jwork.org/jport - this one is an application launcher for ~200 Java programs.

2

u/Magick93 Oct 22 '20

Its a specification more so than a library - I really like CDI. The reference implementation is Weld.

2

u/sudkcoce Oct 22 '20

Immutables.

3

u/dark_mode_everything Oct 22 '20

Quartz scheduler. It supports cron syntax and is awesome. https://www.quartz-scheduler.org/

Also imgscalr for efficiently resizing image files.

3

u/C_Madison Oct 22 '20

https://lucene.apache.org/ If you do anything which needs search you want to use Lucene. There is no better search library out there. If you don't want a lib, but something you can call you want Solr, the search server build on Lucene. Both are released together.

Bonus: You do not want Elasticsearch. It will not do what you need and it will bring you pain.

4

u/gitaroktato Oct 21 '20

Spring Boot, JUnit, Mockito are the most popular ones as I've seen. Also probably would recommend Hibernate.

18

u/OzoneGrif Oct 21 '20

Hibernate is often nightmare to use properly.

I would recommend jOOQ instead.

5

u/gitaroktato Oct 21 '20

Yes, Hibernate can be a nightmare often, but as I've seen it's more popular than JOOQ. So you can't avoid learning to use Hibernate properly.

1

u/lukaseder Oct 21 '20

Of course you can. 2 easy steps:

Step 1. Use jOOQ. Step 2. Avoid "it".

2

u/gitaroktato Oct 21 '20

Sounds so easy that next time I'll try to apply and see how it goes :)

2

u/constructivCritic Oct 21 '20

I don't think those are competitors. But maybe by hibernate you all mean some specific part of it, that would compete with JOOQ.

3

u/lukaseder Oct 22 '20

It's not uncommon to add jOOQ to JPA applications for queries and reporting, but from what I can tell, people don't often add JPA to a jOOQ application. At least, I don't remember any support case, Stack Overflow question, etc. hinting at going that direction

2

u/constructivCritic Oct 22 '20

Right, that would make perfect sense.

2

u/rbygrave Oct 22 '20

Ebean ORM is a hibernate competitor

2

u/VincentxH Oct 22 '20

One does not just use an ORM.

3

u/CaptainKvass Oct 21 '20

I would recommend jOOQ instead.

Isn't that paywalled?

6

u/_predator_ Oct 21 '20

It‘s free to use with OSS Databases like MySQL, Postgres and SQLite. They‘re only charging for commercial DB support (Oracle, Azure etc.), see here. Pretty nice pricing model imo.

2

u/CaptainKvass Oct 21 '20

Oh, that's cool. Thanks!

1

u/wildjokers Oct 21 '20

For commercial databases yes.

4

u/_litecoin_ Oct 21 '20

Hibernate should die

2

u/Hoskit Oct 21 '20

Lombok. Never write (some) boilerplate again

5

u/xKoem Oct 21 '20

Yeah, but start using it after you wrote at least a bit of boilterplate to know whats going on behind this "magical" annotations

2

u/VincentxH Oct 22 '20

You mean generate?

1

u/veryspicypickle Oct 21 '20

Lombok is good for DTOs with getters and setters. For domain classes I have my reservations.

→ More replies (1)

1

u/Tarlovskyy Oct 22 '20

How about Google Guava, and my awesome professors implementation of an ARRAY-BAG datastructure!

1

u/plokhotnyuk Oct 22 '20

https://github.com/ngs-doo/dsl-json - one of the fastests JSON parser for Java

1

u/[deleted] Oct 22 '20

Protostuff for compact and fast serialization.

1

u/altmind Oct 22 '20

if you have large, deeply nested beans, for example from DOM or JAXB mapping, jxpath helps greatly navigating them.

1

u/[deleted] Oct 22 '20

Webflux: https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/web-reactive.html

This has enabled us to reduce most of our microservices from running on like 20 to 60 servers down to like 3 to 6 servers.

1

u/vxab Oct 22 '20

Isn't the change in model for programming confusing?

1

u/[deleted] Oct 24 '20

For a while, took our team about a month or two to ramp up. But saving 6 figures a year on AWS costs was worth it.

1

u/vxab Oct 24 '20

Do you think you be able to save the same amount if you used loom instead (if it were available)?

1

u/9numbernine9 Oct 22 '20

It's perhaps not glamourous, but I'm a big fan of EqualsVerifier.

  • It requires a lot less code that writing an effective test case using Guava's EqualsTester.

  • It's great for helping ensure that the values returned from my equals methods don't change in unexpected ways.

  • It gives me some more confidence that heavily refactoring a class won't break the equals method.

Also, the developer seems really responsive to issues and the project seems well-maintained. Highly recommended!

1

u/[deleted] Oct 22 '20

You just started a civil war without realizing it 😂

1

u/K3dare Oct 25 '20

https://openwebstart.com/ - Because Java Web Start was not a bad idea

1

u/vips7L Oct 25 '20

https://ebean.io

Ebeans a different take on a Java ORM.

1

u/D10S_1 Oct 26 '20

Has anyone had issues with Lombok on large scale projects? If not then I'll highly recommend Lombok for annotation based getters/setters/constructor

1

u/aviral1701 Nov 03 '20

Why no lombok here?

1

u/OzoneGrif Oct 21 '20

Guice for the Inversion of Control - https://github.com/google/guice

It's way lighter and faster than Spring Core, and less verbose.

18

u/cogman10 Oct 21 '20

Dagger 2, even lighter and faster than Guice and it blows up on you at compile time when you make a mistake.

2

u/rbygrave Oct 22 '20

And https://avaje.io/inject for a more server side Dagger2 style DI with lifecycle support and spring like features

1

u/vips7L Oct 25 '20

Or weld if you want to use the standard:

https://weld.cdi-spec.org/

1

u/jongraf Oct 21 '20

SPQR for domain-first GraphQL schema generation

1

u/dagguh2 Oct 21 '20

jsonp - JSON as code. No reflection, high performance, full programmatic power.

1

u/mcobery Oct 22 '20

https://micronaut.io/ Great framework for building compile time dependency injection applications in many different formats like stand alone MVC application to AWS Lambdas. Micronaut also has great integration with GraalVM (https://www.graalvm.org/) which is another great library.

1

u/mirkoteran Oct 22 '20

Just 2 that I haven't seen here.

-1

u/simas_ch Oct 22 '20

If you didn't miss it why should you use it? Libraries should used to replace homegrown infrastructure code.

0

u/vokiel Oct 21 '20

Guice, Guava, EasyMock, RestEasy (jax-rs impl), Redisson are all good examples that can be used without killing your product on a framework choke hold.

Wiremock as a standalone service is amazingly useful.

Protobuf needs to be mentioned as it's a lot quicker than parsing xml or json for messaging.

Feign for making quick Rest client libs is as great if not better than Retrofit.

2

u/ge0ffrey Oct 29 '20

Guava introduces backwards incompatible changes regularly (every 18 months or so). If 2 dependencies use Guava and the version is 2 years apart, those dependencies might not be able to work properly on the same classpath, due to NoSuchMethodError, etc.

We've deliberately dropped the Guava dependency because our users were reporting such troubles.