Coding Fun Java Learn Java Tutorial for Beginners, Part 15: Getters and Return Values

Learn Java Tutorial for Beginners, Part 15: Getters and Return Values

More courses! Free C++ course:
Make a social network with Spring Boot:
Learn about MySQL and relational databases:
Java desktop programming:…

Tags: , , , , , , , , , , , , , , ,

41 thoughts on “Learn Java Tutorial for Beginners, Part 15: Getters and Return Values”

  1. jamaraquai says:

    I just wanted to say, that I've tried learning computer programming (both C++ and Java) from a number of other places (Khan Academy – useless, SoloLearn – usless, CodeAcademy – useless, text books – better than the online options, but still lacking), and your lessons are the best I've found by far. For the first time, I'm actually understanding the why's and how's behind the language, and seeing the concepts applied in real-time as they're explained makes such a huge difference! I cannot tell you how thankful I am to have stumbled across your tutorials, and I can't wait to jump into other programming languages, as well. Thank you again!

  2. Jakonate says:

    what is the difference between




  3. kosmox says:

    I can't believe how much of an animal is our brain ( we ). Like, yea sure, when we understand this programming it's totally easy for us and seems logical, but the point is, if it's so easy, than why don't we get it instantly?

    Our brains are logical machines right?

    No, our brain haves to create new connections to create the illusion of logic.. that's so sick. It's like our brain is a powerful VR module which allows us to perviece this world as we do. Even counting, 2+2, has be to learned. It's not obvious for someone who gets to know math for the first time. SICK!!!

  4. Thank you so much! You teach extremely well!

  5. Wolfferoni says:

    It took me a while to get this. I mean, watching and following along in a tutorial is one thing but trying to do it from scratch is another. That's when the real learning happens. I highly recommend people to make another class and try to replicate John's code but with a different class, objects, variables etc. and try not to look at his code, try to just do it yourself. I made a class called Animal instead and though it took some time to figure out, I completely understand now.

  6. Shar Love says:

    YOU ARE AMAZING!!! Thank you for your videos!!!

  7. I hope you are making loads of money with your tutorials. They are terrific.

  8. sad kid says:

    You make such a great vids mate. I wonder if you ever drink some warter 😀 ?
    Cheers from Poland <3

  9. You are the creator haha

  10. This is an awesome video series! I am really getting ahead in my computer science class. Thank you.

  11. so basically getter are just return methods,

  12. emerlander says:

    Dude you are so amazing! Thank you!

  13. Jinxas Kao says:

    Having problems with 'return'.

    class Asmenybe {
    String vardas;
    int metai;

    void susipazindinimas() {
    for (int i = 1; i <= 7; i++) {
    System.out.println("As esu " + vardas + "man yra" + metai + "( " + i + " )");


    void pasisveikinimas() {
    System.out.print("Zdrw ");

    void apskaiciavimasMetuIkiPensijos() {
    int metuLiko = 70 – metai;


    return metuLiko;

    public class App {

    public static void main(String[] args) {

    Asmenybe asmenybe1 = new Asmenybe();
    asmenybe1.vardas = "Tomas";
    asmenybe1.metai = 32;

    Asmenybe asmenybe2 = new Asmenybe();
    asmenybe2.vardas = "Billas";
    asmenybe2.metai = 35;

    System.out.println(asmenybe1.vardas + " " + asmenybe2.vardas);
    int metuLiko1 = asmenybe1.apskaiciavimasMetuIkiPensijos();
    System.out.println("Metai likusieji iki pensijos Tomui" + metuLiko1);
    // asmenybe2.susipazindinimas();



  14. Dom says:

    what's the difference when you tried to get the return value of age by the int getAge() and then store it to a variable 'age' to what I did which is simply storing person1.age to, say, int x = person1.age directly ?? THANKS !

  15. I am having problems with the Person class that was put on top of the App class . I am getting a duplicate error message.

  16. Yi Hao Xie says:

    what happens if I return the this keyword? how do I do it?

  17. difference between void and public void .

  18. Bob Smith says:

    Eureka! I finally understand "Getters!" (Nevermind the dozen or so books I have on Java……….!)

  19. how do you return three int values n,p,r at the end of a method to the main method.Please give me the syntax.Thanks.

  20. Bashir says:

    awesome I learned so much from this video

  21. AryJaey says:

    Hello John, I had a question. Why doing it the hard way with the int and return method when you can do what you did in the first place with just using void and person1.calculateYearsToRetirement();
    I mean what you did first is easier, isn't it?
    Thanks for the tutorials, they are very helpfull!

  22. Yuva Raj says:

    In getters method : You can simple have all the variables in string right .. why we need to two methods to print integers and Strings ?  Am a newbie, pardon me if this is silly.

    public String getInt()
    String integersValues;

    integersValues = "Ages is : "+age+" Height is :"+height + "Weight is : "+ weight ;
    //getter logic 
    //return age;
    return integersValues;

  23. Yuva Raj says:

    John,Thank you very much for your videos.

  24. Hello, and as many already wrote down here i just wanted to say a HUGE thank you for those tutorials, they are very very useful and easy to understand, THANKS A LOT!!!

  25. Man Loo says:

    thank you!your tutorial are awesome! 


  26. ghvy1122 says:

    Wow, had to watch this one a few times. LOL I finally got it. But sure takes a bit to get your head around. BTW – thanks again John for posting these vids. I'm also reading a beginner java book and the reading is fairly straightforward after watching your vids.

  27. Bhargav Raut says:

    Phenomenal videos! I'm making a lot of progress. Btw, whats the name of the classical piece at the beginning of each video? Really regal stuff!

  28. I noticed sometimes if I return a value inside an if statement, the compiler still asks me for a return statement. In which case I have resolved it by putting a second return value at the very end: "return null;" 

  29. Asymptote says:

    what's the point of returning and then creating another variable in main class and printing again? wouldn't the Void method will just do fine?

  30. ahmed hashad says:

    Impressive understandble Tutorials  You are Awesome Bro !

  31. Samuel kings says:

    you're a life saver bro

  32. I've been lazy about suggesting exercises 🙂 On the front page of my website, Cave of Programming, there's a Java test that actually contains practical exercises for absolute beginners. But really the best thing is just to think up some programs and try to write them. Like, try to create a text-based game.

  33. DebankaD says:

    hey can you please suggest some practise exercises for a java beginner like me ?

  34. ALaw says:

    You're teaching is so straight forward and easy to understand. Love it!

  35. noone mate says:

    You guys should use to insert your code.

  36. Ah OK. Try ctrl+shift+f too … it formats the code and makes it much easier to see which closing bracket should close which opening bracket …. They all need to be paired off.

  37. adam says:

    It doesn't quite show it for some reason on the code I pasted but I removed the 2 }} underneath the person class and now it kind of works but now I just need to get my head around the returns because it isn't quite working right, not fully understanding how the {} work doesn't help either. Thanks for the help though.

  38. Don't worry about it too much. Sometime Eclipse seems to complain about there being no main class even when there is one. Start a new project with ONLY a main class/method and click the green run button to check that it runs. Then add your code to it. I have the same problem all the time ….

  39. adam says:

    I havent written it all 1 lined like that thats becaue of youtube.. Its when I added the int tax it starts saying I have {} in wrong places and that theres no main class :S

  40. adam says:

    I felt like I was started to understand it then it saying i dont have a main class etc I really dont understand why these errors are cominUp

    class person {
    String name;
    int age;
    int income;

    int taxCal(){
    int tax= income +2;
    return tax;

    public class Eh {

    public static void main(String[] args) {

    person person1= new person(); "bob";
    person1.income= 100;



Leave a Reply to ghvy1122 Cancel reply

Your email address will not be published. Required fields are marked *