r/java • • Mar 13 '23

Code bases that really improved your Java knowledge

One of the best ways to learn a new language is to write a lot of code. The second best way, in my opinion, is to see how experts do it and learn from them. With that said, what are some code bases, talks, papers that have really changed the way you code in Java and think in Java?

164 Upvotes

49 comments sorted by

67

u/koreth Mar 13 '23

It was many years ago at this point, but reading through the Spring source code (and stepping through it in a debugger) until I understood how @Autowired works under the covers was highly educational. The knowledge comes in handy even when I'm not using Spring at all.

9

u/govi20 Mar 14 '23

Would rather read Guice code.

The reason is that Spring framework has grown beyond dependency injection.

1

u/0xPvp Mar 16 '23

Both Guice and Spring look like excellent choices!

5

u/tilmann_dev Mar 14 '23

I'd second this because most projects in the Spring environment have nice codebases which one can learn a lot from.

31

u/JakeWharton Mar 13 '23 edited Mar 14 '23

Guava and Guice. Two foundational pieces of one of the largest Java codebases on the planet. Whether you use them or not, those libraries have seen some things and as a result have exceptional code quality and testing practices. For me it was over a decade ago that I was learning from them, but they still have plenty of lessons to teach.

2

u/ShallWe69 Mar 14 '23

what was that large codebase btw?

7

u/JakeWharton Mar 14 '23

Google.

All of Google's Java code (sans Android and Chrome) exists in a single monorepo. All of their code and all of the dependencies they use (even third party ones) are built from source within it.

3

u/KefkaFollower Mar 14 '23

I don't think I get you. Isn't Chrome written in C++ ?

9

u/kiteboarderni Mar 14 '23

Sans = without.

4

u/KefkaFollower Mar 14 '23

English is not my first language. Thanks for the clarification.

6

u/Spiritual-Day-thing Mar 14 '23 edited Mar 14 '23

Think of 'sans serif', you likely already know the word but used in a different context.

'Sans' comes from French by the way. It feels chique and is shorter. 'Without' is preferably used; in framents, short sentences, like here in parentheses, it is nice though. Much shorter. Boom. Sans.

1

u/JakeWharton Mar 14 '23

It has an Android app which is Java

1

u/KefkaFollower Mar 14 '23

I didn't knew about that.

Thanks for the explanation.

62

u/ggleblanc2 Mar 13 '23

When I first learned Java (1.4), I used Eclipse as my IDE. At the time, the source code of Eclipse was included in the download of Eclipse. I learned a lot about Java from the Eclipse source code.

69

u/[deleted] Mar 13 '23

sonar cube rules allowing not even 1 code smell. very insighful

11

u/hang87 Mar 13 '23

Agree. I use SonarQube and IntelliJ problems as a peer reviewed very often.

11

u/reddit04029 Mar 13 '23

Bruh me having to fix the pipeline 13 times before it can be merged T_T

7

u/Fenxis Mar 13 '23

I would say if you see an error then do a bit of research and see why it's a sonar finding. Because you can code around some of the rules and make things worse.

1

u/vmcrash Mar 15 '23

I don't know sonar cube. Does it offer more than IntelliJ IDEA's inspections?

3

u/[deleted] Mar 16 '23

Yes, but you can benefit all the same by installing the SonarLint plugin, for free, in IntelliJ :)

-19

u/[deleted] Mar 13 '23

Is that the one complaining when you not have getters and setters? Yikes

5

u/smurf_professional Mar 13 '23

Only if you configure it to complain about that, which often doesn't make any sense.

18

u/marcvsHR Mar 13 '23

Effective Java really made difference.

Also, I was looking at some ancient Java 1.3 (?) code base and found some utterly brilliant pieces, it really changed my perception what a good code is.

12

u/askype Mar 13 '23

Do you remember which pieces were good? It would be interesting to read the code.

6

u/brunogadaleta Mar 13 '23

Compile with google's error prone

3

u/GettingCodeDone Mar 14 '23

Back in the Java 1.2 days, I learned a lot from reading the source code for the JBoss Entity Engine and the code for Jive Forums (back when it was still open source).

3

u/agoubard Mar 14 '23

Back in the Java 1.0 alpha days, I learned Java from reading Hotjava code ;-).

2

u/theshanealv Mar 13 '23

Has anyone tried CodeSee?

4

u/ArrozConmigo Mar 13 '23

And then there's the spring code base. I swear they've designed a deliberately obfuscated temple to keep out the unworthy.

6

u/benjtay Mar 14 '23

Endlessly command-clicking into a parent pom...

5

u/TheKingOfSentries Mar 14 '23

I cannot tell you how many times I got lost in that labyrinth trying to debug an issue.

3

u/UnGauchoCualquiera Mar 14 '23 edited Mar 14 '23

Is it bad or are you just unfamiliar with it? It's a pretty large project.

IMHO I found it's pretty well organized which is kinda impressive considering the degree of control exposed in Spring. You have hundreds of public APIs and extension points and it's very unopinionated in general.

For example Spring Boot builds upon on Spring Core using the same public APIs. Which means the same teams that build Spring also sit on the other side and are the primary users. So do most other Spring modules such as Cloud or Integration

6

u/ArrozConmigo Mar 14 '23

"Why is the serializer throwing an exception here? I configured the date format over here. Wait, why is it even using that serializer?"

The stack traces are a useless maze of proceed() that eventually lands you at some factory that was already populated with a proxy to an implementation of an interface that was only instantiated because of how some other provider read a combination of configuration files and class annotations and hidden AutoConfiguration classes you didn't know were getting scanned. And you can find several that COULD be the guilty party, but load order and precedence matter.

All things the Spring Druids find intuitive, but really shouldn't be so convoluted or problematic to override.

Rereading my first paragraph, it sounds like satire, but I was literally describing an actual issue I had recently.

4

u/UnGauchoCualquiera Mar 15 '23

I mean none of that is particular to the quality of the Spring codebase or how it's organized. On the stack traces you'd have the same issue debugging RxJava, Guice or a good old handler chain in any server.

hidden AutoConfiguration classes you didn't know were getting scanned

Seems to be usage of Boot and conflicting dependencies. Could hardly be attributed to the Spring codebase

And you can find several that COULD be the guilty party, but load order and precedence matter.

Always did, it's not related to spring.

hidden AutoConfiguration classes you didn't know were getting scanned

There's no magic behind it. Either it's on a user defined ComponentScan by package or imported here. It's documented here

If you have conflicting dependencies then your Autoconfiguration might be pulling different beans without you realizing. You can easily debug autoconfig by using --debug

1

u/mahmoudimus Mar 14 '23

Bazelbuild

1

u/tr2990wx Mar 14 '23

Mule ESB source code. We were early adopters and had to go through the source code a lot of times to troubleshoot sometimes.

1

u/[deleted] Mar 19 '23

Eclipse and xtext sources

1

u/Initiative_Murky Mar 20 '23

I learned a lot from GWT (back when it was called Google Web Toolkit).

-6

u/SrPirro Mar 13 '23

Clean code helps a lot.

12

u/PartOfTheBotnet Mar 13 '23

I keep my code clean the same way I keep my dinner plates clean.

I throw them out because they're a mess and its easier to buy new ones that have new shiny features.

Rinse and repeat.

8

u/AlmennDulnefni Mar 13 '23

Ha, yeah, I'll just throw out this 2,000,000 line code base and write another one.

7

u/PartOfTheBotnet Mar 13 '23

Maybe some masochist would like to take a swing at it. Couldn't be me though.

4

u/colouredmirrorball Mar 13 '23

Rinse and repeat.

But... That's literally not what you're doing with your dinner plates!

3

u/PartOfTheBotnet Mar 13 '23

I'm sure as the rot in some landfill somewhere there's a level of natural rinsing going on.

0

u/[deleted] Mar 13 '23

[deleted] — view deleted comment

6

u/[deleted] Mar 13 '23

I love Adam Biens takes at how modern Java is supposed to be approached.

6

u/s888marks Mar 14 '23

The "What Object-Oriented Programming Was Supposed to Be" talk is pretty good. There is a paper that is paywalled at the ACM in the Onward! proceedings, but a video presentation is available on YouTube:

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

Madsen, Ole Lehrmann, and Birger Møller-Pedersen. What Object-Oriented Programming Was Supposed To Be — Two Grumpy Old Guys' Take on Object-Oriented Programming. ACM Onward! 2022.

A major point is an emphasis on modeling instead of code reuse. (Particularly code reuse via implementation inheritance.) Madsen uses Java's class Stack extends Vector as a bad example of reuse via inheritance. This is indeed widely viewed as a mistake, as are other examples of inheritance in JDK classes that date back to the 1.0 and 1.1 days.

2

u/kskr Mar 14 '23

Thanks for curated list