Terminology review

Be sure to look at the glossary at the back of your text.

  • An object has state and behaviors.
    • state: what it knows at the moment or what distinguishes it from other objects. A car has a color, an odometer reading, a current speed, current accelerator setting, a number of doors, etc. The state of an object consists of its properties or attributes.
    • behavior: what it can do with what it knows and with what you tell it. The behaviors of an object are called its methods.
  • You activate an object's behavior by sending it a message. That is, by calling a method.
  • A class is a collection of objects. A class definition is a specification of the state and behavior of the members of that collection of objects. It also specifies how the state can change. It's like a recipe or a blueprint for the members of that collection. A member of a class is also called an instance of that class.
  • When an expression in code always stands for itself, that expression is called a literal. E.g., 3 is a literal, it stands for the number three. "Hello" is a literal, it is a reference to the string "Hello". true is also a literal in Java, it stands for truth.
  • Each declaration in your code defines a variable. A variable has several properties that we are interested in:
    1. Kind: (I made up the word "kind".) If I ask, "what kind of variable is this?" I want you to answer "local variable", "parameter", "instance field", or "static field".
    2. Type: This determines the range of values of the variable. The type might be something like int, String, double, Scanner, boolean, etc.
    3. Name: a variable's name is the identifier declared in the declaration. A variable's name cannot change once it it declared. Many variables can have the same name as long as their scopes do not intersect. However, a local variable or a parameter can have the same name as a field in the same class because we can use this or the name of the class to differentiate the fields from the local variables and parameters.
    4. Value: a variable's value is the sequence of bits that the machine is using that variable to remember. The value of a variable can change unless it is declared final. There are only reference and primitive values.
    5. Scope: the scope of a variable is the section of code in which mentioning that variable's name will designate the value of this variable.
    6. Lifetime (extent): the period of time (during run-time) when that variable is being stored in the machine.
  • For information about the scope, lifetime and default initial value of the different kinds of variables, look at the handy, dandy scope chart.
  • An argument is a way of customizing the message. For example, .5 is an argument to the accelerator message. I can send the changeGear message with messages such as "1", "3", "R", and so on. So I would type changeGear("2") to change to second gear. "2" is called the argument to the message. It customizes the message. The bahavior of the object also depends on the argument.
  • When a method invocation expression has a value, the type of its value is called the return type of the method.
  • local variable: a variable declared within the implemenation of a method is called a local variable.
  • receiver: the object to which a message is sent. For example, in the expression timer1.start(), timer1 is the receiver and start() is the (instance) method. In the implemenation of the start() method, you can refer to the receiver using the this reference. In the implementation of an instance method, this is always a final variable whose value is a reference to the receiver.
  • overload: to overload a method is to write a method with the same name but different parameter types or a different number of parameters. For example, in the typing timer assignment, you wrote the methods test() and test(int times). This is called overloading. We have seen several examples of overloading constructors. The String class has its constructor overloaded: new String() and new String("Hi"). Most operators are also overloaded. The + operator works with many different types of operands so we say it is overloaded.
  • The signature or prototype of a method consists of its return type, its name, and the types of its arguments. You can have two methods with the same name and return type but with different types of arguments. This is called overloading methods. E.g., the void println(String) and the void println() are overloaded methods.
  • field: a field is a variable that is declared at the top level within a class. It can be given a protection modifier such as public or private.
    1. instance field (aka, member field, member variable, field, instance variable): an instance field is a field that can have a different value associated with each instance of the class.
    2. static field (aka, class field, class variable): a static field is a field whose value is associated with the class itself.
  • parameter: a variable declared in the parameter list is called a parameter. The initial value of a parameter is determined by the arguments in the invocation. For example, in the code myName.setFirstName("Anita"), the argument is "Anita". If the method is defined as
      public void setFirstName(String first) { /*...*/ }
    then the value of the parameter first will be "Anita" during this execution of the method.
  • method (aka, function): a method is a specification of the behavior of an object. A method is defined at the top level in a class definition.
    1. instance method (aka, member function, method): an instance method is associated with instances of a class. When an instance method is called, the receiver must be an instance of the class.
    2. static method (aka, class method, class function): a static method is associated with the class itself. It has no receiver! This means that you cannot say this in a static method!
  • abstract: An abstract method is a method with no implementation. An interface is a class with no (non-static) fields and all of whose methods are abstract. You cannot call the constructor of an interface.
    An interface is like a contract.
  • implement: If a class implements an interface, that means that every instance of that class must have an implementation of each of the abstract methods in that interface.
    To implement an interface means to promise to uphold the contract.
  • override: to override a method means to write a method with the exact same signature as a method that already exists in a class. For example, when we write the toString() method, we are overriding the default toString() method.
  • inheritance: When one class extends another class, this is called inheritance. The new class is called the child class or subclass and the class being extended is called the parent class or superclass. We say that an instance of the child class is a(n) instance of the parent class. The child class inherits all of the methods and fields of the parent class. The child class can only access those fields and methods that are declared public or protected (or sometimes the default protection which is called "package".)
  • polymorphism: The feature of object-oriented languages that allows the exact method that is executed to be determined by the run-time type of the receiver.
  • abstract class: An abstract class is just like an ordinary class except that it might have abstract methods. A class that is not an interface or an abstract class is sometimes called a concrete class. A concrete class cannot have any abstract methods. All of its methods must have an implementation. Since abstract classes and interfaces might have abstract methods, you cannot call the constructor of an abstract class or of an interface. You may only call the constructor of a concrete class.
  • recursion: A method that calls itself is called a recursive method. A recursive method must have at least one base case, in which no recursive call is made, and at least one general case, in which a recursive call is made. The recursive calls must be made in a way that moves the problem closer to the base case. To "use recursion" means to solve a problem using a recursive method.
  • destructively modify (AKA modify): when a method makes a change to its receiver, we sometimes say that it "destructively modifies" (or "modifies") the receiver. We use this scary-sounding phrase because we want people who use the method to notice.
  • shared structure: Sometimes we say that two objects "share structure." This phrase reminds us that if we make certain changes to one of the objects, it will affect the other. For example, if two different linked list nodes have the same "next" reference, we say that the two linked lists "share structure" because if we (say) delete a node from one of the linked lists, it may affect the other.