| ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Author:Samiya Illias | ||||||||||||||||||||||||||||||
| Date written / submitted:15th October 2004 | ||||||||||||||||||||||||||||||
| Title:Java _ anytime anywhere | ||||||||||||||||||||||||||||||
Java is just like algebra; either it’s a piece of cake, or you don’t get it at all. The problem with both of them is that students fear them. Remember the phrase, ‘Fear is the key’. During my teaching tenure, I have observed that students are so frightened to make a mistake, that they end up making just so many. They also assume that it is incomprehensible, therefore, why waste time trying to understand something which is simply impossible. Nothing could be more removed from the truth! Class:
Java is a fine example of logical programming, where the language has been adapted to the real world model. In the real world, we tend to classify everything as living, non-living, plant, animal, mammal, cat, dog, human, etc. So is the same in Java. Each class represents a logical group, such as animal, mammal, cat, and so on. Also notice that in this list, each class is a subclass of the previous class. In Java, we have the concept of generalization-specialization, or superclass-subclass, or parent-child relationship. It is exactly the same. The animal class (or group, if that sounds easier), is the super class of the class mammal. Thus all those properties and behaviors common to all animals, i.e. common to mammals, birds, fishes, etc. are contained in the animal class. Properties and behaviors specific to mammals only are defined in the mammals class. When the mammal class becomes the super class of the class cat, it automatically bestows all the properties of the animal and mammal classes to the clas cat. Thus, in the class cat, only cat-specific data definitions need to be stored. Object or instance:
Now, coming to the next point. The cat class is a concept. A cat is not the same as the cat class. The cat class defines what a cat should be and how it should behave, whereas a cat is a real world object exhibiting behaviors and properties defined in the cat class. Thus, a cat is an instance of the cat class, whereas the cat class is the data type of our object cat. Our cat object can also have a name such as Garfield or Tom. It can also have a color property such as orange or gray. The cat object can have a name and a color because the cat class, or its super class, contains definitions for such properties for cats. Interface:
An interface is a set of abstract methods, that is, method definitions, but no details of what or how. It can be likened to a set of rules that must be implemented. For example, an education governing body oversees many diverse types of institutions from schools and universities to institutes for technical education. The governing body defines an interface, say ‘general rules’, which have the following method statements. A) Each institution will have a formal admission procedure. B) Each institution will have a syllabus. C) Each must have a time table for classes. D) Each must have an examination policy and procedure, and E) Each must have a system of results. Now, these are only broad guidelines at best. How each institution implements it is entirely up to it. The only constraining factor is that all educational institutions coming under this governing body must implement ‘general rules’, and that also all of them. Procedures may be different, but compliance is a must! |
||||||||||||||||||||||||||||||