Reference vs.primitive o Java handle objects and arrays always by reterence. o Java always handle values of the primitive types directly ●differ in two areas: Ocopy value Ocompare for equality
Reference vs. primitive lJava handle objects and arrays always by reference. lJava always handle values of the primitive types directly ldiffer in two areas: ¡copy value ¡compare for equality
Visibility of fields and methods Generally make fields private and provide public getField()and setField()accessor functions O-O term:encapsulation o Private fields and methods cannot be accessed from outside of the class
Visibility of fields and methods lGenerally make fields private and provide public getField() and setField() accessor functions lO-O term: encapsulation lPrivate fields and methods cannot be accessed from outside of the class
Static vs.non-static oStatic:class variable/method o Non-static:instance variable/method Static ones are associated with class,not object.Can be called using class name directly ●main()is static OEven though it's in a class definition,no instance of the class exist when main starts executing
Static vs. non-static lStatic: class variable/method lNon-static: instance variable/method lStatic ones are associated with class, not object. Can be called using class name directly lmain() is static ¡Even though it’s in a class definition, no instance of the class exist when main starts executing
Static vs.non-static (cont. o Instance fields define an object;the values of those fields make one object distinct from another o Instance method operates on an instance of a class (object)instead of operating on the class itself. o Class methods can only use class fields; while instance methods can use both instance fields and class fields
Static vs. non-static (cont.) lInstance fields define an object; the values of those fields make one object distinct from another lInstance method operates on an instance of a class (object) instead of operating on the class itself. lClass methods can only use class fields; while instance methods can use both instance fields and class fields
Keyword this o Invisible additional parameter to all instance methods OValue is the instance through which it was called otc.instanceMethod(;->this=to ●Three common usage ○Same name variable OPassing the object myself OCall another constructor
Keyword this lInvisible additional parameter to all instance methods ¡Value is the instance through which it was called ltc.instanceMethod(); -> this=tc lThree common usage ¡Same name variable ¡Passing the object myself ¡Call another constructor