Pascal for Java users/de: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | 1 | Zurück zu den [[Additional information/de|Zusätzlichen Informationen]].\ | |
| 3 | - | ||
| 2 | + | ||
| 4 | 3 | =Übersetzen von gemeinsamen Programm-Teilen= Die verlinkte englischsprachige Seite zeigt, wie gemeinsame Probleme in verschiedenen Programmiersprachen, einschließlich Java und FreePascal / Object Pascal gelöst werden können.\ | |
| 5 | 4 | [Rosetta Code](http://rosettacode.org/wiki/Category:Pascal) | |
| 6 | 5 | ||
| 7 | 6 | # Übersetzen von Java-Operatoren | |
| 8 | 7 | ||
| 9 | 8 | ## Arithmetische Operatoren | |
| 10 | 9 | ||
| 11 | 10 | | Java | Pascal | Kommentare | | |
| 12 | 11 | |------|--------|-----------------------------------| | |
| 13 | 12 | | + | + | Addition | | |
| 14 | 13 | | - | - | Subtraktion | | |
| 15 | 14 | | * | * | Multiplikation | | |
| 16 | 15 | | / | / | Gleitkommadivision | | |
| 17 | 16 | | % | Mod | Modulo (Division ohne Rest) | | |
| 18 | 17 | | ++ | Inc | inkrementieren (Hochzählen) | | |
| 19 | 18 | | -- | Dec | dekrementieren (Herunterzählen) | | |
| 20 | 19 | ||
| 21 | 20 | ## Relationale Operatoren | |
| 22 | 21 | ||
| 23 | 22 | | Java | Pascal | Kommentare | | |
| 24 | 23 | |-------|--------|------------------| | |
| 25 | 24 | | == | = | gleich | | |
| 26 | 25 | | != | \<\> | ungleich | | |
| 27 | 26 | | \< | \< | kleiner | | |
| 28 | 27 | | \<= | \<= | kleiner gleich | | |
| 29 | 28 | | \> | \> | grösser | | |
| 30 | 29 | | \>= | \>= | grösser gleich | | |
| 31 | 30 | ||
| 32 | 31 | ## Logische Operatoren | |
| 33 | 32 | ||
| 34 | - | ||
| 35 | 33 | <thead> | |
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 34 | + | ||
| 41 | 35 | </thead> | |
| 42 | 36 | <tbody> | |
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 37 | + | ||
| 52 | 38 | In Free Pascal ist dies die Standard-Compilereinstellung</td> | |
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 62 | - | ||
| 39 | + | ||
| 63 | 40 | In Free Pascal ist dies die Compilerdirektive {$B ON}</td> | |
| 64 | - | ||
| 65 | - | ||
| 66 | - | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - | ||
| 41 | + | ||
| 75 | 42 | </tbody> | |
| 76 | - | ||
| 77 | 43 | ||
| 78 | 44 | ## Bit Operatoren | |
| 79 | 45 | ||
| 80 | 46 | | Java | Pascal | Kommentare | | |
| 81 | 47 | |----|----|----| | |
| 82 | 48 | | ~ | Not | Einerkomplement | | |
| 83 | 49 | | & | And | bitweises UND | | |
| 84 | 50 | | \| | Or | bitweises inclusives ODER | | |
| 85 | 51 | | ^ | Xor | bitweises exclusives ODER | | |
| 86 | 52 | | \>\> | Shr | bitweises Rechtsschieben mit Vorzeichen | | |
| 87 | 53 | | \>\>\> | ist in Free Pascal nicht vorhanden | bitweises Rechtsschieben ohne Vorzeichen | | |
| 88 | 54 | | \<\< | Shl | bitweises Linksschieben | | |
| 89 | 55 | ||
| 90 | 56 | ## Zuweisungs Operatoren | |
| 91 | 57 | ||
| 92 | 58 | Hinweis: C-artige Operatoren werden in Free Pascal über die Kommandozeilenoption -Sc ermöglicht. C-artige Operatoren werden in Lazarus über die Projekteinstellungen ermöglicht.\ | |
| 93 | 59 | {\| class="wikitable" ! Java !! Pascal !! Kommentare \|- \| = \| := \| Einfache Zuweisung \|- \| += \| += \| Additionszuweisung \|- \| -= \| -= \| Subtraktionszuweisung \|- \| *= \| *= \| Multiplikationszuweisung \|- \| /= \| /= \| Divisionszuweisung \|- \| %= \| ist in Free Pascal nicht vorhanden \| Modulo Zuweisung \|- \| &= \| ist in Free Pascal nicht vorhanden \| UND Zuweisung \|- \| \|= \| ist in Free Pascal nicht vorhanden \| ODER Zuweisung \|- \| ^= \| ist in Free Pascal nicht vorhanden \| Exclusive ODER Zuweisung \|- \| \>\>= \| ist in Free Pascal nicht vorhanden \| Rechtsschiebe Zuweisung \|- \| \>\>\>= \| ist in Free Pascal nicht vorhanden \| Rechtsschiebe Zuweisung mit Nullexpansion \|- \| \<\<= \| ist in Free Pascal nicht vorhanden \| Linksschiebe Zuweisung \|} | |
| 94 | 60 | ||
| 95 | 61 | ## Sonstige Operatoren | |
| 96 | 62 | ||
| 97 | 63 | | Java | Pascal | | | |
| 98 | 64 | |------|--------|--------------------| | |
| 99 | 65 | | & | @ | Adresse von ... | | |
| 100 | 66 | | * | ^ | Zeiger / Pointer | | |
| 101 | 67 | ||
| 102 | 68 | ## Ternärer Operator | |
| 103 | 69 | ||
| 104 | - | ||
| 105 | 70 | {\| class="wikitable" ! Java !! Pascal !! Kommentare \|- \| ? \| ist in Free Pascal nicht vorhanden \| Erlaubt die verkürzte Schreibweise von If-Else Verzweigungen und gibt einen Wert zurück\ | |
| 106 | 71 | Verwendung:\ | |
| 107 | - | ||
| 72 | + | Ergebnisfeld = Bedingung ? Wahrfall : Falschfall\ | |
| 108 | 73 | \ | |
| 109 | 74 | Beispiel:\ | |
| 110 | 75 | Für ein Maximum in Java:\ | |
| 111 | 76 | max = ( a \> b ) ? a : b;\ | |
| 112 | 77 | \ | |
| 113 | 78 | Dies entspricht in Pascal folgendem if-else-Konstrukt:\ | |
| 114 | 79 | if a \> b Then\ | |
| 115 | 80 | max := a\ | |
| 116 | 81 | else\ | |
| 117 | 82 | max := b;\ | |
| 118 | 83 | \|} | |
| 119 | 84 | ||
| 120 | 85 | # Übersetzen von Java Kommentarzeichen | |
| 121 | 86 | ||
| 122 | 87 | | Java | Pascal | Kommentare | | |
| 123 | 88 | |-------|--------|---------------------------| | |
| 124 | 89 | | /* | { | Anfang eines Kommentars | | |
| 125 | 90 | | /* | (* | Anfang eines Kommentars | | |
| 126 | 91 | | */ | } | Ende eines Kommentars | | |
| 127 | 92 | | */ | *) | Ende eines Kommentars | | |
| 128 | 93 | | // | // | Kommentarzeile | | |
| 129 | 94 | ||
| 130 | 95 | # Übersetzen von Java Anweisungsblöcken | |
| 131 | 96 | ||
| 132 | 97 | | Java | Pascal | Kommentare | | |
| 133 | 98 | |------|---------|-------------------------------------------| | |
| 134 | 99 | | { | Begin | Anfang eines Anweisungsblocks | | |
| 135 | 100 | | } | End | Ende / Abschluss eines Anweisungsblocks | | |
| 136 | 101 | ||
| 137 | 102 | # Übersetzen von Java Schleifentypen | |
| 138 | 103 | ||
| 139 | 104 | | Java | Pascal | Kommentare | | |
| 140 | 105 | |----|----|----| | |
| 141 | 106 | | for( ...; ...; ...++) | For ... To ... Do | Kopfgesteuerte Schleife, die hochgezählt wird | | |
| 142 | 107 | | for(...; ...; ...--) | For ... Downto ... Do | Kopfgesteuerte Schleife, die heruntergezählt wird | | |
| 143 | 108 | | for (Datentyp ...: Array) // For Each Schleife | For ... in | Kopfgesteuerte Schleife, für das Durchsuchen von Mengen | | |
| 144 | 109 | | while (...) | While ... Do | Kopfgesteuerte Schleife | | |
| 145 | 110 | | do ... while(...) | Repeat ... Until | Fussgesteuerte Schleife | | |
| 146 | 111 | | do ... while!(...) | Repeat ... Until ... Not | Fussgesteuerte Schleife mit Nichtung des Ergebnisses des Ausdrucks | | |
| 147 | 112 | ||
| 148 | 113 | # Übersetzen von Java Verzweigungen / Bedingungen | |
| 149 | 114 | ||
| 150 | 115 | | Java | Pascal | Kommentare | | |
| 151 | 116 | |----|----|----| | |
| 152 | 117 | | if(...) | If ... Then | If-Bedingung | | |
| 153 | 118 | | if(...) ... else | If ... Then ... Else | If-Bedingung mit Sonstzweig | | |
| 154 | 119 | | switch(...) case ...: ...break; | Case ... Of ...: ... End; | Case-Bedingung | | |
| 155 | 120 | | switch(...) case ...: ... break; default ...; | Case ... Of ...: ... Else ... End; | Case-Bedingung mit Sonst-Zweig | | |
| 156 | 121 | ||
| 157 | 122 | # Übersetzen von Java Verzweigungen- / Schleifenabbrüchen | |
| 158 | 123 | ||
| 159 | 124 | | Java | Pascal | Kommentare | | |
| 160 | 125 | |----|----|----| | |
| 161 | 126 | | break | Break | Die break-Anweisung ermöglicht es, vorzeitig eine Schleife (oder ein switch-case-Konstrukt) zu verlassen | | |
| 162 | 127 | | continue | Continue | Die continue-Anweisung ermöglicht es, den aktuellen Schleifendurchlauf zu beenden | | |
| 163 | 128 | ||
| 164 | 129 | # Übersetzen von Java Prozeduren und Funktionen | |
| 165 | 130 | ||
| 166 | 131 | | Java | Pascal | Kommentare | | |
| 167 | 132 | |----|----|----| | |
| 168 | 133 | | void Prozedurname(...) | Procedure Prozedurname(...) | Unterprogramm (Prozedur) ohne Rückgabewert | | |
| 169 | 134 | | datentyp Funktionsname(...) | Function Funktionsname(...): Datentyp | Unterprogramm (Funktion) mit Rückgabewert | | |
| 170 | 135 | | return | FunctionName := ... | Diese Pascal-Schreibweise ist überholt (deprecated) | | |
| 171 | 136 | | return | Result := ... | Einer Funktion Ihren Rückgabewert zuweisen | | |
| 172 | 137 | ||
| 173 | 138 | # Übersetzen von Java Dateiheadern | |
| 174 | 139 | ||
| 175 | 140 | | Java | Pascal | Kommentare | | |
| 176 | 141 | |----|----|----| | |
| 177 | 142 | | package ...; | Unit ...; | Einbinden der Pascal Unit bzw. des Java Packages | | |
| 178 | 143 | | import ...; | Uses ...; | Bindet Bibliotheken und Klassen ein | | |
| 179 | 144 | | public static void main(String\[...\] args) {...} | Program ProgramName; Begin ... End. | Hauptprogramm | | |
| 180 | 145 | ||
| 181 | 146 | # Übersetzen von Java Datentypen | |
| 182 | 147 | ||
| 183 | 148 | | Java Datentyp | Pascal Datentyp | Speichergrösse in Bits | Range | | |
| 184 | 149 | |----|----|----|----| | |
| 185 | 150 | | byte | Shortint | 8-Bit | -128 .. 127 | | |
| 186 | 151 | | short | SmallInt | 16-Bit | -32768 .. 32767 | | |
| 187 | 152 | | int | LongInt | 32-Bit | -2147483648..2147483647 | | |
| 188 | 153 | | long | Int64 | 64-Bit | -9 223 372 036 854 775 808 .. 9 223 372 036 854 775 807 | | |
| 189 | 154 | | float | Single | 32-Bit | 1.5E-45 .. 3.4E+38 | | |
| 190 | 155 | | double | Double | 64-Bit | 5.0E-324 .. 1.7E+308 | | |
| 191 | 156 | | boolean | Boolean | 8-Bit | False bzw. True | | |
| 192 | 157 | | char | WideChar | 16-Bit | 2 Bytes codieren ein sichtbares Zeichen | | |
| 193 | 158 | | String | WideString | 0-Bit bis ∞ | Zeichenkette | | |
| 194 | 159 | ||
| 195 | 160 | # Übersetzen von Java Aufzählungen (Enumerationen) | |
| 196 | 161 | ||
| 197 | - | ||
| 198 | 162 | <thead> | |
| 199 | - | ||
| 200 | - | ||
| 201 | - | ||
| 202 | - | ||
| 203 | - | ||
| 163 | + | ||
| 204 | 164 | </thead> | |
| 205 | 165 | <tbody> | |
| 206 | - | ||
| 207 | - | ||
| 208 | - | ||
| 209 | - | ||
| 166 | + | ||
| 210 | 167 | Die Konstante MAXVALUE enthält den Wert 1</td> | |
| 211 | - | ||
| 168 | + | ||
| 212 | 169 | </tbody> | |
| 213 | - | ||
| 214 | 170 | ||
| 215 | 171 | # Übersetzen von Java Arrays | |
| 216 | 172 | ||
| 217 | 173 | | Java | Pascal | Kommentare | | |
| 218 | 174 | |----|----|----| | |
| 219 | 175 | | Datentyp\[\] arrayName = new Datentyp\[...\]; | Datentyp: Array\[...\] Of Datentyp; | | | |
| 220 | 176 | | Datentyp arrayVar\[...\] = new Datentyp\[...\]; | Datentyp: Array\[...\] Of Datentyp; | | | |
| 221 | 177 | ||
| 222 | 178 | # Übersetzen der Java Objektorientierung | |
| 223 | 179 | ||
| 224 | - | ||
| 225 | 180 | <thead> | |
| 226 | - | ||
| 227 | - | ||
| 228 | - | ||
| 229 | - | ||
| 230 | - | ||
| 181 | + | ||
| 231 | 182 | </thead> | |
| 232 | 183 | <tbody> | |
| 233 | - | ||
| 234 | - | ||
| 235 | - | ||
| 236 | - | ||
| 237 | - | ||
| 238 | - | ||
| 239 | - | ||
| 240 | - | ||
| 241 | - | ||
| 242 | - | ||
| 243 | - | ||
| 244 | - | ||
| 245 | - | ||
| 246 | - | ||
| 247 | - | ||
| 248 | - | ||
| 249 | - | ||
| 250 | - | ||
| 251 | - | ||
| 184 | + | ||
| 252 | 185 | In Free Pascal ist der Name des Konstruktors Create</td> | |
| 253 | - | ||
| 254 | - | ||
| 255 | - | ||
| 256 | - | ||
| 257 | - | ||
| 258 | - | ||
| 259 | - | ||
| 260 | - | ||
| 261 | - | ||
| 262 | - | ||
| 263 | - | ||
| 264 | - | ||
| 265 | - | ||
| 266 | - | ||
| 267 | - | ||
| 268 | - | ||
| 269 | - | ||
| 270 | - | ||
| 271 | - | ||
| 272 | - | ||
| 273 | - | ||
| 274 | - | ||
| 275 | - | ||
| 276 | - | ||
| 277 | - | ||
| 278 | - | ||
| 279 | - | ||
| 280 | - | ||
| 281 | - | ||
| 282 | - | ||
| 283 | - | ||
| 284 | - | ||
| 285 | - | ||
| 286 | - | ||
| 287 | - | ||
| 288 | - | ||
| 289 | - | ||
| 290 | - | ||
| 291 | - | ||
| 292 | - | ||
| 293 | - | ||
| 294 | - | ||
| 295 | - | ||
| 296 | - | ||
| 297 | - | ||
| 298 | - | ||
| 299 | - | ||
| 300 | - | ||
| 301 | - | ||
| 302 | - | ||
| 303 | - | ||
| 304 | - | ||
| 305 | - | ||
| 306 | - | ||
| 307 | - | ||
| 308 | - | ||
| 309 | - | ||
| 310 | - | ||
| 311 | - | ||
| 312 | - | ||
| 313 | - | ||
| 314 | - | ||
| 315 | - | ||
| 316 | - | ||
| 317 | - | ||
| 318 | - | ||
| 319 | - | ||
| 320 | - | ||
| 321 | - | ||
| 322 | - | ||
| 323 | - | ||
| 324 | - | ||
| 325 | - | ||
| 326 | - | ||
| 327 | - | ||
| 328 | - | ||
| 329 | - | ||
| 330 | - | ||
| 331 | - | ||
| 332 | - | ||
| 333 | - | ||
| 186 | + | ||
| 334 | 187 | </tbody> | |
| 335 | - | ||
| 336 | 188 | ||
| 337 | 189 | ## Freigabe eines Objektes | |
| 338 | 190 | ||
| 339 | - | ||
| 340 | 191 | <thead> | |
| 341 | - | ||
| 342 | - | ||
| 343 | - | ||
| 344 | - | ||
| 345 | - | ||
| 192 | + | ||
| 346 | 193 | </thead> | |
| 347 | 194 | <tbody> | |
| 348 | - | ||
| 349 | - | ||
| 350 | - | ||
| 351 | - | ||
| 195 | + | ||
| 352 | 196 | In Pascal führt der Aufruf FreeAndNil(...) zum selben Ergebnis.</td> | |
| 353 | - | ||
| 197 | + | ||
| 354 | 198 | </tbody> | |
| 355 | - | ||
| 356 | 199 | ||
| 357 | 200 | ## Klassenbestimmung | |
| 358 | 201 | ||
| 359 | 202 | | Java | Pascal | Kommentare | | |
| 360 | 203 | |--------------|--------|----------------------------------------------------| | |
| 361 | 204 | | instanceof | Is | Bestimmt die Klassenzugehörigkeit eines Objektes | | |
| 362 | 205 | ||
| 363 | 206 | ## Werfen von Exceptions | |
| 364 | 207 | ||
| 365 | 208 | | Java | Pascal | Kommentare | | |
| 366 | 209 | |----|----|----| | |
| 367 | 210 | | throw | Raise | Wirft eine Exception | | |
| 368 | 211 | | throws | ist in Free Pascal nicht vorhanden | Gibt im Methodenkopf einer Klasse oder Methode an, welche Ausnahme(n) von der Klasse bzw. Methode ausgelöst werden kann. | | |
| 369 | 212 | ||
| 370 | 213 | ## Fangen von Exceptions | |
| 371 | 214 | ||
| 372 | 215 | | Java | Pascal | Kommentare | | |
| 373 | 216 | |----|----|----| | |
| 374 | 217 | | try { ... } catch { ... } | Try Begin ... End Except Begin ... End | Fehlerbehandlung mit einem Try-Block | | |
| 375 | 218 | | try { ... } catch { ... } finally { ... } | begin ... try try ... except ... end; finally ... end; ... end; | Fehlerbehandlung mit einem Block für Abschlussarbeiten | | |
| 376 | 219 | ||
| 377 | 220 | ## Threadprogrammierung | |
| 378 | 221 | ||
| 379 | - | ||
| 380 | 222 | <thead> | |
| 381 | - | ||
| 382 | - | ||
| 383 | - | ||
| 384 | - | ||
| 385 | - | ||
| 223 | + | ||
| 386 | 224 | </thead> | |
| 387 | 225 | <tbody> | |
| 388 | - | ||
| 389 | - | ||
| 390 | - | ||
| 391 | - | ||
| 392 | - | ||
| 393 | - | ||
| 394 | - | ||
| 395 | - | ||
| 396 | - | ||
| 226 | + | ||
| 397 | 227 | In Free Pascal sind alle global definierten Variablen volatile.</td> | |
| 398 | - | ||
| 228 | + | ||
| 399 | 229 | </tbody> | |
| 400 | - | ||
| 401 | 230 | ||
| 402 | 231 | # Aufruf von Fremdfunktionen (z. B. aus Dll's) | |
| 403 | 232 | ||
| 404 | 233 | | Java | Pascal | Kommentare | | |
| 405 | 234 | |----------|-----------|-----------------------------------------| | |
| 406 | 235 | | native | StdCall | Pascal / FPC Standardaufrufkonvention | | |
| 407 | 236 | | native | CDecl | C Standardaufrufkonvention | | |
| 408 | 237 | ||
| 409 | - | ||
| 410 | - | ||
| 411 | 238 | --Olaf 14:28, 24 March 2013 (UTC) | |
| 412 | 239 | ||
| 413 | 240 | --- | |
| 414 | 241 | *From the Free Pascal wiki, page "Pascal for Java users/de", as it stood on 2014-01-12 after a change by Olaf, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 415 | 242 | Category: Code/de | |
| 416 | 243 | Category: Deutsch |
