Java Reflection Tutorial

Java Reflection Tutorial

FavoriteLoadingAdd to favorites

Java Reflection Cheat Sheet:

Java468x60

Welcome to my Java Reflection Video Tutorial! I’ve been asked many times to cover Java Reflection lately and in this tutorial I’ll show you pretty much everything you can do with Java Refelection.

Many people are confused by reflection because they think it is a concept or technique. Java Reflection is an API and as soon as you know that it becomes easy. The Java Reflection API is used to manipulate classes and everything in a class including fields, methods, constructors, private data, etc. And, in this tutorial you’ll learn it all!

source

By |2019-06-13T19:36:29+00:00June 13th, 2019|Java Video Tutorials|33 Comments

33 Comments

  1. Nikolay Shaydulin June 13, 2019 at 7:36 pm - Reply

    What's the point catching IllegalArgumentException? It is unchecked

  2. Ameya Patil June 13, 2019 at 7:36 pm - Reply

    great video

  3. Nino Nazghaidze June 13, 2019 at 7:36 pm - Reply

    Hello

  4. Arya Pourtabatabaie June 13, 2019 at 7:36 pm - Reply

    Great material, good voice. You should use a better microphone though :p

  5. IMTHEVERYBEST June 13, 2019 at 7:36 pm - Reply

    It was amazing, keep a good job:3 Just need to find out how to create a class dynamically in run time now whit reflection.

  6. Smile&Relax June 13, 2019 at 7:36 pm - Reply

    why thise motherfuckers signers have alwyas millions subscribers why not this channel, this man deserves at least 10 milllions subscribers

  7. Humberto Fioravante Ferro June 13, 2019 at 7:36 pm - Reply

    It is a gorgeous tutorial. Thank you so much, Derek!

  8. akainsane June 13, 2019 at 7:36 pm - Reply

    When I hear that voice, it reminds me of Ed Helms 😛

  9. David COX June 13, 2019 at 7:36 pm - Reply

    Perfect! thanks!

  10. Amaravati June 13, 2019 at 7:36 pm - Reply

    Great video, can I pass the class name as string , search through my package and return that class object if it is present? and then proceed with rest of your tutorial to get methods and constructors?

  11. Grant Wilson June 13, 2019 at 7:36 pm - Reply

    Great video. Easy to follow

  12. Sriram R June 13, 2019 at 7:36 pm - Reply

    How does int.class work? Isn't Integer the class for int types?

  13. your mom June 13, 2019 at 7:36 pm - Reply

    What's the point of getting a field's value by passing its (string) name instead of just calling the getter for it? Example on 20:30.

    What use case would suggest using this technique?

  14. Ketan Makavana June 13, 2019 at 7:36 pm - Reply

    your video really clear my understanding for reflection, thanks

  15. Mo D Genesis June 13, 2019 at 7:36 pm - Reply

    How do I use reflection on a program that is running like a game or something?

  16. comradestan Okoye June 13, 2019 at 7:36 pm - Reply

    Loaded with easy to understand examples. Dissects reflection and lays it bare. Excellent tut on java reflection api.

  17. Nick Zakharov June 13, 2019 at 7:36 pm - Reply

    Dude you sound like Andy Bernard from The Office!!

  18. Navid Alipour June 13, 2019 at 7:36 pm - Reply

    thank you … you are amazing !

  19. Kiên Định June 13, 2019 at 7:36 pm - Reply
  20. wesos de queso June 13, 2019 at 7:36 pm - Reply

    I understood everything you said. I can't find a reason to use this API, other than somekind of Java editor. Is possible to create new methods in runtime? That would be insane for configuration files.

  21. Blake Bartenbach June 13, 2019 at 7:36 pm - Reply

    Holy try/catch blocks. Probably would have been easier to just add "throws Exception" onto main.

  22. Sh.C June 13, 2019 at 7:36 pm - Reply

    So clear! Thanks!

  23. ASI බ්‍රෝ June 13, 2019 at 7:36 pm - Reply

    Can you determine polymorphism factor solely through reflection

  24. ASI බ්‍රෝ June 13, 2019 at 7:36 pm - Reply

    Can you determine cyclomatic complexity solely through reflection? Why, or why
    not?

  25. Amit Shimon June 13, 2019 at 7:36 pm - Reply

    Your the man

  26. S RiSH June 13, 2019 at 7:36 pm - Reply

    @Derek Banas this design pattern seems to be too specific to Java, isn't it? please correct, if I am wrong (since, I would try out the concept in C++)..

  27. Sanket Korgaonkar June 13, 2019 at 7:36 pm - Reply

    Hi Derek, So I was experimenting with something recently – and I am unable to solve it. From your tutorial you show how we can invoke a method of our choosing dynamically with java reflection API. This is pretty cool. I am looking to dynamically provide code or compiled objects – so I not only want to dynamically choose what to execute but dictate what that method does on the fly. I am trying to write software knows the version numbers of all of its modules and tries to listen to a socket for new messages. The messages can contain modules as java object stored in byte arrays – if the software detects that the software module version on an in coming message is greater/ newer than the one its currently using, it replaces its existing module with the one just received.

    In other words you are able to do a software update/ change functionality without rebuilding and re-deploying the jar. Is this doable ?

  28. Elliptical Oblivion June 13, 2019 at 7:36 pm - Reply

    Love you Derek :p <3 , Thank youuu soo much

  29. Giorgos D June 13, 2019 at 7:36 pm - Reply

    Thanks for reflecting your knowledge to us Derek! 🙂

  30. Sushant Gaikwad June 13, 2019 at 7:36 pm - Reply

    best reflection tutorial ever! thank you

  31. Shubham Chaudhary June 13, 2019 at 7:36 pm - Reply

    very helpful tutorial

  32. maks burkov June 13, 2019 at 7:36 pm - Reply

    Good video! Can't find the the next tutorial video for Reflection in the real world scenario..

  33. Edward Ryklin June 13, 2019 at 7:36 pm - Reply

    Is it possible to get the name of a variable such as this:

    class EnemyShip{

    };

    main()
    {
    EnemyShip starBlaster;

    /// I want to now print out starBlaster because that's the name of the variable. But instead I get the name of the class which is EnemyShip.

    starBlaster.Class.getName() returns "EnemyShip" because that's the class's name, but I want it to return "startBlaster" because that's what I called the variable.
    }

Leave A Comment

*