mockable-24-android.jar : Sometime too large

As a TA of the course “Mobile Application App”, I recently run into a problem. The teacher asks students to upload their homework to LATTE, our university’s course management platform. However, the size limit of LATTE platform is 20 MB, and

As Professor Chaturvadi suggests that we’d better stick on Latte for homework submission, I tried to load the apk. Actually, it does work on my AVD. But the thing is, although apk is actually zip, many files are turned into binary. Android Studio 2.2, which is released on 9/19, has a tool to decompile the code. However, I bet none of us want to read decompiled code like this: read more

TIJ chapter 8: Polymorphism

Polymorphism(also called dynamic binding or late binding or run-time binding) is an essential concept in OOP. This chapter is basically a more detailed explanation of polymorphism, which is highly relevant to inheritance. (As mentioned in chapter 7, in many cases inheritance is meaningless when polymorphism is not necessary.) read more

TIJ chapter 7: Reusing Classess

Composition, inheritance and delegation are 3 main methods to reuse classes.

Delegation is not a familiar concept for me, and it is not directly supported. However, I think I have used its content before. It just put a member object in the new class and expose all method to the new one.

About inheritance, it always calls the super() constructor even if you don’t called it literally in derived class. As a result, if the base class don’t have a constructor without any parameters, and you don’t call base class constructor literally in derived class, you will get a compile time error. read more

TIJ chapter 6: Access Control

This chapter is not a complex one. It just tells the access control involved in Java.

There are 4 access level in Java, public,  protected, package-private, private. (By accident they all start with letter “p”). Package-private is the default one without any modifier. The only thing one should note is the protected access level implies package-private ones(Actually this is true for all 4 levels, one implies the other one by order).

If one doesn’t allocate a package for a class, this class will belong to the default package. Default package in a same directory is viewed as one package. read more

TIJ chapter 5: Initialization and Cleanup

This chapter is really the beginning of OOP. I think Java is really designed with the concept of OOP. Even those process oriented programming elements are forced to be absorbed in that systems and become static element. If in one day, which may not be too far away, OOP are no longer popular, Java would either.

Ironically, we always had to have some place to start up a program, and that place can’t be an non-static method, at which no object has been created since it is the beginning. So, the starting point is always a static method, either main() method or something else in JUnit or things like that. In that static method, we can call other static methods or create new objects and run non-static method on that. However, every static method cannot go beyond classes. read more

Thinking in Java Chapter 1&2: Object

After one year of programing with Java, I am gradually familiar with OOP. Learning java for me, whose first programming language is C, was much more than change the name system, like field, method, reference, etc. It is almost a renewal of concept. Although so, my knowledge of Java was founded from all kinds of sources, and a book like Thinking in Java seems useful for me to introduce systematically introduce the thought behind Java.

It is important to design classes appropriately. For people who is not familiar with OOP, it can easily happen that use classes as structs and designs methods as “functions” in the outer classes. Abusing inheritance may also be a popular mistake. When the relationship between classes is “have-a”, one should use composition(or aggregation when dynamically). We should also think about it whether the relationship is “is-a” or “is-like-a”. For the former one, we may only override methods of base class, while the latter one may involves implicating new methods. When we upcasting objects to their base classes types, only methods we use substitution can be called. Otherwise, we will have to downcast the reference to call the unique methods. Although so, both the two models are useful, and the choice will be obvious for certain problems. read more