Annotations In Java Tutorial - How To Create And Use Your Own Custom Annotations

Sdílet
Vložit
  • čas přidán 15. 05. 2022
  • Create your own custom annotations in Java!
    Thanks to Mailgun for sponsoring this video! Head to mailgun.com/john to try Mailgun today.
    Complete Java course: codingwithjohn.thinkific.com/...
    Annotations are a really cool part of the Java language. Many developers know how to use annotations, but not so many know how simple it is to create their own custom annotations.
    In this video, we'll go over how to create 3 different types of custom annotations in Java, and how you can use those annotations to do cool things in your programs.
    If you're confused by creating annotations in Java, you're in the right place!
    Learn or improve your Java by watching it being coded live!
    Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletrial.com/johnclean...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Phone I use for recording:
    amzn.to/3HepYJu
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com/donate/?hosted...
    ☕Complete Java course:
    codingwithjohn.thinkific.com/...
    codingwithjohn.com

Komentáře • 308

  • @CodingWithJohn
    @CodingWithJohn  Před 2 lety +40

    Thanks to Mailgun for sponsoring this video! Head to mailgun.com/john to try Mailgun today.
    As a few commenters have mentioned, I forgot to note that you can also use enums as an annotation parameter.
    Let me know if you guys have other questions about annotations!

    • @TakeshySun
      @TakeshySun Před 2 lety +2

      Streams and Optional :) And thank you :)

    • @shlack
      @shlack Před 2 lety +1

      I was wondering, can we actually make annotations like in python where you would annotate a method so that something runs before and/or after the method has ran ?

    • @TakeshySun
      @TakeshySun Před 2 lety

      @@shlack Did you ask for junit ? If not just read about listeners in java, it could help you

    • @TakeshySun
      @TakeshySun Před 2 lety

      @Henryk Zschuppan config reader, good point for tutorial.

    • @hzlcrpz887
      @hzlcrpz887 Před 2 lety

      Hi John, thank you for your videos, I'm not a programmer, I'm just an enthusiast and I want you to know what your videos are really helpful and worth watching.

  • @xslicer5779
    @xslicer5779 Před 2 lety +250

    Would be nice to see a part 2 where you have a preprocessor for the annotation so you won't have to write logic for a specific objcet to process the annotation, but instead to be processed where you apply it.

    • @leetaeryeo5269
      @leetaeryeo5269 Před 2 lety +37

      I was just gonna come here to suggest that. It would be cool to see something like an annotation for a field that generates getters/setters (I know this isn’t something you’d actually build, but just an example) or maybe a method timer that logs how long a decorated method takes to execute. Basically, it’d be nice to see an example that shows an executable use, in addition to the flagging and data storing usage.

    • @ralfiasz
      @ralfiasz Před 2 lety +2

      Man I second that! That would be great to learn!

    • @fenigrini
      @fenigrini Před 2 lety +3

      I think a good idea, is to implement a anotaciones to prevent null on getter or setter

    • @szalaytamas3184
      @szalaytamas3184 Před 2 lety +6

      Yeah. This way it's just pointless.

    • @leetaeryeo5269
      @leetaeryeo5269 Před 2 lety +2

      @@szalaytamas3184 now, let’s not go that far. There is definitely a use to these style of annotations. An actor model driven architecture can use these sorts of annotations to find and track which sorts of things to observe, for example. And a testing framework can use these sorts of annotations to mark which methods to test.

  • @codewithenthronekingsley
    @codewithenthronekingsley Před měsícem +2

    Dear John, you are something else. All your tutorials are just great. Very well simplified, straight to the point, very educative and really impactful. I have learnt a lot from you. Infact, I always read a minimum of 10 articles on the internet about a particular topic am learning at any time, watch 10 CZcams tutorials on that topic from different tutors. I always use your tutorial to drive that concept deep in my spirit. Each time I watch your tutorial, I get a signal from my spirit saying "Enthrone" you have successfully sink this in. Keep it up man. A big fan from Nigeria West Africa.

  • @Pierre-wl9gf
    @Pierre-wl9gf Před 2 lety +73

    I love the way you explain in your videos. It is always clear and understandable. Most of all I always learn something. Thank you man. Greetings from France.

    • @doud7072
      @doud7072 Před rokem +2

      Ouais on a pas des tutos comme ça nous...

  • @sadeepaalwis5938
    @sadeepaalwis5938 Před 2 lety +15

    i always struggled with annotation when creating my custom ones without understanding it completely thank you very much john for this awesome explanation.

  • @atomiccoding
    @atomiccoding Před 2 lety +18

    Although I have been working as a Java Software developer for more than a year, I learn something new from your videos all the time. Thanks for the tutorials. I wish I had such a Team Lead as you or worked in your team.

  • @ragore7947
    @ragore7947 Před 2 lety +2

    Hey John, thanks for all [public static final] videos. Please continue doing the good work.

  • @fc6827
    @fc6827 Před rokem +2

    Thank you so much for this. I was especially surprised at how much reflection was required for processing!

  • @flexerfadrigalan
    @flexerfadrigalan Před 6 měsíci

    John! You have amazing presentations and I am all for it. I went to subscribe right away, only to figure out I already am! Thank you for pumping out these videos. They are so helpful!

  • @misaelpereira9679
    @misaelpereira9679 Před 2 lety +62

    Java is a beatifull language❤️

  • @barbosabass
    @barbosabass Před rokem

    Even when I watch a video that I already know about, I can learn something new.
    Thank you John!

  • @girirajtomar519
    @girirajtomar519 Před 11 měsíci

    The way you teach any concept is just amazing.

  • @elcaballopapi
    @elcaballopapi Před rokem

    Finally someone who explains this in a clear way. Thank you John

  • @CodecrafterArtemis
    @CodecrafterArtemis Před rokem

    Thank you for explaining custom annotations in such a straightforward way.

  • @GhostlyDream
    @GhostlyDream Před rokem

    I have been reading books and some articles on internet all day, and just watched this video... In 20 minutes I've understood much more then in the whole day
    Thank you very much!🙏

  • @Felipe-yr5gm
    @Felipe-yr5gm Před 2 lety +3

    John, I need to say... Your videos are freaking awesome! Excellent explanation.
    Could you bring more content about collections and how they work in deep, please?

  • @maheshrphulse
    @maheshrphulse Před 2 lety +4

    Hi! John, I love the way you teach difficult topics with a hint of fun and humour, and that makes your videos effortless to understand. Could you please make your next video on regular expressions?

  • @muhammedahmed3386
    @muhammedahmed3386 Před rokem

    The best explanation I have seen covering Java annotations thank you

  • @user-qg1qg2vi4c
    @user-qg1qg2vi4c Před rokem +3

    Awesome! I didn't even know that you can handle object methods and object variables this way! Thank you so much!

  • @AnatolyLeonov
    @AnatolyLeonov Před 11 měsíci

    Nice and simple explanation. Thanks!

  • @andtif
    @andtif Před 9 měsíci

    John you're an absolute LEGEND for the way you explain complex things in a simple way. Please continue being you and do what you're doing. Would love to see some more advanced Java topics as others has mentioned with annotations and reflection! What you've described in this video is also, what I assume, closely related to Aspect Oriented Programming or IS in all practical sense, AOT?

  • @simonrozendal7542
    @simonrozendal7542 Před 2 lety +1

    Thank you very much John! I like to develop in Java very much. But today i learned something new. I like learning on a practical way very much, keep on the good work. Because there are not enough people where we can learn good things like this. I'm now a fan of your work.

  • @Speiger
    @Speiger Před 2 lety +6

    I actually have a interesting case for Annotation.
    I am writing a pretty big mod that is synchronizing fields automatically through networking.
    So you just have to request the field name to be synchronized.
    What you have to do is add the "@NetworkField" Annotation to the Field and it will be automatically mapped to the networking manager.
    Which allows me to compress information down to 1 byte instead of having to write down the fields name, since they are automatically mapped I just write down the Index it was mapped to and send the data over with the index to then use that info to gather the index automatically.
    Another usecase is for plugins where a Annotation is the Indicator where a class might be a plugin. Which allows you to make modding support super easy for you or other people.

  • @libertymedicalcommunicatio4908

    Good stuff. Congratulations on the sponsorship

  • @cjamith
    @cjamith Před 2 lety

    Thanks John. It was short yet comprehensive.

  • @abdullohmaraimov2022
    @abdullohmaraimov2022 Před 6 měsíci

    The best explanation ever. Thanks

  • @mohammadobeidat5685
    @mohammadobeidat5685 Před 10 měsíci

    You're legend in explaining things, many thanks man.

  • @saadmansakib6612
    @saadmansakib6612 Před 6 měsíci

    Excellent video John!

  • @Devivl
    @Devivl Před rokem

    Thank you, John! Your videos are very helpful.

  • @elvenpath7
    @elvenpath7 Před rokem +1

    Nice.. very clear explanation. Thanks !

  • @satyasarma2458
    @satyasarma2458 Před rokem +1

    Wow.! its crystal clear explanation..!

  • @Teddy0611
    @Teddy0611 Před rokem

    Hi John ! Thanks for all your videos. Your explanations are very precise, crystal clear and whenever I have a question, you answer it a few seconds later. Thanks a lot !
    I was looking for a video on java Streams which is a totally new subject for me. Your explanations on this would be really helpful. Thanks again for your work !

  • @PavelBader
    @PavelBader Před 2 lety

    Thanks a lot, John! Very useful tutorial.

  • @suwatchainanchai6637
    @suwatchainanchai6637 Před 9 měsíci

    here again thanks alot for clarifying thing in the simplest term with an example. when using annotation alot in work. It really fascinating how the background thinggy work. Best Basic Java instructor in YT.

  • @nightscrape3670
    @nightscrape3670 Před 2 lety

    Every video i watched from your channel has been easy to follow along and understandable. Is there going to be Spring tutorials in the future? Keep up the amazing work!!

  • @shoaibhasan5620
    @shoaibhasan5620 Před 2 lety +21

    Please john make a spring boot series. I really like the way you tech. I will love to learn spring boot from you. Specifically if you make a monolithic application from the scratch then move to microservices part. We the followers of yours looking forward to it. So much love and respect for you.

  • @nikosdapergolas9430
    @nikosdapergolas9430 Před 2 lety +1

    Great video man! I would love to see a tutorial on reflection one day!! It seems very interesting

  • @rodNantz
    @rodNantz Před rokem

    This video is about a not-so-trivial subject and still is so clear that it seems easy ✌ so great

  •  Před 2 lety

    Thank you, John!

  • @innocentomoyibo6312
    @innocentomoyibo6312 Před rokem

    Thank you so much for this video honestly!!

  • @aminesafi7261
    @aminesafi7261 Před 2 lety

    Excellent video about implementing a custom annotation, great content, keep going!

  • @francksgenlecroyant
    @francksgenlecroyant Před 2 lety

    Thanks John, it's helpful

  • @maiscarlos
    @maiscarlos Před rokem

    Awesome as always! Thanks for sharing!

  • @shankar7435
    @shankar7435 Před rokem

    Thanks for such a quality explanation of Annotations.

  • @rewrose2838
    @rewrose2838 Před rokem +1

    Man am I glad I found your channel, I was going crazy tying to learn Java from other videos. (I was actually about to give up and switch to Js lol)

  • @helk00
    @helk00 Před 2 lety +1

    Thanks John! Would love to see a lesson on regular expressions (patterns)

  • @vaclavvlcek4527
    @vaclavvlcek4527 Před 2 lety

    Hi John, this is a great tutorial, thank you for that!

  • @annarozou4821
    @annarozou4821 Před 2 lety +1

    Thanks, John! Would love to see a lesson on Stream API for processing collections of objects.

  • @annagre4804
    @annagre4804 Před rokem

    awesome as always, your presention is so nice, thanks for sharing!

  • @superman5810
    @superman5810 Před 2 lety

    Hands down the best Java guru here on CZcams!! 👌

  • @yfidalv
    @yfidalv Před 2 lety +4

    Been really enjoying the videos! Could you please do a video on the “static” keyword? :)

  • @indel0425
    @indel0425 Před 2 lety +9

    Great video!
    Can you do separate video on getClass and Reflection?
    Also, can you do series on dependency injection.

  • @DarKodama
    @DarKodama Před 9 měsíci

    Thank you very much for this explanation!

  • @TheWalace10
    @TheWalace10 Před 5 měsíci

    Thank you for this!!

  • @chtulurr
    @chtulurr Před rokem

    The moment I made the code work, you also showed Stella on the screen and it was the best payoff I have ever had aaw. Thanks for the videos, they have been great help for me for an interview preparation. Very clear explanations and examples.

  • @hunelysium
    @hunelysium Před 2 lety

    Hello John
    Thank you for making this great video!!
    I always enjoyed your video, and learnt a lot from them.
    I watched this video, and not sure if this knowledge point is supposed to be pretty complicated, didn’t fully grasp like I did with all of your previous videos.
    I guess this annotation is supposed to be kind of hard!
    Thank you for sharing your knowledge with us!! :-)

  • @MikairuEichdy
    @MikairuEichdy Před 2 lety

    Thanx! Great and simple tutorial

  • @huseyinkadioglu
    @huseyinkadioglu Před 2 lety

    Great video and you explain the consepts very well! Now, you have one more subscriber. Greetings from Turkey!

  • @hamdamboy4398
    @hamdamboy4398 Před 11 měsíci

    Nice explanation John.

  • @siavashnourmohammadi9189
    @siavashnourmohammadi9189 Před 7 měsíci

    thank you alot dear John

  • @prashantbalotra
    @prashantbalotra Před 2 lety

    Amazing, Nice and easy explanation!

  • @__-zv4qn
    @__-zv4qn Před rokem

    Thank you so much! Finally i figured it out...

  • @ornitcohengindi90
    @ornitcohengindi90 Před 3 měsíci

    thank you for this great explaination

  • @EzequielCREY
    @EzequielCREY Před rokem

    Thanks a lot for your explanation :=) I'm practicing right now

  • @AmitCodes
    @AmitCodes Před 2 měsíci

    mast explain kiya John bhai

  • @wayneinteressierts9973

    Hey John! As always, very nice video. I always enjoy to watch your videos. Thanks for each and every one of them.
    In general, even if only briefly, could you talk about what books you would recommend, especially for beginners, on one subject or another. I know it is very individual. I would still be happy about your recommendation. I’m a beguines to programming and totally a fan of your way of explaining things. Thanks again for all your work.

  • @shiz4849
    @shiz4849 Před 2 lety +1

    I need a complete regular expressions tutorial to create "IP filters". The way you teach us is amazing

    • @CodingWithJohn
      @CodingWithJohn  Před 2 lety +4

      Not sure when exactly I'll be able to get to it, but it's on the list!

  • @Uminental
    @Uminental Před 2 lety

    This is so cool! Thanks.

  • @it029-shreyagandhi5
    @it029-shreyagandhi5 Před 10 měsíci

    Thank you so much :)
    you are a saviour !!!

  • @powertester5596
    @powertester5596 Před rokem

    Your videos are gold! You are a very gifted teacher :-).

  • @qingchen191
    @qingchen191 Před 8 měsíci

    It's very clarify, thanks very much.

  • @thevicraft_
    @thevicraft_ Před 8 měsíci

    Very nice tutorial!

  • @nathanwang9363
    @nathanwang9363 Před 2 lety

    what a great video! i think i've learned a lot from it!

  • @codex8797
    @codex8797 Před 5 měsíci

    Thanks bro, really helped

  • @prathapdudvat8635
    @prathapdudvat8635 Před rokem

    So Simple , Crisp and Clear Explanation - with extra flavour of where to use it and where not to use. thank you very much

    • @pranavnyavanandi9710
      @pranavnyavanandi9710 Před rokem

      I'm just amazed about how much more there is to learn and then apply it.

  • @abdelkaderkaouane1944
    @abdelkaderkaouane1944 Před 2 lety

    It is a pleasure to watch your videos

  • @aminmotiwala5141
    @aminmotiwala5141 Před 2 lety

    loved this :) really helpful sir

  • @johnkeck
    @johnkeck Před 2 lety

    Very good, John: thanks!

  • @mahoneg
    @mahoneg Před 2 lety

    John - I know it is said a lot in here but I love your explanations. Even if I know the topic it is still great to watch

  • @erwin5126
    @erwin5126 Před 2 lety

    Thanks for the video

  • @labochi90
    @labochi90 Před 2 lety +1

    Never leave me john.

  • @alessioantinoro5713
    @alessioantinoro5713 Před 2 lety +1

    It would be awesome if you did a video about annotation processors! There are not much tutorial online, and the one there are mostly use external libraries

  • @quadrarilific
    @quadrarilific Před 2 lety

    I really enjoy your videos!!! I learn something new everyday with your videos all the time :) Also can I request on how to do method referencing? I really confuses and there's not good tutorials on youtube. Thanks!!!

  • @svalyavasvalyava9867
    @svalyavasvalyava9867 Před 2 lety

    awesome content, thank you so much!

  • @gurudatt-shahane
    @gurudatt-shahane Před rokem

    Thank you for making this video. Your content is really provides a great value for those who are not privileged to afford high pricey courses and even they will not teach you this way. Love from my heart for your dedication ❤️❤️

  • @rebeccamonroy444
    @rebeccamonroy444 Před 2 lety

    Very helpful video!!

  • @user-ry8ff3ky4d
    @user-ry8ff3ky4d Před 9 měsíci

    Hi John, Loved the way you teach. Please add a Java full stack or Spring boot series as well

  • @jannickvieluf
    @jannickvieluf Před 2 lety

    Hey,
    thank you for this video. I was always interested in annotations but never had the motivation to look at them.
    I also would like to have a video about the Factory Design Pattern.

  • @matimozg
    @matimozg Před rokem

    I don't knew this syntatic sugar after instanceof, thanks!

  • @theaftermath98
    @theaftermath98 Před rokem +1

    best teacher for beginners and advanced.......even better than mosh

  • @takony1994
    @takony1994 Před 2 lety +1

    Stella is such a beautiful cat

  • @svddwd
    @svddwd Před 2 lety

    Nicely explained.

  • @anantharamu80
    @anantharamu80 Před 2 lety

    Excellent thanks a lot

  • @ganeshbodduaddasuryanitinb7811

    Excepting part 2 with real time example scenarios. 😊

  • @GustavoMimesse
    @GustavoMimesse Před měsícem

    Thanks.
    You´re the best

  • @harshitkrvishwakarma3602
    @harshitkrvishwakarma3602 Před 2 měsíci

    Awesome content on java.

  • @marwanebenhaddou8658
    @marwanebenhaddou8658 Před rokem

    Thank you so much

  • @pradeep1198
    @pradeep1198 Před 2 lety +1

    you are awesome ❤️
    Best teacher 😘
    I like your teaching very much ❤️❤️❤️❤️❤️❤️❤️❤️

  • @xugefu
    @xugefu Před rokem

    Thanks!

  • @gabrielp8660
    @gabrielp8660 Před rokem

    Many thanks.