Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

Verteilte Software - Java - Prozedurale Programmierung 1

Ähnliche Präsentationen


Präsentation zum Thema: "Verteilte Software - Java - Prozedurale Programmierung 1"—  Präsentation transkript:

1 Verteilte Software - Java - Prozedurale Programmierung 1
Datenbezug Ablaufsteuerung Objektbezug boolean byte char (const) double false final float int long short static transient true void break case catch continue default do else finally for (goto) if return switch synchronized throw throws try while abstract class extends implements import instanceof interface native new null package private protected public super this volatile Schlüssel- worte Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

2 Verteilte Software - Java - Prozedurale Programmierung 2
// elementare Datentypen public class el_dt { public static void main(String args []) byte b = 127; short s = 32767; int i = ; long l = L, l0; float f = e+38f; double d = e+308; char c = 'j'; boolean bool = true; l0 = 0; System.out.println ("byte\tb = " + b); System.out.println ("short\ts = " + s); System.out.println ("int\ti = " + i); System.out.println ("long\tl = " + l); System.out.println ("long\tl0 = " + l0); System.out.println ("char\tc = " + c); System.out.println ("float\tf = " + f); System.out.println ("double\td = " + d); System.out.println ("boolean\tbool = " + bool); } byte b = 127 short s = 32767 int i = long l = long l0 = 0 char c = j float f = e+038 double d = e+308 boolean bool = true Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

3 Verteilte Software - Java - Prozedurale Programmierung 3
// Zeichenketten und Modifizierer public class zk_mod { static String static_text = "Zeichenketten"; public static void main(String args []) String s1 = "Arbeit "; String s2; s2 = "mit "; System.out.println (s1 + s2); System.out.println (static_text + " (" + static_text.length() + " Zeichen)" ); static_text = "Umlauten"; } Arbeit mit Zeichenketten (13 Zeichen) Umlauten (8 Zeichen) Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

4 Verteilte Software - Java - Prozedurale Programmierung 4
1 () [] . lv++ lv-- links nach rechts 2 ! ~ -unär +unär ++lv --lv rechts nach links 3 new (type) 4 * / % 5 + - 6 << >> >>> 7 < <= > >= instanceof 8 == != 9 & 10 ^ 11 | 12 && 13 || 14 ?: 15 = += -= *= /= %= ^= &= |= <<= >>= >>>= Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

5 Verteilte Software - Java - Prozedurale Programmierung 5
Alternativen bedingte Verarbeitung if ( Bedingung ) Anweisung einfache Alternative if ( Bedingung ) Anweisung_1 else Anweisung_2 mehrfache Alternative switch (Ausdruck) { case const_ausdruck_1 : Anweisungen case const_ausdruck_2 : Anweisungen : case const_ausdruck_n : Anweisungen default : Anweisungen } Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

6 Verteilte Software - Java - Prozedurale Programmierung 6
// Alternativen public class alt { public static void main(String args []) short i1 = 33; int i2 = 58; char antwort; boolean b = false; if (i1 == i2) System.out.println (i1 + " gleich " + i2); else System.out.println (i1 + " ungleich " + i2); if (i1 != i2 && !b) antwort = 'v'; b = 'z' >= antwort; if (b) System.out.println ('z' + " >= " + antwort); switch (antwort) case 'e': System.out.println ("Eingabe"); break; case 'v': System.out.println ("Verarbeitung"); break; case 'a': System.out.println ("Ausgabe"); break; default: System.out.println ("Fehler"); } 33 ungleich 58 z >= v Verarbeitung Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

7 Verteilte Software - Java - Prozedurale Programmierung 7
Iteration Abweisschleife while ( Bedingung ) Anweisung Zählschleife for ( Initialisierung; Bedingung; Ausdruck ) Anweisung Nichtabweisschleife do Anweisung while (Bedingung); Steuerung von Schleifen continue break continue label break label Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

8 Verteilte Software - Java - Prozedurale Programmierung 8
// Iteration public class iter { public static void main(String args[]) { int i; double zahl = 0; char c; String text; c = 'a'; text = ""; while (c <= 'm') { text += c; c++; } System.out.println (text); for (c = 'z', text = ""; c >= 'n'; c--) text += c; i = 100; do { i = (i - 6) / 2; if (i == 0) continue; if (i % 6 == 1) break; zahl = 1000 / i; System.out.println ( " / " + i + " = " + zahl); } while ( zahl > 0 ); abcdefghijklm zyxwvutsrqpon 1000 / 47 = 1000 / 20 = 50 Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

9 Verteilte Software - Java - Prozedurale Programmierung 9
Ausnahmebehandlung Deklaration [modifier] typ name ( [Parameterliste] ) [throws Typnamenliste] { Vereinbarungen und Anweisungen } Ausnahmeobjekt auswerfen throw objekt try-catch-Anweisung try { Anweisungen } catch ( Ausnahme oa1 ) {Anweisungen bei Ausnahme oa1} catch ( Ausnahme oa2 ) {Anweisungen bei Ausnahme oa2} : catch ( Ausnahme oan ) {Anweisungen bei Ausnahme oan} [finally { Anweisungen als abschließende Maßnahmen }] Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

10 Verteilte Software - Java - Prozedurale Programmierung 10
// Ausnahme import java.lang.Error; public class ausnahme { static Error s = new Error ("Ziffer"); public static void main(String args[]) { int i; for (i = 2; i > -3; i--) try { System.out.println (100 + " / " + i + " = " + 100/i); } catch (ArithmeticException e) { System.out.println (e); } finally { System.out.println ("fertig"); }; { alfa_zeichen('a'); alfa_zeichen('4'); alfa_zeichen('b'); catch (Error x) { System.out.println ("!!! FEHLER !!! " + x); static void alfa_zeichen (char z) throws Error { if (z >= '0' && z <= '9') throw s; System.out.println (z); 100 / 2 = 50 fertig 100 / 1 = 100 java.lang.ArithmeticException: / by zero 100 / -1 = -100 100 / -2 = -50 a !!! FEHLER !!! java.lang.Error: Ziffer java.lang.Error: Ziffer Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik

11 Verteilte Software - Java - Prozedurale Programmierung 11
// Feld public class feld { final static int MAX = 4; public static void main(String args[]) { int i, j, x [], y [], matrix [] []; x = new int[MAX]; y = new int[MAX]; matrix = new int [MAX][MAX]; for (i = 0; i < MAX; i++) { x[i] = i; y[i] = (i * 2) % MAX;} printvec(x); printvec(y); for (i = 0; i < matrix.length; i++) for (j = 0; j < matrix[i].length; j++) matrix[i][j] = (x[i] + y[j]) % MAX; System.out.println ("MODULOSUMME"); { for (j = 0; j < MAX; j++) System.out.print (matrix[i][j] + " "); System.out.println (); } static void printvec (int[] z) { for (int i = 0; i < z.length; i++) System.out.print (z[i] + " "); MODULOSUMME Prof. Dr.-Ing. habil. B. Steinbach - Informatik / Softwaretechnologie und Programmierungstechnik - Institut für Informatik


Herunterladen ppt "Verteilte Software - Java - Prozedurale Programmierung 1"

Ähnliche Präsentationen


Google-Anzeigen