Learn Java Tutorial for Beginners, Part 21: toString() and the Object class

///Learn Java Tutorial for Beginners, Part 21: toString() and the Object class

Learn Java Tutorial for Beginners, Part 21: toString() and the Object class

FavoriteLoadingAdd to favorites

Get complete courses at
This is a tutorial on the important toString() method in Java, which allows you to create a text representation of your object. Highly useful for debugging and much used in the Swing framework for example.

source

Java468x60
By |2019-11-15T23:55:41+00:00November 15th, 2019|Java Video Tutorials|37 Comments

37 Comments

  1. And Rew November 15, 2019 at 11:55 pm - Reply

    🙁 I liked Bob the frog…

  2. Lukasz Ziegler November 15, 2019 at 11:55 pm - Reply

    Why when we call frog1 it automatocally returns our toString method?

  3. JP CF November 15, 2019 at 11:55 pm - Reply

    you have the smoothest voice, it remembers me of Daniel Day Lewis! btw, the tutorial was very clear and usefull, keep going 🙂

  4. uxzh November 15, 2019 at 11:55 pm - Reply

    Watched many tutorials on how to understand this toString method best. This one helped me a lot. I like how simple it is and you don't start adding random things within the string

  5. HallivanGalli ( ͡° ͜ʖ ͡°) November 15, 2019 at 11:55 pm - Reply

    Well explained…Thx.

  6. Ein Hacker-Typ November 15, 2019 at 11:55 pm - Reply

    Really comfortable to watch this! You earned yourself a subscriber!!

  7. Özil vision November 15, 2019 at 11:55 pm - Reply

    So this would be good practice for identifying non-syntax errors, just logical errors?

  8. Nethertar November 15, 2019 at 11:55 pm - Reply

    Freddie and Roger. I bet this guy loves Queen.

  9. Arun Chaudhary November 15, 2019 at 11:55 pm - Reply

    These tutorial are really great !! Good Work John

  10. Heat4Life November 15, 2019 at 11:55 pm - Reply

    By the way, Is it nessesary to put Sysout(frog1.toString()) or I don't need to put toString() in there? Thanks 😀 I'm loving this tutorials!!!

  11. Heat4Life November 15, 2019 at 11:55 pm - Reply

    Oh man! I'm Excited for the next Tutorial after I master this a little bit!

  12. Dave Joseph November 15, 2019 at 11:55 pm - Reply

    What if Frog was declared as private?

  13. Locationary November 15, 2019 at 11:55 pm - Reply

    HAHAHAHA that dry humor when you say freddy the frog. made me laugh heaps

  14. Chengqing Xu November 15, 2019 at 11:55 pm - Reply

    Thank you very much!!!

  15. Neur0s1s November 15, 2019 at 11:55 pm - Reply

    this one's got decent audio

  16. James Whyte November 15, 2019 at 11:55 pm - Reply

    So we are allowed to just created a new class without explicitly creating it with that button in Java? like how you created Frog class outside of the App class?

    Also, when you ran that print method with (frog1), when that runs does it just automatically go through the Frog class line by line and because there was a toString() method there it just went ahead and printed what was returned in that method?

  17. Verena Kasselhuber November 15, 2019 at 11:55 pm - Reply

    ninice dude youre voice sonds awsome pls never stop talking im gettin aroused MD

  18. The gamer November 15, 2019 at 11:55 pm - Reply

    King of caves

  19. The gamer November 15, 2019 at 11:55 pm - Reply

    puplic string ..how it returns int id?

  20. sargon marqos November 15, 2019 at 11:55 pm - Reply

    mad me sleeping man

  21. Adolfo Fragoso November 15, 2019 at 11:55 pm - Reply

    Nice tutorials dude, your voice is so peaceful 🙂

  22. Duncan Whyte November 15, 2019 at 11:55 pm - Reply

    100th Liker

  23. blissB2 November 15, 2019 at 11:55 pm - Reply

    Thanks ! Pleasure listening to your tuts.

  24. Guillermo Rendon November 15, 2019 at 11:55 pm - Reply

    I also see that the toString() method works only with the constructor. 

  25. Guillermo Rendon November 15, 2019 at 11:55 pm - Reply

    I noticed you can only have one toString() method per class. Thanks COP. Your tuts are always enlightening! 

  26. Phallus Eseis November 15, 2019 at 11:55 pm - Reply

    cheers mate…was really useful 🙂

  27. Zachary Prinzbach November 15, 2019 at 11:55 pm - Reply

    Your voice is beautiful.

  28. Cave of Programming November 15, 2019 at 11:55 pm - Reply

    I wouldn't like to draw any conclusions about speed. Both are fast. But yes, no format options with StringBuilder, but StringBuilder is designed for concatenating as many strings as you want. With format() you have to know how many strings, ints, doubles, etc, you want to put in your formatted output, but it will format them very flexibly.

  29. skazis87 November 15, 2019 at 11:55 pm - Reply

    So in a case of many strings placed together StringBuilder must be faster, but it doesn't provide format options?

  30. Cave of Programming November 15, 2019 at 11:55 pm - Reply

    It has a different purpose; StringBuilder is only for concatenating strings, while format() can format numbers in strings to a certain number of decimal places, along with lots of other useful stuff.

  31. skazis87 November 15, 2019 at 11:55 pm - Reply

    So String.format() method is as efficient as StringBuilder class? Or was it just an example to show again a way to format strings?

  32. bitiminicik November 15, 2019 at 11:55 pm - Reply

    For my version of eclipse it is enough to type syso + ctl spacebar to print that line but it only works in places where this command actually works. If you put it in the wrong place the shortcut won't work.

  33. Cave of Programming November 15, 2019 at 11:55 pm - Reply

    It breaks a lot … Try going to File -> Switch Workspace, and select an empty folder. For some reason that often seems to fix it.

  34. John Fyffe November 15, 2019 at 11:55 pm - Reply

    mail me at groundscore420 at facebook.com if u would, never check my gmail

  35. John Fyffe November 15, 2019 at 11:55 pm - Reply

    when u do the control space with sysout, for me it just says "no suggestions", i have to type System all the way out before it will suggest anything and then it still wont 2 out of three times, what do i do to fix this, i dont mind typing it out, but still

  36. Cave of Programming November 15, 2019 at 11:55 pm - Reply

    Cheers. Hopefully I'll make some more in the next few weeks.

  37. Wayne Marshall November 15, 2019 at 11:55 pm - Reply

    Another excellent tutorial thanks, are you likely to be making any more in the near future.

Leave A Comment

*