Topic
V Notes on Java Ontology
V Overview
* We write Java programs in text files called source files (ending with the extension ".java") using an editor. The Java compiler translates these source files into files called object files (ending with the extension ".class"), containing codes that can actually be run on the computer. Once compiled, the object files can be run repeatedly, copied, and distributed to others. On modern computers, the values, references, and even the instruction codes which make up a running Java system are represented inside the machine by sequences of bits (0s and 1s) held in a linear, sequential memory.
V Syntax, semantics and pragmatics
* The syntax of Java describes how it is written down in a program; it has significance at compile time, when the program is translated into codes that can be run. The semantics of a Java program is its meaning, the manner in which it creates and successive changes various Java objects when it is run. These objects cooperate to produce a Java system at run time. Pragmatics refers to both the practical aspects of working with Java and to conventional and recommended usage patterns.
V Values of primitive type and expressions
* Values of primitive type are simple, “atomic” values such as integers, booleans and characters. They may be written as literals ("constants" such as numerals or quoted characters) or may be the results of applying operators (like + or *) or method applications. They are stored directly in Java variables (objects are stored by reference; see below). In the syntax, parentheses are used to show grouping.
V Statements
* Statements are written instructions which constitute the bulk of a Java program. They include loops, if statements, switch statements and sequences of instructions strung together with semi-colons. The meanings of statements are the actions, successive changes to objects and references, which occur over time in the running Java program.
V Methods and method calls
* Methods are abstractions which capture an algorithm as a process relative to some parameters. Method calls constitute one form of expression (a method name followed by actual arguments in parentheses, separated by commas) and signify the running of the body (statements) of a method after binding the actual arguments to the method's parameters.
V Variables
* Variables are named, types "slots" or "boxes", containers into which a Java primitive value or object reference can be stored. The whole point of a variable, unless it is marked final, is that the value associated with the name (put in the slot or box) can change over time. Variables are changed by assignment or, in the special case of parameters, by binding to an actual argument when a method or constructor is called. When a variable is assigned, the old value stored is over-written and lost.
V Objects
* Objects are collections of data values and references held in named "slots" (i.e., variables), along with certain capabilities, i.e., actions that can be performed upon request (realized as methods). The capabilities do not vary from object to object but are rather manifested in a class, so that all objects of the same class have the same methods; they also have the same structure of named slots. Since methods may be parameterized on an object's data values, how a method actually runs may depend not only on a specific object but even on how its member "slots" are filled at a given time.
V References to objects
* Java variables do not hold objects directly, but rather hold references to objects. A reference is like the address of a place where the actual value is held: we draw references as arrows in diagrams. Several different variables may reference the same Java object, so that changes made to the object are "visible" through any variable referring to it. When a reference is over-written by an assignment, other variables may still refer to the same object; but when all references to the object are gone, it can no longer be used by the program (and it will be "garbage-collected" or its space reclaimed by the system).
V Classes
* A class definition is written into a Java file of the same name: it provides a "structure-and-capabilities" description of objects that will be created according to this "template". The structure is given by a set of typed variable names (slots) that can hold values or references; the capabilities are given by method definitions that may be called "on" the object or from within it. When calling a method on an object from the outside, we write a reference to the object followed by a dot (.)
V Sub-classes and inheritance
* One class may be declared to extend another: the extending class is called a sub-class, the extended one its super-class. The sub-class includes (as a template) all of the named slots (variables) and capabilities (methods) of the
V Method signatures
* A method signature constitutes most of what we informally call a method header: it includes the method’s return type, its name, and the types of its parameters. Although the names of the parameters are also written in, so that the signature looks like a method header, they are not actually relevant for matching the signature.
V Modifiers
V Modifiers on Java declarations include public vs. private, static (versus non-static, the default), and final
* public members are visible from outside the object, private ones are not
* static members are associated with (held by) the class, not by individual instances
* final values
* Interfaces
* Implementation of interfaces
* Abstract classes
* Exceptions