Vous êtes sur la page 1sur 7

Accessibility Modifiers

Are used with the definition of a class, it's methods, instance and class variables to specify which other objects can access those types. E.g. ' public class Jim { private int a; public int getA() { return a; } }' Are used to request information from an object when invoked (e.g. values of instance variables), but should not change the objects state.

Accessor Methods

Actual Arguments

Term used to refer to the actual values passed as arguments to a method when it is invoked on an object. E.g. 'abird.fly(10, 12);'
Uses several letters (mnemonic symbols) to represent registers and opcodes, rather than raw machine code which is entirely numeric. More human readable and can help with understanding / memory during development.
Gives values to variables in the form 'variable = expression;'. Expression must deliver a value that can be stored in the variable (otherwise, compiler error). The '=' in Java does not represent equivalence but is an assignment operator.

Assembly Code

Assignment Statement

boolean

(George Boole - Mathematical Logic) primitive data type that only has two possible values, true or false, which can be the result of a logical expression. Often used with accessor functions that are named as if they ask a question, e.g. 'public boolean isFlying() { return false; }'.

bytecode

Java compiles source code (.java) to its intermediate generic machine code called bytecode (.class).
Extending a class is part of a strategy to increase code re-use and reduce the amount of code to be maintained (don't repeat yourself).

Class Extension

Class Hierarchy

Diagram showing inheritance relationships between classes. In UML classes are shown as named boxes with subclasses showing lines with arrows pointing to their superclass.
Start with upper-case letter, then lower-case. However, each new word within the class name should start with and upper-case letter (camel). E.g. 'JonAttribute'. Conceptually classes are usually named using one or more nouns...because they define objects !.

Class Naming Convention

Compilation

Translates (Translation Unit) a program from source code (written in a programming language) to native code that can be executed by the target platform (effectively machine code for the CPU and native OS calls).

Composite Objects

Objects whose state contains 1 or more additional objects.


Constructors can be defined with arguments like any method. E.g. 'public Bird(int startX, int startY) { xPos = startX; yPos = startY; }'. Would be invoked if the appropriate actual arguments matched the type and number of the formal arguments (see method signature). E.g. 'Bird abird = new Bird(10, 12);'. Can be used to give an object a specific initial state when it is created with 'new'. Not strictly a method and is only invoked using the class-name and new, e.g. 'Bird a bird = new Bird()' invokes the constructor defined by 'public Bird() {}'.

Constructor Arguments

Constructors

covariant return type

An overriding method can also return a subtype of the type returned by the overridden method. This is called a covariant return type.

default constructor

Java provides a default constructor which takes no arguments and performs no special actions or initializations (although it calls the superclass empty constructor), when no explicit constructors are provided.

Delimiters

A token that specifies the boundaries between separate, independent regions of text. In Java, curly brackets are used, for example, to specify the body of a class definition, the method body of a concrete method and even the body and scope of a loop (for).

Disassembler

Takes java bytecode and displays corresponding source code. Note that usually a disassembler takes machine code (entirely numeric operation codes) and converts it into assembly language.
When defining a method, you can specify the arguments that it takes. These are specified with types and identifiers, like other variables. In this sense are considered in contrast to 'actual arguments' which are the values passed into the method when it is invoked. E.g. 'public void fly(int destX, int destY)' Integrated Development Environment. Convenience tool that will hide details such as compiler/debugger used, names of java files at various stages of building. However, will add features such as code formatting / colouring / completion. Hierarchical file views of source and resources, debugger with variable inspector etc.

Formal Arguments

IDE

Identifiers and case-sensitivity

Java identifiers are case-sensitive. So this should b taken into account when naming identifiers.
Where access to object instance variables is restricted by only allowing the use of methods which restrict use of an object to how the author intended rather than it being able to make use of implementation details. In this way, a maintaining programmer can change the internals of a class (e.g. instance variables, method bodies) without changing the external interface (method names and arguments) and even add to it !. Changes are therefore localised and the rest of the software system that uses the class can remain as it was.

Information Hiding

Inheritance

A relationship between classes and a key part of OOs approach to code re-use. An inheriting class will be similar to it's super-class but is effectively extending and specialising the super-classes data structure and possible operations. It can add data to that inherited from the super-class, as well as adding to and modifying inherited methods from the super-class.

Instance variables

Standard term for variable that belong to each instance of an object, sometimes also called member variables. These are declared within a class definition. These are opposed to local variables declared within a method body, or class variables which are static and belong to the class rather than being instantiated for each object.

Interpreter

An interpreter can be written, relatively easily, for any platform - it translates bytecode to native machine code at run-time so that it can be executed on that computer. Whereby java code requests that a given operation (ie. method) is performed on a given object which is then executed. E.g. 'object.aMethod();'

Invoking a method

Invoking a Method on a Reference Variable Java Applets

It is possible to invoke a method on a given object instance of a class by using a reference variable assigned to that object and a '.'. E.g. 'abird.fly();' would invoke the method 'fly' on the object referenced by 'abird'. Note that this is possible because the method is defined by the objects class type, or one of it's super-classes.
Java programs that can be run within a java-enabled browser by embedding them in HTML (which references the Applet executable). Were initially used to make dynamic web content (HTML is largely about displaying passive data, forms aside). Actually download and run the application over a network rather than having to install it. Are often digitally signed (to verify who wrote them - security) or run in a sandbox environment so that they can't access or change the host computer (security).

Java Applications

Standalone java programs which require the JRE (Java Runtime Environment), as opposed to Applets which require a Java-enabled browser.

Java Class

A structure that defines both the stored data and program code that is associated with a group of similar objects (common properties). Ie. common state structure (not state itself, the values can vary) and operations used by a group of objects.

Java Declaration

Specify the type and then the identifier(s). E.g. 'int a, b, c;'. This causes the Java system to allocate 3 memory locations and could either be undefined (locals) or set to their default (instance variables). Declarations can be combined with assignment statements (see later).

JDK

Java (Software) Development Kit. Contains compiler, interpreter, javadoc processor, debugger, disassembler, appletviewer.
Used to define a class. Roughly of the form 'class [Identifier] { [Data declarations] [Method Definitions] }'. Note that data can be declared and not defined (in this case it will take default values ie. null/zero).

Keyword 'class'

Keyword 'extends'

Used to define an inheritance relationship between a subclass and its superclass. In the form 'class A extends B {}' when the class is defined.

Keyword 'new'

Used to create an object instance for a given class. E.g. 'Bird abird = new Bird();' will allocate memory for the data required by an object of class type 'Bird'. this statement then assigns the address of this data to the reference variable 'abird'. In this way, 'abird' references the new Bird object.
Used within the body of a method that returns a value. Therefore it must be followed by an expression that returns a value that is of the type declared in the method header. E.g. 'public int birdWeight() { return birdWeight; }' would be fine, as long as the variable identifier 'birdWeight' was declared with the primitive data type 'int'.

Keyword 'return'

Keywords and case-sensitivity

Java keywords are always in lowercase, e.g. 'class, for, public, switch'.
The entry/starting point for a Java program and defined in the manifest. Clearly needed because object methods need to be invoked from somewhere. Hence a class is defined that has a main method, which will be the first method to be called. Of the form 'public static void main (String[] args) {}'. Note that the method is static, it is a class method. Ie. an object of that class doesn't need to exist. The String array contains the command line arguments passed by the OS.

main method

Method Arguments

Used to supply information as part of the request for an operation to be invoked on an object. Are contained within brackets, e.g 'object.aMethod('a', 1)'. Methods can have any (?) number of arguments. Similar to variable, lower-case for first letter, then upper-case for start of new words. Note that they usually start with a verb. E.g. 'increaseSpeed'.

Method Naming Convention

Method Return Values

Define what type of value a method will return. Can be set to the keyword 'void' if the method doesn't return a value. Usually of the form '[accessibility modifier] [return-type] [method-name] ( [arguments] )'. Followed by either a ';' for an abstract method, or the method body, enclosed curly-bracket delimiters '{...}'.

Method Signature

Includes the name of the method along with the number, order and type of its arguments. Basically what is required to invoke the method.

Multiple Inheritance

Not possible in Java or C# as opposed to C++. Can be approximated by the use of 'Interfaces' and inner-classes.
A type of method which, when invoked on an object, will change the objects state (ie. the value of the data associated with the object that defines it - instance variables).
Where classes in a hierarchy may have more than one method with the same name although their signatures must vary by the number and/or types of its arguments. The method implementation chosen to execute therefore depends on the types given on invocation. A method can't be overloaded by having two methods with the same argument pattern and name but different return types. At the point of invocation, this will not be enough information for the compiler to decide which method to invoke. Compile error !.

Mutator Method

Overloading

Overloading and Return Type

Overloading with different argument pattern AND different return type. Overriding

For most programming languages that support method overloading (Java, C#, C++, ...), if the parameter types are different, then the return types can also be different.
Where subclass can modify the body of the methods that it inherits from its superclass (but not the method signatures, which should remain the same, including the return type). Simply involves redefining the method in the sub-class using the same signature and return type.

Pattern of arguments

Describes the number and type of formal arguments defined, or actual arguments used. Pattern depends on the number and type of arguments (and order).

Portability

Describes the way that one program can run on many different platforms. Could be ported by hand, recompiled for each platform, or interpreted to nativecode at run-time.

Primitive Data Types

Simple types such as integer, floating point, boolean, character as opposed to complex 'object' types which may be made up of many primitive types and even other objects.
Declared by using any class identifier, these can be used to refer to an object instance but aren't objects in themselves but references (internally they contain memory addresses to the objects location, something like smart pointers and are involved in ref-counting for garbage collection). E.g. 'Bird abird;' would allocated a memory location for a reference to an object of class type 'Bird'. To define the reference variable we need to assign it to an instantiated object (either an existing object, or in combination with the 'new' operator to create a new object).

Reference Variables

State

Refers to the value of data associated with an object at any one point in time. Object state can be defined by it's instance variables (and class variables.?). State can change.

State change

In OO, usually an objects state should only be changed by invoking a method.


Term used to refer to a class further down the inheritance hierarchy from the inherited class (super-class). Ie. used to refer to the class that is inheriting. In UML, the arrow would point from the subclass to its inherited super-class. Subclasses extend their superclass.

Subclass

Superclass

Term used to refer to a class further up the inheritance hierarchy from an inheriting class (sub-class). In UML the super-class is pointed to by its inheriting sub-classes. Superclasses are extended by their subclasses.

Superclass Constructor

The most basic situation for this is that a superclass constructor is called automatically before the subclass constructor. (there are ways of having finer control over which constructor).
If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.

superclass constructor

this and constructors

It is possible to call one constructor from another within a class using 'this(..);' but it must be at the beginning of the constructor.

UML

Unified Modelling Language

Using return values

When invoking a method with a return value on an object, the return value will be discarded once the statement is complete unless it is assigned to a variable of the appropriate type. For example 'int birdResult = abird.birdWeight();' would assign the value of the method return value to the variable identified by 'birdResult;'.

Variable Naming Convention

Start with a lower-case letter but then use upper-case for the start of any new word in the name (camel). E.g. 'speedMeasure'.

Vous aimerez peut-être aussi