Einführung in Operationen in Java im Rahmen der Lehre des Programmierens mit der Programmiersprache Java. [] (Operationen in Java java.lang.Thread.dumpStack Java Semikolon Java Ausdruckanweisung Java Klammern Java), Lektion, Seite 720333
http://www.purl.org/stefan_ram/pub/operationen-in-java (Permalink) ist die kanonische URI dieser Seite.
Stefan Ram

Operationen in Java

Operationen

Eine Aktion  eines Systems ist ein Eingriff, den das System an einem anderen System vornimmt. Beispielsweise ist das Falten eines Blattes Papier durch einen Menschen ein Eingriff, den dieser Mensch an dem Blatt vornimmt, also eine Aktion dieses Menschen.

Eine Aktion

.--------------------------------.
| Aktion |
'--------------------------------'
| Eingriff
V
System

Oft werden Aktionen an Hand gewisser Regeln  vorgenommen. Um alle Blätter aus einem Stapel von Papier einmal zu falten, sollte beispielsweise die Regel beachtet werden, daß ein Blatt nur dann einmal gefaltet wird, wenn es nicht schon gefaltet ist. Der Zustand eines Blattes soll also berücksichtig werden, bevor er verändert wird.

Der Zustand  eines Systems vor einem bestimmten Zeitpunkt wird auch Vorzustand  genannt, der Zustand danach Nachzustand.

Aktionen, die nach Regeln ablaufen, werden hier Operationen  genannt. Man kann also sagen, daß eine Operation unter Beachtung eines Vorzustandes einen Nachzustand produziert.

Eine Operation mit Vorzustand und Nachzustand

|
V Vorzustand
.--------------------------------.
| Operation |
'--------------------------------'
| Nachzustand
V

In der Programmiersprache Java  können Ausdrücke  verwendet werden, um Operationen anzugeben.

Der Ausdruck »java.lang.Thread.dumpStack()« gibt beispielsweise eine Operation an. Daher kann man auch von der Operation  »java.lang.Thread.dumpStack()« sprechen.

Diese Operation erzeugt einen Bericht auf einem Ausgabegerät, der den Zustand des Stapels zum Zeitpunkt der Aktivierung dieser Operation ausgibt. Der Stapel ist ein Bereichs des Speichers, in dem ein Teil des aktuellen Zustands des Programms vermerkt wird.

Würde dieselbe Operation bei einem anderen  Stapelzustand aktiviert werden, könnte ein anderer  Bericht ausgegeben werden. Die bei der Aktivierung der Operation ausgeführte Aktion hängt also vom Zustand des Stapels ab. Insofern berücksichtigt die Operation  »java.lang.Thread.dumpStack()« ihren Vorzustand.

Die Operation »java.lang.Thread.dumpStack()«

Stapel und
betriebsbereites Ausgabegerät
|
V Vorzustand
.--------------------------------.
| java.lang.Thread.dumpStack() |
'--------------------------------'
| Nachzustand
V
unveränderter Stapel und
Ausgabegerät mit einem
ausgegebenen Stapelbericht

In dem schon bekannten Programmbeispiel enthält die Ausgabe der Operation beispielsweise die Zahl 3 (das ist ihr Nachzustand), weil die Operation in der Zeile 3 aktiviert wurde (das ist ihr Vorzustand).

Main.java
public class Main
{ public static void main( java.lang.String[] args )
{ java.lang.Thread.dumpStack(); }}
Konsole
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1206)
at Main.main(Main.java:3)

Die schon bekannten Regeln der Formatierung von Java erlauben es, das Programm so umzuformatieren, daß dieselbe Operation in einer anderen Zeile aktiviert wird. Man sieht an der Ausgabe, daß diese Änderung des Vorzustandes  sich auch auf den Nachzustand  der Operation auswirkt und die Zahl 4 in der Ausgabe erscheint. Diesmal hat dieselbe Operation also eine andere Aktion bewirkt.

Main.java
public class Main
{ public static void main( java.lang.String[] args )
{
java.lang.Thread.dumpStack(); }}
Konsole
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1206)
at Main.main(Main.java:4)

Übungsfragen

/    Wirkung einer Operation
Die Wirkung der Aktivierung einer Operation
o … ist immer gleich.
o … kann von den Umständen abhängen.

Anhang *

(Dieser Anhang enthält Ergänzungen, die normalerweise nicht gelesen, sondern ignoriert werden sollten. Dieses Material kann im Bedarfsfall zur Klärung von Nachfragen zu Details dienen.)

Begriffe

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 valuation 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 very close to the use of »operation« in this tutorial. The notion here is taken from the field of abstract datatypes, which are related to object-oriented programming and Java programming. UML also uses this term. The notion used here is consistent with

ISO 2382-2

"Information technology-Vocabulary-Part 2: Arithmetic and logic operations"

"02.10.01

operation

A well-defined action that, when applied to any permissible combination of known entities, produces a new entity.

and

ISO/IEC 2382-15, SECOND EDITION / 1998, 15 PROGRAMMING LANGUAGES

15.04.02

abstract data type

ADT (abbreviation)

A class of data structures described by a list of operations or features available in the data structures and the formal properties of these operations, with the interfaces separated from the internal implementation.

15.06.31

generic operation

An operation that is overloaded and does not designate one specific operation but rather provides formal parameters for actual parameters of specific data types.

Example: The lexical token "+" may mean integer addition, real addition, set union, concatenation, etc.

15.09.05

object (in programming languages)

A set of operations and data that store and retain the effect of the operations.

NOTE - Objects are implemented as packages or tasks in Ada, as "modules" in Modula-2, and as "objects" in Smalltalk.

15.09.06

message (in programming languages)

A request for an object to perform one of its operations.

15.09.08

method (in programming languages)

An operation that an object * executes upon receipt of a message.

15.09.09

class (in programming languages)

A template for objects that defines the internal structure and the set of operations for instances of such objects.)

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)

Seiteninformationen und Impressum   |   Mitteilungsformular  |   "ram@zedat.fu-berlin.de" (ohne die Anführungszeichen) ist die Netzpostadresse von Stefan Ram.   |   Eine Verbindung zur Stefan-Ram-Startseite befindet sich oben auf dieser Seite hinter dem Text "Stefan Ram".)  |   Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram. Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram720333 stefan_ram:720333 slrprd, slrprdqxx, slrprddoc, slrprd720333, slrprddef720333, PbclevtugFgrsnaEnz

Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten.
http://www.purl.org/stefan_ram/pub/operationen-in-java