COP2800 : Java Programming Chapter 3

Advanced Object Concepts

Section A Class Features

1) Block: within any class or method, the code between a pair of curly brackets is called a block.

2) Nested: When a block exists within another block, the blocks are nested.

3) Scope: The portion of a program within which you can reference a variable is the variable's scope.
A variable cease to exist at the end of the block in which it is declared.

4) Same name variable: Within a method, you can declare a variable with the same name multiple times, AS LONG AS each declaration is in its own, NonOverLapping Block (out of its scope).

5) Overrides: If you declare a variable within a class, and use the same variable name within a method of the class, the variable used inside the method takes precedence, or overrides, the 1st variable.

6) Overloading: When you overload a Java method, you write multiple methods with a shared name. The complier understands your meaning based on the arguments you used with the method.

7) Ambiguity: When you overload a method, you run the risk of creating an ambiguous situation - one in which the compiler cannot determine which method to use.

8) Overloading constructors: You can write constructors methods to receive arguments. Such arguments often are used for initialization purposes when the values that you want to assign to objects upon creation might vary.

Back to the Top


Section B Using Methods

1) When creating classes: Usually, you want each instantiation of a class to have its own copy of the data fields. If you create a class and instantiate 2 objects, you usually store 1 copy of each method for use with the objects. When you create multiple class objects and use a class method, the compiler accesses the correct object's data because you implicitly pass a reference to the object.
The this reference specifies which object you are referencing.

2) this: is a keyword in java used to reference an object.
Usually, you do not want or need to refer to the this reference within the methods you write, but the this reference is always there, working behind the scenes, so the data fields for the correct object can be accesses.

3) Nonstatic methods: methods that you associate with individual objects.

4) static methods: like main() method in a program and the methods main() calls without an object reference are static. (static methods also called class methods.)

5) Class Methods: These methods DO NOT have a this reference because they have NO OBJECT associated with them.... they are class methods (static).

6) Class variables: variables that are shared by each instantiation of a class. You only need one copy of that variable and it is shared with each object of that class, if that variable changes, it changes for all class instantiations.

7) Constants: it should not be changed during the execution of a program.

8) final: to prevent alteration of a constant the keyword final is inserted and it becomes a symbolic constant.

9) symbolic constant: has the keyword final which means it cannot be changed for the duration of an executing program. You CANNOT change the value of a symbolic constant after declaring it; any attempt to do so will result in a compiler error. You must initialize a constant with a value, which makes sense when you consider that a constant cannot be changed later. If a constant does not receive a value upon creation, it can never receive a value at all.

10) Package: is a folder that provides a convenient grouping for classes, which is sometimes called a library of classes. (P.119)

11) Fundamental classes: or basic classes, are implicitly imported into every java program and is named java.lang. --- We have used several prewritten classes like:
System, Character, Boolean, Byte, Short, Integer, Long, Float, Double.
java.lang.Math contains constants and methods that you can use to perform common mathematical function. Example of constant is PI.

See page 120 for Math methods and the meaning.

12) Optional classes: must be explicitly imported. Examples are: java.util.* The * is a wildcard and represents all the classes in the package rather then importing only one of the many packages like java.util.Date

13) import class: you must use 1 of 3 methods. (page122)

14) wildcard symbol: asterisk(*) example: import java.util.*;
imports the entire package so any class within that package can be utilized.

Back to the Top


Links to COP2800 Java Programming Chapters:
Links to the java.sun.com to help with Java Programming

Back to the Top