#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0

    Figuring out "Objects"


    I started doing a tutorial on Fortran and found it pretty easy. Then I found that the class I plan to take in the fall (beginning programming) uses Java so I got a book from the library. After reading 100 pages I'm still lost and not even as far, in skill as I was with my 5 page tutorial with Fortran. I think the problem is that I still can't understand what a class is, an object, a method etc. In fortran, you just declare a variable, tell it to read the input from the user, do your math or whatever and print. So what's with the void, static, main, public etc etc? I assume it makes things really awesome once you figure it all out because right now it seems like gibberish.

    Any help with learning what object orientation means?
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    Object oriented programming exists because once your program grows beyond a few hundred lines it becomes extremely difficult to organize the code in a robust way. Organization of code is the primary purpose of object oriented programming.

    Java takes object oriented programming to a far more extreme degree than most other languages, but that's one of the reason why its often used for teaching. It's also an extremely verbose language, which is nice while you're learning, but sort of annoying once you already know it.

    Maybe try another book on it. The concepts behind object oriented programming are pretty much the same across all programming languages, so you don't necessarily need to use Java to learn it.

    In a very simplified sense, a class is a template for a set of related variables and functions that operate on those variables. An object is a "real" copy of the template - ie: you can store values in the variables and and call the methods of an object. You can have many objects of a single class, and each one has its own set of values for the variables that are defined for that class. The only thing the objects share is the fact that each has the same variable names and functions.

    While you're figuring that out, I recommend ignoring the static keyword as much as you can (because it sort of violates the description I gave you above). However, you have to use static when defining the main method, which is the starting point for the program.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Dallas, TX
    Posts
    50
    Rep Power
    2
    In addition to what was said by E-Oreo, I would recommend finding a few good books on Amazon regarding "Object Oriented Patterns". It will bring a lot of things to light with regards to why and how OO programming can be very powerful and robust. This is something I wish I had done when I was first learning Java, rather than learning it more along the lines of a procedural language (which is probably where your frustration is stemming from - you need to abandon the idea of procedural ways of coding where things are just clumped into one giant program with hundreds of lines of code, one after another).

    The company I work for does a lot of Android development, and Java is the primary language. The folks on the team are some of the best in the business when it comes to OO patterns, so they were sticklers when it came to me coming aboard and building code on the platform. Ultimately this has led me to learn a LOT and really fall in love with OO patterns and using them to build clean and robust code. It's worth it, trust me.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by BlastPort
    In addition to what was said by E-Oreo, I would recommend finding a few good books on Amazon regarding "Object Oriented Patterns". It will bring a lot of things to light with regards to why and how OO programming can be very powerful and robust. This is something I wish I had done when I was first learning Java, rather than learning it more along the lines of a procedural language (which is probably where your frustration is stemming from - you need to abandon the idea of procedural ways of coding where things are just clumped into one giant program with hundreds of lines of code, one after another).

    The company I work for does a lot of Android development, and Java is the primary language. The folks on the team are some of the best in the business when it comes to OO patterns, so they were sticklers when it came to me coming aboard and building code on the platform. Ultimately this has led me to learn a LOT and really fall in love with OO patterns and using them to build clean and robust code. It's worth it, trust me.
    You are exactly right. I just couldn't comprehend why you needed to put "public void etc etc" in front of code when in other languages, older ones even, it's much simpler.

    I wish someone had just told me that a "method" is just like a string for other code. I was getting really confused when I thought that this kind of thing was a primitive command: "calculateRate()" or "placeBeeperThenTurnAround()" So I've found some more resources that are making it more clear.

    Can I ask you how you got started? CS Major?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Location
    Dallas, TX
    Posts
    50
    Rep Power
    2
    Originally Posted by sakalava47
    You are exactly right. I just couldn't comprehend why you needed to put "public void etc etc" in front of code when in other languages, older ones even, it's much simpler.

    I wish someone had just told me that a "method" is just like a string for other code. I was getting really confused when I thought that this kind of thing was a primitive command: "calculateRate()" or "placeBeeperThenTurnAround()" So I've found some more resources that are making it more clear.

    Can I ask you how you got started? CS Major?
    Absolutely, yeah sometimes it's just a matter of explaining it the right way. Think about it in a way that your code should be a collection of methods, and if it helps, try to have small chunks of code in each method (no more than 10-15 lines of code per method). If a class gets too big, then start to break off chunks of functionality into new classes to separate it out. This may be a good way to start training yourself at least to use some light OO techniques.

    i.e.:
    public void doStuff() {
    doFirstThing();
    doSecondThing();
    }

    private void doFirstThing() {
    // some code to do the first thing
    }

    private void doSecondThing() {
    // some code to do the second thing
    }


    This makes for very clean and easy-to-follow code.

    I was indeed a CS major, but unfortunately they taught me a very procedural way to code Java while in college (Java was just getting ramped up at the time and people figuring it out), so it wasn't until much later, after I graduated and started working at a large corporation, that I saw how Java code should be written. I was surprised to see concepts of Abstract Classes, Factory Patterns, correctly-built encapsulation, polymorphism, and extending classes to add on or to change functionality that you need. All very cool stuff!

    Let me know if I can help understand any piece of something you come across that doesn't make sense, and I'd be glad to help.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by BlastPort
    Absolutely, yeah sometimes it's just a matter of explaining it the right way. Think about it in a way that your code should be a collection of methods, and if it helps, try to have small chunks of code in each method (no more than 10-15 lines of code per method). If a class gets too big, then start to break off chunks of functionality into new classes to separate it out. This may be a good way to start training yourself at least to use some light OO techniques.

    i.e.:
    public void doStuff() {
    doFirstThing();
    doSecondThing();
    }

    private void doFirstThing() {
    // some code to do the first thing
    }

    private void doSecondThing() {
    // some code to do the second thing
    }


    This makes for very clean and easy-to-follow code.

    I was indeed a CS major, but unfortunately they taught me a very procedural way to code Java while in college (Java was just getting ramped up at the time and people figuring it out), so it wasn't until much later, after I graduated and started working at a large corporation, that I saw how Java code should be written. I was surprised to see concepts of Abstract Classes, Factory Patterns, correctly-built encapsulation, polymorphism, and extending classes to add on or to change functionality that you need. All very cool stuff!

    Let me know if I can help understand any piece of something you come across that doesn't make sense, and I'd be glad to help.
    Thanks so much! I will.

IMN logo majestic logo threadwatch logo seochat tools logo