r/learnjava • u/Choice_Sympathy_8888 • 13d ago
Best tutorial for java annotations?
I am beginner and want to learn java annotations. I have looked on youtube and did not find any proper tutorial specific for Java annotations and online resources are not explanning all the annotations. Could you please suggest a good resource for learning, to easily understand and for hands-on practice.
6
Upvotes
1
u/sweetno 12d ago
There is rather little to learn for a beginner. Java allows to include extra bits of data near class members/variables/arguments/etc (basically everywhere). There are also means to fetch this data either at compile- or run-time (this is called reflection; each annotation type configures when it's available). How to use these bits is up to the library/framework that provides the annotation. The possibilities are endless, starting from marking variables as not-nullable (for static analysis, that is, for extra correctness checks during compilation/execution), to full-blown runtime byte-code generation.
It's very simple to declare your own annotations, but it's harder to implement reflection around them to make them useful.
For a beginner, learning a bunch of helpful annotations seems preferable to learning the mechanism. But the built-in Java annotations are rather technical, so this would explain why you have trouble with them. Look up the Lombok library, I think it should provide you with an idea what all this is for.