Posts

Showing posts from November, 2018

Integer Class possible NullPointerException

While I was debugging, I got NPE which is not happy. When I glanced at the codes, it seemed that there was no problem. But after looking through line by line, I finally got the point. For example, let's have a class Result. public class Result { private Integer rcode ; public Integer getRcode () { return rcode ; } public void setRcode ( int rcode) { this . rcode = rcode ; } } It has only one Integer variable. If the class is instanciated from json or without validation, rcode could not be initialized and could not have any value.  And at the point the value is compared, NPE comes. Result result = new Result() ; if (result.getRcode()== 1000 ){ // NPE happens! System. out .println( "this cannot be reached." ) ; } Same situation can happen if we take this variable as a method with primitive parameter. public static void printReturnCode ( int rcode){ System. out .println( "this also cannot b...

It's so hard to change.

Recently, I had two tests. One on online judge site and another one at work. In common after two tests, I realized that I had never designed any method at first time. Studying algorithm and architecture, I learnt that 1. problem define 2. simplify problem 3. design how to solve 4. design method 5. name a great name on methods and variables But when I faced a real test, I totally forgot what I learnt from study. Only thing that I did was reading the problem, starting the typing. On daily work, for sure, I have changed nothing. Get a mission and start to type. No consideration about other services, maintainability, optimization, and even test cases. Why I am not changed after reading and learning the quality of good software engineer. I think it has been long time with this habit and it's not easy to change at once. I think I need to keep thinking and trying to change every single day.