Monday, July 5, 2010
Instance Variable Hiding
When a local variable has the same name as an instance variable, the local variable hides the instance variable.
Garbage Collection
Java provides auto garbage collection for unused objects. The garbage collector runs periodically, checking for objects that are no longer referenced by any running state or indirectly through other referenced objects.
The finalize( ) Method
By using the finalize method, we can define specific actions that will occur when an object is just about to be reclaimed by the garbage collector. The Java run time calls this method whenever it is about to recycle an object of that class. Inside the finalize( ) method you will specify those actions that must be performed before an object is destroyed. The garbage collector runs periodically, checking for objects that are no longer referenced by any running state or indirectly through other referenced objects.
Overloading Methods
Method overloading is one of the ways that Java implements polymorphism. When two or more methods within the same class share the same name but differ in the type and/or number of their parameters then those methods are said to be overloaded. While overloaded methods may have different return types, the return type alone is insufficient to distinguish two versions of a method. When Java encounters a call to an overloaded method, it simply executes the version of the method whose parameters match the arguments used in the call. Java uses the type and/or number of arguments as its guide to determine which version of the overloaded method to actually call.
Argument Passing
Call-by-value: This method copies the value of an argument into the formal parameter of the subroutine. Therefore, changes made to the parameter of the subroutine have no effect on the argument.
Call-by-reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter. Inside the subroutine, this reference is used to access the actual argument specified in the call. This means that changes made to the parameter will affect the argument used to call the subroutine.
When a simple type is passed to a method, it is done by use of call-by-value. Objects are passed by use of call-by-reference.
Call-by-reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter. Inside the subroutine, this reference is used to access the actual argument specified in the call. This means that changes made to the parameter will affect the argument used to call the subroutine.
When a simple type is passed to a method, it is done by use of call-by-value. Objects are passed by use of call-by-reference.
Subscribe to:
Posts (Atom)