Javahackercoding 2: This time, it’s personal

This entry is part 2 of 8 in the series Java Class

Last night was a wash Java wise. I’ll be writing another post soon, once I’ve gone through my text book1, and dissecting what we covered last night. Until I do that, I’m completely lost. And not because I can’t understand it so much as the delivery was all over the place.

My lecturer complained a couple of times that the text and notes go into complicated areas that if he were to teach it, would not be covered yet — which is fair enough. But then time and again he himself would veer off into areas that I’m sure will be covered in a few weeks (ie. not now) and just makes things more confusing now.

And what is with using “Dog” as an example of a program? Every introduction to programming I’ve read uses dogs, cats, cars and pizza to explain classes. That’s useful for about as long as it takes for you to “get” that a class can have attributes and functions, but beyond that is completely meaningless in a practical sense. Using dogs for coding examples just makes my brain hurt, because I can’t see how you can perform arithmetic on a dog, or use a dog to perform a function for another dog. I get that it’s using simple things to explain new concepts, but to me it just clouds the issue. Give me a real example (a simple one) of how making a function and calling it generates a result, and I’ll be happy. Unless your example is int x = a+b; — that’s almost as meaningless as Dog().

I apologise if I’ve used the incorrect terms for things in the previous paragraph. I also stress that I can’t do better or think of more useful examples because I still can’t program yet. But I’m working on it. And I’m gonna’ read a chapter ahead this time, as I suspect my classmates are only ahead of me by a hair as I’m pretty sure all the questions they were asking would have been straight forward and obvious if they were reading the text (judging by the questions they asked about stuff even I knew).

Please correct me or share your thoughts about how Dog() is actually a useful thing to learn!

Footnotes
  1. yes I have it now! 
  • When that lightbulb goes on and you "get" object oriented you will never go back. If you have the bucks for a book I would recommend Refactoring by Martin Fowler. It shows you OO by showing what bad code is like and how to fix it. It is a book that will stand you in good stead in your professional career as well as at school.
  • Thanks for the suggestion. I'll check it out. As for the lightbulb... I'm expecting it will go on when I actually get into code examples, rather than watching the lecturer discuss Dog classes on the board out front.
  • To help you out, they use Dog() as a class because it is very easy to show inheritance such as:

    Public class dog{

    int numberOfLegs = 4;
    String voice = "Woof";
    }

    public class goldenRetreiver extends dog {

    String temperment = "happy" ;
    String color = "golden";
    }

    In the above case, the goldenRetriever class inherits the numberOfLegs and voice from the class dog() (because a golden retriever is a dog) but the class goldenRetriever also has it's own temperment and color.

    As far as performing functions with them, you can do things like:

    System.out.println(voice);

    which would print the word "woof" to the screen. You would be able to use the variable named voice with any dog() or any extension of dog(), like goldenRetriever.

    I would suggest checking out these sites for additional info:
    http://java.sun.com/docs/books/tutorial/
    http://stackoverflow.com/questions/tagged/java
  • Cheers for explaining that molex. I think I understand that, but last night he started with something like your example, but immediately went on to explain that you'd instead use getters and setters to get "voice" from "dog", which kinda just makes everything less clear, because yours is a straightforward example, while the other is programming with dogs.
  • The whole getters and setters thing will make sense soon. Until then , think of it like this:

    A getter in Java is a way for one object (goldenRetriever) to "get" data(voice) from another object(dog).

    A setter in Java is a way for an object(goldenRetriever) to "set" data(voice) as it's own.

    It is really a lot of typing for a simple idea. That is one of the chief complaints about Java. There is a lot of "keyboard noise" to produce a small result.
  • Ben
    For most people its hard at the start, but assuming the teacher knows what he is doing, one day its just gonna click and all make sense.
  • I'm expecting it to make sense as soon as I can sit down with the text and read through the section we covered last night. I think it's just that I'm finding the piecemeal nature of the tutorials difficult, not that the concepts are inherently difficult to get.
blog comments powered by Disqus