r/javahelp • • May 07 '20

Codeless Java Developers: what are the common data structures you usually use on production

To professional java dev here, what are the common data structure youve been using and which data structure you strongly suggest for beginners, like me, to study carefully

40 Upvotes

38 comments sorted by

View all comments

34

u/ObscureCulturalMeme May 07 '20 edited May 08 '20
  1. The built-in Collections framework goes a long, long way. Even when it comes time to roll a custom structure, basing it off one of those gets you a very solid start.

  2. I believe that a pair of Countdown Latch objects, properly applied, can solve all communication problems including peace in the Middle East.

  3. What I've found myself missing is not so much a data structure exactly, but the ability to return more than one thing from a function, the way (for example) Lua can. The way to do that in Java (and its parent languages) is to build an aggregate structure and return that "one" thing, but it's tedious no matter how you implement the aggregates. I'm looking forward to someday working with java 14 and its records, for this reason.

3

u/MrSquicky May 07 '20

I believe that a pair of Countdown Latch objects, properly applied, can solve all communication problems including peace in the Middle East.

I'd love to hear more about this. I'm using Spring's DeferredResult in what I think is a similar context. I'm aware of CountDownLatches, but I've never used them.

1

u/Yithar Intermediate Brewer May 08 '20 edited May 08 '20

I have used them in combination before. Hmm, thinking about it, maybe they're not so different.

I see DeferredResult a sort of like callbacks in Javascript with the event loop. Like frontend JS often involves fetching JSON or something.

I feel CountdownLatch is more of like you're waiting for a certain number of things to happen, like maybe you need to get 2 messages back before something that can happen. I can't go into too much detail I think, but basically I was waiting for 2 requests I sent over the messaging protocol, to respond back. And then the logic would execute to process the responses so the GraphQL server could respond to the request it originally received.

It seems to me as similar to race conditions and data races. You can have a race condition without a data race, for example.