These are working notes and are being revised daily. I am
open to corrections and improvements.
[ java.syntax.html ]
[ java.glossary.html ]
Data in Java
In Java there is a split between basic data types (int,char,...) and Objects [ Basic Data Types ] [ Objects] . A value, literal, variable,.... is always either one or the other. There is no overlap or confusion allowed. Further basic data types are privileged to be manipulated by operators. Objects are uniquely privileged to be manipulated by methods. Data types have many literals, but the only literal Object is
nullHowever both Objects and basic data types can be the parameters and results of functions and can be stored in variables (or constants).
The basic types also have an interpretation, a set of constant values that can be coded in the language, and a large number of predefined operations.
. . . . . . . . . ( end of section Basic Data Types) <<Contents | Index>>
[ Arrays in java.classes ]
The basic types are not Objects. Basic type values are
not values of Objects. Objects have user defined "methods"
but basic data types do not.
Objects do not have any operators(like +,-,...). All
Objects are extended from the class Object. The symbol
nullis a special value indicating that an Object has no value or does not exist. This value null can be assigned to an object of any class, but can not be assigned to any basic data type. However several basic data types have a class of of Objects associated with them. However several basic data types have a class of of Objects associated with them [ Object in java.classes ]
There are a few classes of Object that encapsulate numeric
[ Number in java.classes ]
Conversions between classes and types
The same name can be used to refer to different functions. The
correct one is chosen by matching the call the functions with
the same name and same number of arguments. The returned type
is ignored. Perfectly matching types select the best method. However
Java permits approximate matches - a byte for example may cast
to a short if better match is found. This is governed by an
arcane table of costs.
Creating new objects
Objects are destroyed and recycled by finalization.
. . . . . . . . . ( end of section Interfaces) <<Contents | Index>>
Programmer Defined Classes
Each class defines a set of fields and a set of methods. The fields define the state of the objects. The methods define what the class will do to the state of the object. Methods can be accessible only with a class, within the same package, or only with derived classes, or by any part of any program...
. . . . . . . . . ( end of section Programmer Defined Classes) <<Contents | Index>>
B x = new C();
B x = new B();
x.M(A); // calls C.M
y.M(A); // calls B.M
Static Method Invocation
A static method M of class C is called like this C.M(A) and if
within scope the M found in the definition of C is invoked with
arguments A passed by value. A static method of class C, invoked
inside class C's definition can be written 'M(A)' and have the same effect.
The variable this
In a class the variable this refers to the currant object
whose method is being executed. An expression or statement of form
In the piece of the source code that defines class C, an expression
Notice that this.M(A) can call a different method M if this is actually an object in a subclass of C.
. . . . . . . . . ( end of section Method invocations) <<Contents | Index>>
[ java.glossary.html ]
. . . . . . . . . ( end of section Some Preliminary Steps Towards a Semantics for the Java Language) <<Contents | Index>>