Java – Object Oriented Programming – part 1

Object-Oriented Programming
Part 1:

1. Differences between local variables and member variables include:

1) Positioning in class. For local variables, the major positioning takes place in or attached to a function itself, whlie for member variables, the major position site is in class yet away from functions.

2) Positioning in the Memory System. Local variables tend to be processed in stack memory, while member variables are firstly initialized, then defined or altered in heap memory.

3) Period of existence. Local variables whose existence rest closely on that of a function disappear with the function; member variables, on the other hand, depend on their class(es) for existence.

4) Way of Initialization. Java automatically assigns values for member variables, in which case String values are defined as “null” and int as “0” for example. However, for local variables, a process of involving coding values is necessary, or the Java compilor would not be able to proceed to the next stage.

2. Cases involving formal parameter being in its typical form and reference type.

In the case that a formal parameter is defined in its traditional form, such as in form of int and string, this parameter disappears after it’s been either apportioned, or referenced. When this parameter takes the form of a reference type, it is de-facto a new object that points to a new area in the heap memory upon initialization.

3. Anoymous Objects.
1) Annoymous Object is executed only once; repetitive call is often discouraged.

2) Sometimes Annoymous Objects play the role of a formal parameter.

4. Encapsulation.

Definition: Encapsulation takes place when the key word “private” is called to make a function/parameter/variable seen and usable for only the class in which the encapsulation takes place. In other words, without a third-party function invovled, it is not likely that a “private” variable or function can be put to use in another class.

5. Keyword “This”

Keyword “This” refers to a parameter that exists in the very class where the coding persists. It is a keyword often called upon when variables or parameters in different classes/functions share the same title/name.

6. Constructor Method.

A Constructor Method is a function used to initialize a related class. A Constructor Method shares the same name with its class. Without a returned value, a Construct Method does not, as is the case with other functions, need to have a “int” or “String” or “void” claim.

When formulating a Constructor Method, please be aware that “return” method is not necessary – in fact, it is even prohibited.

7. Ways to attach values to a Member Variable

1) Using a public function
2) Using a Constructor Method

8. The process of Member Function’s Initialization
Case:

Student s = new Student();

A. An area is designated for objects in the stack Memory.

B. New Student starts to request space in the Heap Memory.

C. When class Student is initialized, the process of loading member variables begins.

D. Constructor Method begins to function, with values attached to each variables

E. An address is designated for the new space in Heap Memory.




Sites DOT MIISThe Middlebury Institute site network.