PEIGANG's profile铁匠铺PhotosBlogLists Tools Help

Blog


    October 26

    1st anniversary in the lab

    It has been for more than a year in the lab. During the year, I have experienced happiness and sadness. There is an old saying in China: In the BenMingNian, a person will be great lucky or great down. I guess I belong to the latter one. Well, this may not be a bad thing; I also learn a lot and think a lot during the down time.

    I think I am a person who don’t like being in an idle state. Everyday, I study the major materials and the Web technique which I have interest in. Sometimes, I feel very tired, especially when I am caught by a problem. But if you have many things to do, you will have no time to think about the sad thing.

    I wish I will be lucky next year. Maybe I should make this wish to god on my birthday,  maybe it is too early now.

    October 09

    Parameter Passing in Java

    In Java, you may use a function which has parameter, then what does the parameter pass into the function? The answer is value, without any doubt. Let us start the insight from the data type. In Java, there are two types of data: one is basic data type, another is object data type. The basic data type contains byte, short, int, long, float, double, boolean and char. If you declare a variable of one of the eight basic data type in program, then the variable will stand for the memory address of the data. When you declare an object variable, the variable will store a specific memory address which the object data start from. We call object variable store a reference of the object and the basic data type variable store the value of the data.

    Then, if you pass a parameter into a function, a copy of the parameter will be automatically created in the program stack. So a basic data type parameter will have a copy of value, and an object data type parameter will have a copy of reference. But we can see the reference as a special type of value and we can call it reference value.

    Before following discussion, we will introduce another two conceptions: mutable and immutable. If an object has some operations like: setValue(Datatype value), etc. These operations can change the object member variable, i.e. change the state of the object. We call this object a mutable object, the class of this object a mutable class. If an object does not any operation which can change the member variable, we call it a immutable object, the class a immutable class.

    If you understand above, then let us talk about a more important issue: if a function does some operations to the parameter passed-in, will the parameter has some change after the function call? There are three conditions. If you pass in a parameter belongs to one of the basic data types, the parameter will not change in any case. If you pass in a mutable object and call the object’s ‘set’ operation, then the object will change after function call. If you pass in an immutable object or a mutable object, but do not call its ‘set’ operation, the parameter will not change also.