Untitled Flashcards Set

Unit 5 Classes Key Words, Classes & Methods

Object Class Methods

clone() Creates and returns a copy of this object. (protected method return : Object)

equals(Object obj) Indicates whether some other object is "equal to" this one. (return : boolean)

hashCode() Returns a hash code value for the object. (return : int)

toString() Returns a string representation of the object. (return : String)

Definitions

Class - A class defines a type and is used to define what all objects of that class know and can do.

Compiler - Software that translates the Java source code (ends in .java) into the Java class file (ends in .class).

Compile time error - An error that is found during the compilation. These are also called syntax errors.

Constructor - Used to initialize fields in a newly created object.

Field - A field holds data or a property - what an object knows or keeps track of.

Java - A programming language that you can use to tell a computer what to do.

Main Method - Where execution starts in a Java program.

Method - Defines behavior - what an object can do.

Object – Object is an instance of a class with defined attributes. Objects are declared as variables of a class type.

Syntax Error - A syntax error is an error in the specification of the program.

Instance Variable are the variables that belong to an object (instance of a class).

Local Variables are the variables that are declared inside of a methods and

constructors. Local variables are only accessible within those blocks and only exists

while that method is running.

Constructors initialize the attributes in newly created objects. They have the same

name as the class.

Signatures is the unique combination of both name and formal parameters for a

method or constructor.

Modifiers (public, private, protected, final, static) are modifiers that are used to

define the behavior, accessibility, and scope of classes, methods, and variables.

Overloading is when there is more than one constructor. They must differ in the

number, type, or order of parameters.

Overriding in Java occurs when a subclass implements a method which is already defined in the superclass or Base Class.

Default constructor is a constructor that doesn’t take any parameters.

Parameters allow values to be passed to the constructor to initialize the newly

created object’s attributes.

Parameter list, in the header of a constructor or method, is a list of the type of the

value being passed and a variable name. These variables are called the formal

Parameters.

Actual parameters are the values being passed to a constructor or method.

Formal parameters are the specified variables in the header of a constructor or a

method. They act as placeholders for actual parameters. Example :

World(int width, int height).

Call by value means that when you pass a value to a constructor or method it

passes a copy of the value of the actual parameters.

Dot operator is used to access the member methods and variables of a class or an

instance of that class. Examples: object.method(); or Class.method(); or

Class.variable

Procedural abstraction allows a programmer to use a method by knowing in

general what it does but without knowing how it does it.

NullPointerException will happen if you try to call an object method on an object

variable whose value is null. This usually means that you forgot to create the object

using the new operator followed by the class name and parentheses.

Object method or non-static method belongs to an object or a particular instance

of the class and not the class itself.

Static method belongs to the class and not a particular

instance of the class.

data encapsulation where the data and the code acting on the data are wrapped together into a single unit and the implementation details are hidden.

Getters/Setters public methods in a class that are used to return or set private instance/class variables that

KEYWORDS

class -the class keyword is used to define a new class

public - a visibility keyword which is used to control the classes that have access. The keyword public means the code in any class has direct access.

private - a visibility keyword which is used to control the classes that have access. The keyword private means that only the code in the current class has direct access.

new- new is a keyword that is used to create a new object of a class. The syntax

is new ClassName(). It creates a new object of the specified class and calls a

Constructor.

static- used to designate that a class member belongs to the class and not a single object.

final- a keyword used to indicate that a variable, method, or class cannot be modified or extended. (A final name should be in all capitals)

return- the return keyword finishes the execution of a method, and can be used to return a value from a method.

void- The void keyword specifies that a method should not have a return value.