.Open Some Preliminary Steps Towards a Semantics for the Java Language . Note Two question marks `??` indicate that I haven't found the data yet. If you have found the answer in any official documentation please send it to dick@csci.csusb.edu where it will be incorporated with an acknowledgment. These are working notes and are being revised daily. I am open to corrections and improvements. .See ../mailme.html Also see .See http://www/dick/samples/java.syntax.html and .See http://www/dick/samples/java.glossary.html . Data in Java data::=object| Basic_data_type. In Java there is a split between basic data types (int,char,...) and Objects .See Basic Data Types .See 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 .As_is null However both Objects and basic data types can be the parameters and results of functions and can be stored in variables (or constants). .Open Basic Data Types A type has a ready made symbol or name that is used to declare its variables. It has a size (in bits). It has a number of operators (prefix, postfix, and infix. There are certain functions and operators that return the values of that type. 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. types::=numeric | character | boolean. numeric::=integer | floating. floating::=float | double. integer::= byte | short | int | long. character::= following .Net symbol="char". size=16.bits. comment=`Unsigned 16 bit, not ASCII but 16 bit $UNICODE`. interpretation=0..2^16-1. .Close.Net numeric::=following .Net symbol="byte" | "short"|"int"|"long". if symbol="byte"then size=8.bits. if symbol="short"then size=16.bits. if symbol="int"then size=32.bits. if symbol="long"then size=64.bits. interpretation=binary(length=>size, signed). Assigning a longer number into a short variable is done modulo the shorter size. operators= .See http://www/dick/samples/java.syntax.html#Expressions .Close.Net boolean::=following .Net symbol="boolean". size=1.bits. storage=??. values={"true", "false"}. prefix={"!"}. infix={"&&", "||"}. priority= /("&&", "||"). postfix={}. from_infix={"<", "<=", "==", "!=", ">=", ">"}. No conversion to numeric types. .Close.Net double::=following .Net symbol="double", size=64.bits. comment=IEEE 754. .Close.Net float::=following .Net symbol="float", size=32.bits. IEEE 754. .Close.Net .See http://www/dick/samples/java.classes.html#Math .Close Basic Data Types . Arrays .See http://www/dick/samples/java.classes.html#Arrays . Objects 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 .As_is null is 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 .See http://www/dick/samples/java.classes.html#Object There are a few classes of Object that encapsulate numeric basic types: .See http://www/dick/samples/java.classes.html#Number . Conversions between classes and types cast::syntax= "(" classname ")" ref_to_object If `B` is a subclass of `A` and `b` is a reference to an object of type `B` and a one of type `A`, then `(A)b` casts `b` into an `A` and `(B)a` casts `b` as an `A`. . Overloading 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 creation ::syntax= "new" C "(" arguments ")" the arguments are passed to a ,matching constructor function in class C C "(" formal_arguments ")". Objects are destroyed and recycled by `finalization`. .Open Interfaces An interface describes how a class can be used without describing how the class carries out the work. Several classes can have one interface. An interface can be formed by mixing in several other interfaces. All methods in an interface are public, variables can by public, private, or static. Methods in interfaces are without modifiers and function bodies. .Close Interfaces .Open Programmer Defined Classes A programmer programs in Java solely by creating new classes. New classes are created by extending existing classes. The default is to extend the class Object. All classes - predefined or programmer created are extensions of the class Object. A new class can also implement zero or more $interfaces. 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... .Close Programmer Defined Classes .Open Method invocations If an object `x` has class `C` and `C` has a method `M` with the right arguments and in the right scope then x.M(A) invokes method M of class C(`C.M`) on the `x`s data. The class `C` is determined dynamically. So if C is actually a subclass of `B` and 'x' is declared to be in `B` but is actually set to a `C` then it is `C.M` that is invoked. For example: .As_is B x = new C(); .As_is B x = new B(); .As_is x.M(A); // calls C.M .As_is 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 this.M(A) applies method M, with arguments A(called by value). The actual method invoked is determined dynamically by the class of object that `this` is. . Local Methods In the piece of the source code that defines class C, an expression of form M(A) is interpreted as calling `C.M(A)` - class C's method `M` with arguments `A` (called by value). Notice that `this.M(A)` can call a different method M if `this` is actually an object in a subclass of C. .Close Method invocations . See Also .See http://www/dick/samples/java.glossary.html UNICODE::=http://www.csci.csusb.edu/dick/samples/comp.text.ASCII.html#Introduction. .Close Some Preliminary Steps Towards a Semantics for the Java Language