Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

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

Ähnliche Präsentationen


Präsentation zum Thema: "Public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1."—  Präsentation transkript:

1 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier1 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.

2 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier2 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.

3 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier3 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: "); }

4 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier4 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

5 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier5 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.

6 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier6 Bei Variablen: 1.Der Inhalt von final-Variablen kann nicht geändert werden. 2. Müssen bei Deklaration auch initialisiert werden. 3.Bezeichner von final-Variablen werden als Konvention komplett in Großbuchstaben geschrieben.

7 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier7 Bei Variablen: final-Variablen werden oft verwendet, um Zustände zu 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;

8 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier8 Als final deklarierte Methoden können nicht mehr überschrieben werden Von final-Klassen kann nicht geerbt werden

9 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier9 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).

10 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier10 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.Kürze Klassen können über ihr Interface angesprochen werden.

11 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier11 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 }

12 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier12 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 }

13 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier13 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

14 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier14 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.

15 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier15 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.

16 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier16 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.)

17 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier17 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){

18 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier18 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

19 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier19 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.

20 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier20 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)

21 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier21 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

22 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier22 Heutige Software ist modularisiert: Oberfläche Systemkern Datenbank Speicher Das Design Pattern (bewährte Lösungen für typische Problemstellungen) Singleton Pattern.

23 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier23 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

24 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier24 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();

25 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier25 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.

26 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier26 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.

27 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier27 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.

28 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier28 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.

29 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier29 abstract Garantiert in Klassenhierarchien eine gemeinsame Basis aller erbenden Klassen final Sorgt dafür, daß sich Werte und Methoden zur Laufzeit nicht verändern interface Javas Form der Mehrfachvererbung static Klassenattribut, unabhängig von Klassenobjekten

30 public interface native private abstract final strictfp synchronized transient static volatile protected in KürzeKürze 20.05.2003java.lang.reflect.Modifier30 Zugriffskontrolle privatedefaultprotectedpublic Selbe KlasseJa Selbes Paket, Unterklasse NeinJa Selbes Paket, nicht Unterklasse NeinJa Anderes Paket, Unterklasse Nein Ja Anderes Paket, nicht Unterklasse Nein Ja


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

Ähnliche Präsentationen


Google-Anzeigen