Reading trough it the first time, it seemed quite hard to understand altough the chapter itself is the smallest in the book only 10 pages! There are many different types of files but the chapter covered only sequentiall access files of characters. So, for writing data to a file you have this squence of steps you must preform in order for you input to reach the phyisical file on the disk. All these FileWritters, BufferedWriters and PrintWriters made little sense when going trough it the first time and maybe even the second.
|Published (Last):||19 December 2018|
|PDF File Size:||3.86 Mb|
|ePub File Size:||6.68 Mb|
|Price:||Free* [*Free Regsitration Required]|
Reading trough it the first time, it seemed quite hard to understand altough the chapter itself is the smallest in the book only 10 pages! There are many different types of files but the chapter covered only sequentiall access files of characters. So, for writing data to a file you have this squence of steps you must preform in order for you input to reach the phyisical file on the disk.
All these FileWritters, BufferedWriters and PrintWriters made little sense when going trough it the first time and maybe even the second.
But then I saw a pattern and I decided to put the explanation into my own words and a drawing, which can be seen downbellow. It takes data in and it converts it into streams of characters.
Anyhow, the right-hand-sided part of the above statement new PrintWriter buffaloSoldier acts as a pipe-line that connects the PrintWriter factory to the BufferedWriter factory. Streams of characters are sent trough this pipe-line into the BufferedWriter. And what does the BufferedWriter do? It plays a part in efficiency because sending characters to a file one at a time, well that would be unefficient. So, the bufferedWriter object puts this cahracter type data from the PrintWriter into packages which are then sent to the FileWriter.
Here it goes again. It has to be double, otherwise the compiler wont reckognize it. Ok, so bottomline… this drawing is far from perfect, but it helped me understand the logic behind passing characters into a file and how that works.
There are other, less complicated ways to write data to files and I was a bit disapointed by the way this chapter was put together it has only one exercise! I started writing out a metaphore for constructors, comparing them to construction workers and classes as their bosses, but in orderd to make full sense of it, I would have to dig quite deep and explain the problematics of other classes as well and the relationships between these different classes. Maybe some other time.
This conncept of programming is very well put it app inventor. Such methods are useful for tasks such as counting the number of objects created etc. A car has a engine, it has a gearbox, it has windows, ets. In the same way an object Car of the Car class, can have attributes which are objects from other classes, for example: Engine class, Gearbox class, Passanger class, Seat class, Window class. If you can use the same words when describing a relationship between two or more objects, you then use compositon.
Another example: I have this object from the Computer class, which is my laptop. What other classes would I use when describing my laptop? So, my computer has a keyboard, it has a mouse-pad, it has a screen, under the hood it has a harddrive, a processor, RAM, etc. So, these are all subcategories for which I could write their own classes.
If a particular class extands any other class, it means it will inherit its atributes. You can think of inheritance in terms of a family tree of classes.
Difference between protected and private? When using private, a certain attribute is reachable only within the class in which it is declared. Relationship between classes? Descendants and ancestors. You can think of relationships between classes as a family tree hiearchy. In fact, all classes in Java are a part of one big built-in hiearchy, with the class Object sitting at the top.
As you can see in this diagram, the class Object is the ancestor to all the other classes. Cat, Dog and GuineaPig classes have the same common ancestor, the Animal class. It means they inherit certain attributes and behaviours which are common to all animals. Polymorphism So, what is polymorphism? In this example with the Animal class and its subclasses, polymorphism would go something like this: every animal can make sounds, right?
It is up to the subclasses to over-ride this abstract makeSound method and fit it to particular class by making it more concrete. Dogs bark, Cats meow and GuineaPigs squeak so they would each have their own version of the abstract makeSound method. At this stage im still quite far from being able to write simple desktop programs but i have an idea for a very useful one.
Edward Currie – Fundamentals Of Programming Using Java