Today I continued with the java tutorials from TheNewBoston. I’m doing this to be able to better understand the programming language behind android development. I watched videos 20-57, I stopped at polymorphism to get a night’s sleep on that subject and review it tomorrow.
The videos covered a great deal of subjects, most of them I already knew from python so I just quickly covered them, focusing on syntax. Here is a little overview of what I saw today:
- averaging program: take a few numbers using a while loop and return the average.
- for loops: Same thing as a while loop for the most part.
- compound interest program: calculate the compound interest over x years, printing the total amount of income for each year
- do while loop.
- Math class: some method examples.
- Random class: revised again.
- Array and matrix
- Enhanced for loop: much like python’s for loop (traversal).
- The ellipse “…”: Takes in a dynamic number of arguments and makes an array out of them. (e.g. public int doThis(int…numbers); //arguements will be stored in the array a.
- “this” keyword: refers to local variables inside methods or to the same method (constructor recursion?).
- multiple constructors: made possible by the “this” keyword. A slightly different constructor gets invoked again inside a constructor’s body of the same class.
- toString method: for object representation, whenever you pass an object as a string, if you have a toString method in that object, that’s the string that’s going to be used.
- Enumeration: constants that are also objects.
- static keyword: a static variable/attr. is the same in all instances. If you change it, it changes in all instances. Can be used to count how many instances have been created. static methods can be accessed without creation of an instance by the statement Classname.methodname();
- final keyword: final means that you can not modify the variable no matter what, like a constant, and you write it in caps by convention.
- inheritance: when a class can use methods from another class. private methods cannot be inherited. the class inherits the methods by using the extends keyword. so now objects from a subclass can use methods from the parent class. inherited methods can be changed across sub-classes, which leads us to polymorphism.
- polymorphism: super and sub classes have the same method name (inherited), but the method in each subclass can be changed to do a different action from what the original inherited method did. So although the method name remains the same, the action can be different across sub classes. With polymorphism you can pass objects as arguements for other class’ methods.
The plans for tomorrow are to finish the rest of the series (30 videos), I’ll probably just look through the more relevant ones. There’s also a video tutorial series that he has on java game development so I’ll probably check that out tomorrow or the day after tomorrow.
Leave a Reply