Here some exercises during my Practice learning Java and Oriented Object Programming
- Learned how to manage Objects;
- Learned how to manage Setters, Getters and Constructors;
- Learned how to set up a package in this Programming Language;
- Inheritance and Polimorphism;
- Conclusion: It isn't as difficult as people say if you learned other Programming languages;
- All classes or at least one class is son of Object -> For example in my NaloFlix exercise the Object Titulo doesn't extend anything even 'cause that is the Mother of all classes, even though it extends Object behind the scenes.
- Why when printing a object it shows the object@somenumbers ?
This happens because
soutconverts the object into a String and the String gets the object and uses this code:
getClass().getName() + '@' + Integer.toHexString(hashCode())- You cannot inherit the constructor
- You can have two variables that work as a reference to one object
Movie movie = new Movie();
Movie lordOfTheRings = movie;
// references but the same object, this is just a form of expressing the same thing- Sometimes you will face the misterious problem of CompareTo -> In my NaloFlix exercise when having to order a List I had problems because the
Collection.sort()could not order Object because it uses thecompareTo()behind the scenes so I went in my SuperClassTituloand made a@overrideand made when comparing the objects, get name from them and comparing these Strings.
@Override
public int compareTo(Titulo anotherTitle) {
return this.getName().compareTo(anotherTitle.getName());
}