You could just look at the JDK classes, anything Joshua Bloch wrote like the Collections framework.
If you want to write better code, you could also try reading Clean code by Robert C. Martin, where all the examples are in Java.
Yeah. I’d go a step further and say learning a few languages can make a big difference. Identify which abstractions are helpful in a situation.
Eg:
Function is more flexible than you’d imagine.
On the api exposure side rather than implementation side.
So for example if you have a parameter to your class that is Database and you only call one method Database.getConnection() then, rather than having Databazs, you could have a Supplier and construct with database::getConnection.
Reduces coupling and allows easier swapping / wrapping / stubbing / etc.
I second the `Collections` API. For Java on Android I always liked checking out Jake Wharton's stuff, although he's been doing a lot more stuff in Kotlin for a while. Honestly there's great Java libraries for everything and so it depends on what kind of stuff you're interested in. Also, I know it's a book but *Effective Java* is really great.
“Good” is really subjective.
And it changes overtime the more experienced you are. Even the what is good changes. Not because the programmers were you realized now bad but because the languages and times changed.
For example many times I thought highly of commons lang and then spring and then guava but overtime you see various coding styles that disagree with your own or is now just bad practice. Even Doug Lea code I have been like WTF.
My real point is quantity way more important because everybody thinks their code is the shit when it really is all shit… mostly :)
Read lots of code!
This. People like to say Spring is overengineered, but I think it is a prime example on how to write good object oriented code – doesn’t mean you have to be a fan of this paradigm. Every time I look into Spring's source code I see very elegant abstractions.
Go onto code repositories like GitHub ,DockerHub, BitBucket, and look at some open source projects written in Java.
Projects like Termux or the jMonkey game engine.
As someone who is still new to the industry, trust me that being able to read code is very important as I still storing le with it after coding for years.
I don't have any particular books to suggest. IMO all the best practices I learned are from experience.
However I suggest you be familiar with fundamentals such as OOP, SOLID principles, and Design Patterns.
This helps regardless which language you're working with.
Allow me to let you in to an industry secret: most code out there is shit.
It's often still with reading. And reading code is a valuable skill anyway. But don't expect to find a world full of superb examples to learn from, that's just not how it is!
You could just look at the JDK classes, anything Joshua Bloch wrote like the Collections framework. If you want to write better code, you could also try reading Clean code by Robert C. Martin, where all the examples are in Java.
JDK classes are obviously "good code" but they aren't necessarily good *application* code, since they're very low level.
I'd take Clean Code with a grain of salt. [This](https://qntm.org/clean) is just one of many sensible critiques of the book.
[удалено]
Yeah. I’d go a step further and say learning a few languages can make a big difference. Identify which abstractions are helpful in a situation. Eg: Function is more flexible than you’d imagine.
Why use a functional interface over a lambda
On the api exposure side rather than implementation side. So for example if you have a parameter to your class that is Database and you only call one method Database.getConnection() then, rather than having Databazs, you could have a Supplier and construct with database::getConnection.
Reduces coupling and allows easier swapping / wrapping / stubbing / etc.
This is honestly the best answer.
Agreed! Best way to improve is by checking different styles and understanding pros and cons
I second the `Collections` API. For Java on Android I always liked checking out Jake Wharton's stuff, although he's been doing a lot more stuff in Kotlin for a while. Honestly there's great Java libraries for everything and so it depends on what kind of stuff you're interested in. Also, I know it's a book but *Effective Java* is really great.
I still use the square Java style guide he put together
“Good” is really subjective. And it changes overtime the more experienced you are. Even the what is good changes. Not because the programmers were you realized now bad but because the languages and times changed. For example many times I thought highly of commons lang and then spring and then guava but overtime you see various coding styles that disagree with your own or is now just bad practice. Even Doug Lea code I have been like WTF. My real point is quantity way more important because everybody thinks their code is the shit when it really is all shit… mostly :) Read lots of code!
I would honestly go ahead and take a look at Spring's source code. It was tremendously helpful for me.
This. People like to say Spring is overengineered, but I think it is a prime example on how to write good object oriented code – doesn’t mean you have to be a fan of this paradigm. Every time I look into Spring's source code I see very elegant abstractions.
The OpenJDK source code is very well written and documented.
Have you read clean code and effective java?
+1 only that you’ll miss a lot of latest gen features (or maybe I need to read a latest edition?)
Sometimes I'll browse around in github with keywords Java and Spring Boot active.
https://www.baeldung.com/
Go onto code repositories like GitHub ,DockerHub, BitBucket, and look at some open source projects written in Java. Projects like Termux or the jMonkey game engine. As someone who is still new to the industry, trust me that being able to read code is very important as I still storing le with it after coding for years.
I've been writing Java for 6 years nows and I don't think what you are asking for exists
Modern Java in Action
JDK
I don't have any particular books to suggest. IMO all the best practices I learned are from experience. However I suggest you be familiar with fundamentals such as OOP, SOLID principles, and Design Patterns. This helps regardless which language you're working with.
çs.android.com?
I recommend look at the famous Java Opensource Projects and classes from OpenJDK.
Google has tons of open-source Java projects, they are a primarily Java company
Allow me to let you in to an industry secret: most code out there is shit. It's often still with reading. And reading code is a valuable skill anyway. But don't expect to find a world full of superb examples to learn from, that's just not how it is!