Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

Java help anyone??

OpenStudy (anonymous):

Please help me understanding the concept "Object" in java..

OpenStudy (javk):

In order to understand the object oriented programming concept, lets first look at what an object really is. An object is a bundle of related state and behaviour. Now that wasn’t very helpful, now was it…which brings us to our next question, what do I mean by the state of an object and its behaviour. The state of an object describes/explains what it is - its properties. For example if we were to look at a dog, then - Object: dog - State: name, breed, colour, etc. In java, this is stored in fields or variables. The behaviour of an object is what it does / what it can perform/ its actions, therefore continuing with the previous example - Object dog - Behaviour: barking fetching, rolling This is exposed through methods. The method operates on an objects internal state. Are you with me so far?

OpenStudy (javk):

now if I haven't lost you yet, then, we need to understand why we use objects in the first place. Attributing states, and methods to change the state, allows the object to remain in control of how the outside world can use it, e.g. if a car has 6 gears only, then the method would reject any values that would fall out of its range i.e. <1 and >6.

OpenStudy (javk):

Using object oriented programming has its benefits. (1) Modularity: it allows you to break down the procedure into manageable chunks. (2) Information-hiding: meaning whatever you do within your methods is hidden from the outside world. (3) Code-reuse: allows you to reuse an existing object. (3) Plug-ability and debugging ease: allows you to use existing code ad to replace a part without having to rewrite the entire programme, similar to replacing a faulty bolt. To understand this further, let’s choose a real life example so that it’s more relatable. Let’s look at the process of baking a cake. This task can be broken down into 3 major steps: collect the ingredients and equipment, mix the ingredients together and baking time (Modularity). Now when I go to collect the ingredients and equipment, at most I’ll go to the supermarket. Why? Because somebody has already made the effort and brought them to the supermarket, I don’t have to redo all that work, I can use the existing system to get what I need (Plug-ability) this allows me to focus my energy on other things for instance how to decorate the cake etc. At this point, take note that I am also unaware of how exactly the ingredients arrived at the supermarket shelf because as long as I got the correct ingredients then it is irrelevant to me how it got there...by ship, by truck, by plane...you get what I mean(information-hiding). Also when I’m collecting the equipment, if I already have some of the equipment at home then I don’t need to keep on buying it each time I want to bake a cake, so I am able to reuse my spatulas (code-reuse). Now if I were to have a rotten egg at my hands, I can just throw it out and get a fresh one, as opposed to throwing out the entire cake (debugging ease). Up till now we’ve only looked at the first stage of baking, the collecting ingredients/equipment part, but already we can see how not having to do all the work yourself or breaking it down into more manageable chunks is really helpful, likewise with java coding.

OpenStudy (anonymous):

Thanks man .. thats was very helpful.. @Javk

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!