Wednesday, October 10, 2007

Java Faqs - Know About Java......& Java Faqs

Everything in Java is an object. An object is a collection of data and actions that make up a programming entity. A 'car' object, for example, might have some data (i.e. 'speed,' 'direction,' 'lights on,' 'current fuel,' etc.) and some actions it can take ('turn right,' 'turn lights on,' 'accelerate,' etc.). Objects provide a number of advantages when programming; the include the ability to hide what's going on 'inside' the object from other programmers, which is useful for writing code that others can work with but not easily mess up. However, the biggest advantage to programming with objects is that objects simply 'make sense'; they form the nouns and verbs that you use to write the 'story' of your program.

Our 'car' example would be (pseudo-) coded as follows:

public class Car { double speed; double direction; boolean lightsOn; double currentFuel;
public void turnRight(){ - code here to turn right - }
public void turnLightsOn(){ - code here to turn lights on - }
public void accelerate(double rate){ - some code here to accelerate - }
}

No comments: