Top Banner
20.05.2003 java.lang.reflect.Modifie r 1 public interface native private abstract final strictfp synchroniz ed transient static volatile protected in Kürze „A Java keyword used in a class declaration to specify that a class may be inherited but not instantiated. An abstract class can have both implemented and abstract methods, which are not implemented in the abstract class, but in a subclass.“ Von abstrakten Klassen können keine Objekte gebildet werden. Sonst verhalten sie sich wie normale Klassen. Sie enthalten die gleichen Eigenschaften und können auch selbst von anderen Klassen erben. Sie dienen hauptsächlich als super- Klasse, um allen erbenden Klassen eine gemeinsame Basis aufzuzwingen.
30

Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

Apr 05, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 1

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java keyword used in a class declaration to specify that a class may be inherited but not instantiated. An abstract class can have both implemented and abstract methods, which are not implemented in the abstract class, but in a subclass.“

Von abstrakten Klassen können keine Objekte gebildet werden. Sonst verhalten sie sich wie normale Klassen. Sie enthalten die gleichen Eigenschaften und können auch selbst von anderen Klassen erben.Sie dienen hauptsächlich als super-Klasse, um allen erbenden Klassen eine gemeinsame Basis aufzuzwingen.

Page 2: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 2

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Beispiel: Eine abstrakte Klasse Kleidung ist die Oberklasse für konkrete Kleidungsstücke.

abstract class Kleidung{ public abstract void wasche();}

Mit dieser abstrakten Klasse drücken wir aus, dass es eine allgemeine Klasse ist, die selbst kein Kleidungsstück darstellt. Es macht also keinen Sinn, davon ein Objekt zu bilden. Das zeigt, dass Oberklassen allgemeiner gehalten sind, und die Unterklassen weiter spezialisieren.

Page 3: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 3

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

abstract class Kleidung{ boolean gewaschen;

public abstract void wasche();}

class Socken extends Kleidung{ /** Creates a new instance of Socken */ public Socken() { wasche(); System.out.println(gewaschen); } /** Implementierung von wasche() */ public void wasche(){ System.out.println("Sauber: "); }}

Page 4: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 4

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

abstract class Kleidung{ boolean gewaschen;

public abstract void wasche();}

class Socken extends Kleidung{ /** Creates a new instance of Socken */ public Socken() { wasche(); System.out.println(gewaschen); } /** Implementierung von wasche() */ public void wasche(){ System.out.println("Sauber: "); }}

Variablen dürfen nicht abstract sein

abstracte Methode, muss implementiert werden

gibt false aus

Page 5: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 5

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java language keyword that defines an entity which cannot be changed or derived from later. A final class cannot be subclassed, a final method cannot be overridden, and a final variable cannot be changed from its initialized value.“

Page 6: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 6

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Bei Variablen:

1. Der Inhalt von final-Variablen kann nicht geändert werden.

22 Müssen bei Deklaration auch initialisiert werden.

3. Bezeichner von final-Variablen werden als Konvention komplett in Großbuchstaben geschrieben.

Page 7: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 7

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Bei Variablen:

final-Variablen werden oft verwendet, um Zuständezu kodieren

final int FILE_NEW = 1;final int FILE_OPEN = 2;final int FILE_SAVE = 3;final int FILE_SAVEAS = 4;final int FILE_QUIT = 5;

Page 8: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 8

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

• Als final deklarierte Methoden können nicht mehr überschrieben werden

• Von final-Klassen kann nicht geerbt werden

Page 9: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 9

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„Interface Definition Language (IDL) provides interoperability and connectivity capabilities with CORBA (Common Object Request Broker Architecture) for the J2EE platform, enabling J2EE applications to invoke operations on remote network services using the Object Management Group (OMG) IDL and Internet Inter-Orb Protocol (IIOP).“

Page 10: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 10

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Ein interface gibt an, was eine Klasse, die sie implementiert, tun muß, aber nicht, wie sie es tun muß.

Interfaces und ihre Methoden sind entweder public oder default (siehe ‚in Kürze‘). Methoden werden nur deklariert, sie haben keinen Körper (ähnlich wie bei abstract). Variablen sind implizit final und static, d.h. ihr Wert muß bei der Deklaration angegeben werden und kann zur Laufzeit nicht mehr verändert werden.

Klassen können über ihr Interface angesprochen werden.

Page 11: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 11

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Bsp.:

public interface BerechneIF{ //IF (=interface) NamensKonvention int berechne(int a, int b); //kein Körper}

public class Summe implements BerechneIF{ public int berechne(int a, int b){ return a + b; //berechnen der Summe }}

public class Produkt implements BerechneIF{ public int berechne(int a, int b) { return a * b; //berechnen des Produktes }}

Page 12: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 12

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

public class Rechnen { //Methode erwartet Interface-Typ public void ausrechnen(BerechneIF rechnen){ System.out.println(rechnen.berechne(5, 10)); }}

public class Mathe { public static void main(String[] args){ //RechnenObjekt instanziieren Rechnen rechnen = new Rechnen(); //Methode bekommt Klassenobjekt, daß das //Interface implementiert hat rechnen.ausrechnen(new Summe()); //-> 15 rechnen.ausrechnen(new Produkt()); //-> 50 }}

Page 13: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 13

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java language keyword used in method declarations to specify that the method is implemented in another source file and in another programming language.“

Mit native werden Methoden gekennzeichnet, die in einer anderen Programmiersprache, typischerweise C/C++ oder Assembler, geschrieben sind.

Solche Methoden müssen ähnlich wie bei abstrakten Methoden deklariert, in einer DLL geschrieben und dann mit dem Java-Code verbunden werden.

Bsp.:public native int meth(); //Methodendeklaration

Page 14: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 14

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Hinweise:

• Sicherheitsrisiko: Nativer Code ist nicht auf die Java-VirtualMachine beschränkt (Zeiger-Problematik). Daher können Applets keine nativen Methoden verwenden. Auch das Laden von DLLs kann eingeschränkt sein.

• Verlust der Portabilität:Auf dem System, das den Java-Code ausführt, muss die DLL vorhanden und kompatibel sein.

Page 15: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 15

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java language keyword used in a method or variable declaration to signify that the method or variable can only be accessed by other elements of its class.“

Wenn ein Member einer Klasse private ist, dann kann auf dieses Member durch allen klasseneigenen Code zugegriffen werden.Innere Klassen haben Zugriff auf private-Member der umgebenen Klasse.

Page 16: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 16

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java language keyword used in a method or variable declaration and signifying that the method or variable can only be accessed by elements residing in its class, subclasses, or classes in the same package.“

Wenn ein Member einer Klasse protected ist, dann kann auf dieses Member durch Code innerhalb des package und außerhalb, sofern es sich um Unterklassen handelt, zugegriffen werden.

(Packages kapseln mehrere Klassen. Ein package ist eine weitere Ebene, um Java-Code zu strukturieren und Zugriffe zu kontrollieren.)

Page 17: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 17

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java language keyword used in a method or variable declaration and signifying that the method or variable can be accessed by elements residing in other classes.“

Wenn ein Member einer Klasse public ist, dann kann auf dieses Member durch allen anderen Code im Programm zugegriffen werden.

public static void main(String[] args){

Page 18: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 18

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java language keyword used to define a variable as a class variable. A class maintains a single copy of class variables which are shared by all instances of the class. The static keyword can also be used to define a method as a class method, which is invoked using the class, instead of a specific instance, and can only operate on class variables“

Page 19: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 19

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Normalerweise kann auf ein Klassen-Member (Variable oder Methode) nur in Verbindung mit einem Objekt zugegriffen werden.Wenn ein Member als static deklariert ist, kann darauf zugegriffen werden, bevor irgendwelche Objekt seiner Klasse erzeugt wurden.static-Variablen sind im wesentlichen global. Alle Instanzen einer Klasse teilen sich dieselbe static-Variable.

Page 20: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 20

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Bsp.:

System.out.println() ist static und kann daher aufgerufen werden, ohne das ein Objekt der Klasse PrintStream * instanziiert werden muß.

* (public final static PrintStream out in der Klasse System)

Page 21: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 21

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Einschränkungen von static-Methoden:

• Sie können nur andere static-Methoden aufrufen

• Sie dürfen nur auf static-Variablen zugreifen

• Sie können nicht auf this und super verweisen

Page 22: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 22

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Heutige Software ist modularisiert:

Oberfläche

Systemkern

Datenbank

Speicher

Das Design Pattern (bewährte Lösungen für typische Problemstellungen) ‚Singleton Pattern‘.

Page 23: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 23

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Nur die Datenbank-Klasse darf Daten schreiben und lesen. Gäbe es mehrere Objekte dieser Klasse, würde das zu Kollisionen führen.

Naive Lösung:Datenbank-Objekt bei Programmstart erstellen und an alle Klassen des Systemkerns per Konstruktor weiterreichen. Funktioniert, ist aber sehr unübersichtlich und führt zu überfüllten Konstruktoraufrufen

Page 24: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 24

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

Form des Singleton Patterns:

class DatenbankManager{

static DatenbankManager dm; //default-Wert = null

public static DatenbankManager getInstance(){ if(dm == null) //nur beim ersten Aufruf dm = new DatenbankManager(); //Objekt erstellen return dm; //ObjektVerweis zurückgeben }//end getInstance //Name getInstance nach Konvention

...}

//Klassen holen sich den Verweis so:DatenbankManager dm = DatenbankManager.getInstance();

Page 25: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 25

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„The strictfp keyword, added in the Java 2 SDK, forces floating point calculations in methods to operate in strict mode. [It] permit the exponent portion of intermediate results to be wider than the 32- or 64-bit size of the end result of the operation.“

• Da unter Windows default-mäßig nicht im strict-Modus gerechnet wird, kann strictfp hier die Laufzeit verbessern.

• In den meisten Fällen ist das Ergebnis einer strict-Rechnung gleich dem einer nicht-strict-Rechnung.

• Eher für wissenschaftliche Rechnungen gedacht.

Page 26: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 26

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java language keyword that, when applied to a method or statement block, guarantees that only one thread at a time executes that code.“

Wenn mehrere Threads gleichzeitig dieselbe Methode ausführen, kann es zu Problemen kommen. Mit synchronized gekennzeichnete Methoden stellen sicher, das immer nur ein Thread Zugriff hat. Erst, wenn dieser Thread die Methode verlassen hat, kann ein anderer Zugriff erhalten.

Page 27: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 27

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A keyword in the Java language that indicates that a field is not part of the serialized form of an object, i.e. the specified field is not written to persistent storage.“

transient-Attribute (Variablen) einer lese- / schreibfähigen Klassen, typischerweise für Drag&Drop oder Copy&Paste benutzt, werden nicht abgespeichert. Der Datenstrom ist also kleiner.

Page 28: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 28

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

„A Java language keyword used in variable declarations specifying that the variable is modified asynchronously by concurrently running threads.“

int kopie = 5;

volatile int master = 15;

Ein Thread

Noch ein Thread

kopie = 10, master = 15

kopie = 20, master = 15

Die Variable master ist volatile, damit haben alle Threads stets den gleichen Wert für master.Der Wert von kopie ist lokal, kann also abweichen.

Page 29: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 29

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

• abstractGarantiert in Klassenhierarchien eine gemeinsame Basis aller erbenden Klassen

• finalSorgt dafür, daß sich Werte und Methoden zur Laufzeit nicht verändern

• interfaceJavas Form der ‚Mehrfachvererbung‘

• staticKlassenattribut, unabhängig von Klassenobjekten

Page 30: Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1.

20.05.2003 java.lang.reflect.Modifier 30

public

interface

native

private

abstract

final

strictfp

synchronized

transient

static

volatile

protected

in Kürze

• Zugriffskontrolle

private default protected public

Selbe Klasse Ja Ja Ja Ja

Selbes Paket, Unterklasse

Nein Ja Ja Ja

Selbes Paket,

nicht Unterklasse

Nein Ja Ja Ja

Anderes Paket,

Unterklasse

Nein Nein Ja Ja

Anderes Paket,

nicht Unterklasse

Nein Nein Nein Ja