Re: being or not being?
Mark Space <markspace@sbc.global.net> writes:
Stefan, are you a native English speaker?
No.
I'm not really sure what you're trying to say here. I can't
think of any programming language that uses words like
"activation", "operation expression".
Regarding ?operation?: This is a quotation from the Java
Language Specification, Third Edition:
?Neither a sleep for a period of zero time nor
a yield operation need have observable effects.?
- JLS3, 17.9
It speaks of a ?yield operation?, which seems to refer to
?java.lang.Thread.yield()?. So, if this is a ?yield operation?
by the Java Language Specification, it does not seem too far
fetched to call the expression for it an ?operation expression?.
Regarding ?activation?: Method invocation will create an
?activation frame?:
?At run time, method invocation requires five steps [...]
a new activation frame is created? - JLS3, 15.12.4
This shows that the notion of ?activation? is not totally
strange to the Java Language Specification.
But what I actually refer to when I use the noun ?activation?,
is the common English meaning of the noun ?activation?.
Evaluation is done when the compiler encounters the expression,
Actually, it happens at run time, not at compile time.
Otherwise, the value of all expressions would be known
at compile time.
You should verify all of this with the JLS, to make sure you
are using the correct terminology.
OK, I have tried to annotate my tutorial fragment with
references to the JLS3. For every term of the field, I have
given references to the JLS3 (usually in parentheses at the
end of a paragraph introducing this term). Here is what I have
written so far. (At the very end, I have used a wording
suggestion by Patricia Shanahan from this Usenet thread.)
*** A Java Tutorial (first part) ***
.----------
|The Java Language Specification, Third Edition
/Java Language Specification/
The Java Language Specification is the authoritative
specification of the programming language Java.
/JLS3/
The phrase ?Java Language Specification, Third Edition?
might be abbreviated as ?JLS3?.
The meaning of terms when discussing Java is given by the JLS3.
Statements by the JLS3 regarding Java are generally deemed
to be true.
When parts of the JLS3 are given as a reference, this might
be written as ?JLS3, 6.2?, for example. This means:
Java Language Specification, Third Edition, Chapter 6, Section 2.
In this text, some notions used are taken from the JLS3,
other sources or are being defined by this text. When a notion
is introduced, it is written on a line starting with a slash
and is terminated with a slash as, for example,
?/Java Language Specification/? above.
Sometimes a source is given for a notion. A source is
formatted as a quotation, thus it is indented relative
to common paragraphs as, for example, the following quotation,
which is a source for the role of the Java Language Specification:
?This book attempts a complete specification of
the syntax and semantics of the language.? -
JLS3, Preface
The source for a notion sometimes is given in parentheses
directly after the first explanation of that notion. It is
intended to be read if the reader is interested in it, but
otherwise might be skipped as well.
The complete text of the JLS3 can be read via the web.
It can be found using a search engine.
.----------
|Some programming terms
/Java implementation/
A system that is capable to execute programs
written in the Java language. The term is used, but
not defined in the JLS3, for example:
?We intend that the behavior of every language
construct is specified here, so that all
implementations will accept the same programs.?
JLS3, Preface
When a Java implementation behaves in some way, but
the JLS3 demands another behavior, the implementation (not the
specification) is deemed to be incorrect. The JLS3, not
any system claiming to be a Java implementation, is the
authoritative source for the specification of the programming
language Java.
/executable program/
An executable program (or just ?executable?) is a record of
information that can be read and used by a computer to control
the computer's actions.
controls
(executable program)-------------->[computer]
(The JLS3 does not literally contain the term ?executable program?,
but mentions the ?execution of programs? in JLS3, 13.4.6.)
/run time/
The time of the execution of an executable program also is
called ?run time?. (The JLS3 does not define the term ?run time?,
but uses it many times in this sense.)
/compiler/
An executable program often is generated by a compiler.
generates controls
[compiler]--------->(executable)--------->[computer]
(The JLS3 does not define the term ?compiler?, but uses it many
times in this sense.)
/source/
The compiler reads a record of information giving the properties
of the executable program to be generated. This record of information
therefore can be considered to be the source of the executable
program and thus it is called /source/.
reads generates controls
(source)--------->[compiler]--------->(executable)--------->[computer]
(The JLS3 does not define, but uses the term ?source? in this sense,
for example, in JLS3, 3.3.)
/source code/
The source for an executable program also is called source code.
A programmer usually writes source code - not an executable program,
because the language of the source code can be made more easy for
humans to write and understand than the language of executable programs.
(The JLS3 does not define, but uses the term ?source code? in this sense,
for example, in JLS3, 3.8.)
/source text/
Every part of source code that is text might be called ?source text?.
(The JLS3 does not define, but uses the term ?source text? in this sense,
for example, in JLS3, 3.3.)
/source file/
The source for an executable program also is called source file
(if it is a file).
(The JLS3 does not define, but uses the term ?source file? in this sense,
for example, in JLS3, 7.4.1.1, Discussion, or 13.4.8.)
/program/
The source for an executable program also is called a program.
It does not have to be an /executable/ program, so it can not control
the computer directly, but because it is used to generate an
executable program, it can indirectly control a computer.
(The JLS3 does not define, but uses the term ?program? in this sense,
for example, in the first sentence of JLS3, 2.)
/compilation unit/
Large programs might consist of several parts, each of which can
be compiled separately to give a piece of an executable program.
These parts are called ?compilation units?, because they are
compilable units. The small programs given at the start of this
tutorial also are compilation units: These programs consist of
only a single compilation unit. (The term is defined in JLS3, 7.3,
?Compilation Units?.)
/Java virtual machine/
A computer (?machine?) capable of executing compiled Java programs
also is called a Java machine. It does not have to be a physical
device, but might be a program simulating such a computer as well.
Such a simulated computer also is called a ?virtual machine?.
?A Java virtual machine starts up by loading a specified
class and then invoking the method main in this specified
class.? - JLS3, 12
.----------
|A simple compilation unit
The following compilation unit (3 lines) can be compiled to an
executable program that prints a so-called ?stack dump?. The
reader is not required to know, what a ?stack dump? is, it is
used here just as an example, because it can be programmed quite
easily.
public class Main
{ public static void main( final java.lang.String[] args )
{ java.lang.Thread.dumpStack(); }}
While not all details of this program can be explained immediatly,
a short explanation of it follows.
?public class Main?
This specifies the name of our program as ?Main?.
Actually it is a ?class? being called ?Main?, but in
this case it can be regarded to constitute the ?program?.
The word after ?public class? needs to match the start
of the filename ?Main.java? (in front of ?.java?).
?public static void main( final java.lang.String[] args )?
This introduces the section of the actual instructions and always
needs to be written in this (or in a very similar) way.
?java.lang.Thread.dumpStack();?
This tells the computer what to do when the program is being
execute. It will be executed after a process has been started
that is being controlled by the above program. When being
executed, it will ?dump? (i.e., write) the current ?stack?
(i.e., certain information about the current state of the
process the details of which do not matter for now).
.----------
|Compiling a compilation unit
To compile this program and execute the result of the compilation,
one needs to
- install the JDK (the Java Development Kit from Sun Microsystems, Inc.),
- add the bin-directory of the JDK to the PATH of the shell,
- write the above programm into a file ?Main.java?,
- open a text command shell, and
- compile the program by using the following command.
javac Main.java
The program then can be started with the following command.
java Main
The Command ?java? starts the Java virtual machine to execute the
program ?Main? (actually, ?Main? is a class as will be
discussed later).
The output of the program should look similar to the following text.
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1206)
at Main.main(Main.java:3)
Exercise:
Compile and run the program as being described above.
Hints:
If the program should not run, the following
conditions can be checked:
- The student needs to know some fundamental aspects of
his computer and operation system before attempting to
learn Java. For example, how to rename a file, how to
use a command line shell, how to use the keyboard, how
to create and edit a text file.
These topics are not treated here and needs to be learned
by other means.
- All commands needs to be typed in exactly as spelt above.
- The source file must have the name ?Main.java? needs to
reside in the current directory of the command shell.
No directory names should be written at the start of the
arguments of the commands.
- The environment variable ?CLASSPATH? should not have been
set to any value. Otherwise, it needs to be cleared.
- Under Windows:
- The current directory should not be on a virtual drive
created by ?subst? or be given by a UNC network path.
- The output of the command ?set? should not contain
?CLASSPATH?, the output of the command ?type Main.java?
should be the three lines of the program as given above.
Exercise:
Modify the program somehow and observe the behavior
of the compiler when it is invoked for the modified program.
.----------
|White Space
When a word (usually made up from letters) is followed by
another word, both words need to be separated. Such a
separation can be done by a space. Thus, one writes
?class Main?, not ?classMain?.
/white space/
Instead of a space an arbitrary combination of multiple
spaces and newlines (line separators) can be used, that
includes at least one space or newline. Such a combination
is called ?white space?. (?White Space? is the title of
JLS3, 3.6.)
White space is not needed, but allowed, on the left or
right of most special characters. Thus, the following
lines are all equivalent:
java.lang.Thread.dumpStack();
java . lang . Thread . dumpStack ( ) ;
One even is allowed to write this as follows.
java.
lang. Thread.dumpStack
() ;
White space must not be inserted within a word, so
?Thread? must not be written as ?Thre ad?.
Exercise:
Insert spaces and newline characters into
the above program or remove them to make it look
as strange as possible while still compiling and
printing a stack dump.
.----------
|Comments
/comment/
Wherever white space is allowed, a comments may be
inserted, that is essentially being ignored (?deleted?)
by the compiler. (?Comments? is the title of
JLS3, 3.7.)
A comment starts with ?/*? and ends with ?*/?.
public class Main /* This is a comment */
{ public static void main( final java.lang.String[] args )
{ /* Here is another /*
* comment */ java.lang.Thread.dumpStack(); }}
Exercise:
Remove all the comments from the above program, then
confirm that it still compiles and prints a stack dump.
Exercise:
Add some comments to the result of the last exercise and
confirm that it still compiles and prints a stack dump.
Finally, remove all comments.
.----------
|Expressions
Whenever someone wants to request something he has to designate
what it is that he requests. A program is such a designation.
/expression/
An expression is a source text that designates something
according to the rules of the language. (?Expressions? is the
title of JLS3, 15, the definition is given in JLS3, 15.27.)
A common form for expressions is as follows.
name()
This is a name followed by parentheses.
/the parentheses test/
Every expression of a program can always be enclosed into a
pair of an opening left parenthesis and a closing right
parenthesis without a modification in the behavior of the
program, that is, the program will still do the same as before.
So, to test whether something is an expression, it can be
enclosed in parentheses.
In the following program, the expression
?java.lang.Thread.dumpStack()? has been enclosed in a
pair of parentheses.
public class Main
{ public static void main( final java.lang.String[] args )
{ ( java.lang.Thread.dumpStack() ); }}
Exercise:
Try to run the above program so as to see whether the
expression ?java.lang.Thread.dumpStack()? passes the
parentheses test! Then try to find anything else that
can be enclosed into an additional pair of parentheses
(this should fail).
.----------
|Expressions and Operations
This lesson will deal with more details of expressions
written in the following form.
name()
/action/
A specific activity of the computer that begins at a certain
instant and ends at a certain instant is an action. An example
of an action is ?to switch on the light?. (The word ?action?
is used informally by the JLS3 in chapters 1-16, for example
?In some cases this will require a corresponding action at run
time? in JLS3, 5, or ?Each action either comes-before di or
comes-after di.? and ?An action a is an active use of X if and
only if at least one of the following conditions holds? in
JLS3, 12.6.1.1, or ?If the value is false, no further action
is taken and the if statement completes normally.? in JLS3,
14.9.1. In chapter 17 a more formal term ?action? is used,
for example ?it then attempts to perform a lock action on
that object's monitor? in JLS3, 17.1, section JLS3, 17.4.2
is titled ?Actions? and contains some examples of actions:
?An inter-thread action is an action performed by one thread
that can be detected or directly influenced by another thread.
There are several kinds of inter-thread action that a program
may perform: Read (normal, or non-volatile). Reading a variable.
Write (normal, or non-volatile). Writing a variable.? These
examples show that ?action? in the JLS3 has a meaning very
similar to the definition given here, but the notions might not
be exactly the same.)
/effect/
The modification of something is also called an effect.
An action might have an effect. For example, the action of
the stack dump might have the effect of a stack dump being
visible on the screen. (The word ?effect? is used informally
in the JLS3 with its common meaning in the English language
in chapter 1-13. In chapter 14, it is used in the sense given
here, for example, ?The sequence of execution of a program is
controlled by statements, which are executed for their effect?
- JLS3, 14. What is called ?effect? here, sometimes also is know
as ?side effect?, especially when it is used as an attribute
of the evaluation of an expression.)
/operation/
An operation describes an effect depending on certain preconditions
(a realization of a mapping from preconditions to postconditions).
For example, the operation ?toggle a switch? will turn on the
switch if it was turned off, but will turn off the switch if it
was turned on. These are two different actions. When an operation
is being activated (or executed) some action will happen, depending
on the state of the relevant system just prior to the activation.
(The term ?operation? is used in the JLS3 on the one hand to
describe what is written with an ?operator?, on the other hand,
it is used similar to the meaning given to it here (not only
referring to operators), but more informal, for example in
?This situation can only occur if the program performed some operation
that would give rise to an unchecked warning at compile-time.? -
JLS3, 14.12.2; ?an operation on this Point object might change its
state? - JLS3, 14.12.4; ?Execution of an operation that causes boxing
conversion? - JLS3, 12.5; ?the exit operation is not forbidden by the
security manager? - JLS, 12.8; ?Code is usually clearer when each
expression contains at most one side effect, as its outermost
operation? - JLS3, 15.7; ?If evaluation of a class instance creation
expression finds there is insufficient memory to perform the creation
operation, then an OutOfMemoryError is thrown.? - JLS3, 15.9.6;
?A thread t may lock a particular monitor multiple times; each unlock
reverses the effect of one lock operation.? - JLS3, 17.1;
?A later operation on the String object might see the correct offset
of 4? - JLS3, 17.5, Discussion; ?Neither a sleep for a period of zero
time nor a yield operation need have observable effects.? - JL3, 17.9.
This last use ?yield operation? is matching exactly the use of
?operation? in this tutorial.)
/activation/
An operation is active, when it actually happens. The activation
of an operation makes it happen. (The JLS3 does not use the term
?activation? directly, but it uses the related term ?activation
frame?: ?At run time, method invocation requires five steps [...]
a new activation frame is created? - JLS3, 15.12.4)
An expression might denote such an /operation/. For example,
the following expression denotes the operation ?dump the current
stack?.
java.lang.Thread.dumpStack()
The effect of this operation depends on the state of the process
because the stack might change in time, so its actual action and
effect might differ depending on the circumstances of the activation
of this operation. Therefore, this expression gives an operation,
not an action.
.----------
|The expression-statement
/evaluation/
The activation of an operation expression is called ?evaluation?.
It will activate the operation that is given by the expression.
(Section 15.1 of the JLS3 is titled ?Evaluation, Denotation, and
Result? and uses the term ?evaluation? with the same meaning as
this tutorial.)
For example, the evaluation of the expression
?java.lang.Thread.dumpStack()? activates the operation
?java.lang.Thread.dumpStack()?.