Pascal for Java users: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Pascal for Java users
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Translating common program snippets | |
| 2 | + | ||
| 3 | + | The following site shows how common problems are solved in various programming languages, including Javan and FreePascal/Object Pascal: [Rosetta Code](http://rosettacode.org/wiki/Category:Pascal) | |
| 4 | + | ||
| 5 | + | ## Translating Java keywords/concepts | |
| 6 | + | ||
| 7 | + | | Java | [[Pascal]] | Additional comments | | |
| 8 | + | |----|----|----| | |
| 9 | + | | { | [[Begin]] | | | |
| 10 | + | | } | [[End]] | | | |
| 11 | + | | = | := | [[Becomes]] | | |
| 12 | + | | == | = | [[Equal]] | | |
| 13 | + | | / | / | [[Slash|Division]] (or sometimes [[Div|div]]) | | |
| 14 | + | | % | [[Mod]] | **Mod**ulo operation | | |
| 15 | + | | ! | [[Not]] | | | |
| 16 | + | | != | \<\> | [[Not equal]] | | |
| 17 | + | | && | [[And]] | | | |
| 18 | + | | \<nowiki\> | | [[Or]] | | |
| 19 | + | | ^ | [[Xor]] | | | |
| 20 | + | | \>\> | [[Shr]] | bit **sh**ift **r**ight | | |
| 21 | + | | \<\< | [[Shl]] | bit **sh**ift **l**eft | | |
| 22 | + | | ++ | [[Inc]] | | | |
| 23 | + | | -- | [[Dec]] | | | |
| 24 | + | | /* | { | [[Comments|Comment]] start | | |
| 25 | + | | /* | (* | [[Comments|Comment]] start | | |
| 26 | + | | */ | } | Comment end | | |
| 27 | + | | */ | *) | Comment end | | |
| 28 | + | | // | // | End of line comment (only one line comment) | | |
| 29 | + | | public static void main(String\[\] args) { } | [[Program]] ProgramName; [[Begin]] [[End]]. | Note the period after End | | |
| 30 | + | | someType arrayVar\[\]; | arrayVar: [[Array]] [[Of]] someType; | | | |
| 31 | + | | someType arrayVar\[#\]; | arrayVar: [[Array]]\[MINRANGE..MAXRANGE\] [[Of]] someType; | | | |
| 32 | + | | null | [[Nil]] | | | |
| 33 | + | | abstract | [[Abstract]] | | | |
| 34 | + | | break | [[Break]] | | | |
| 35 | + | | class TheClass { } | TheClass = [[Class]] [[End]]; | Delphi OOP | | |
| 36 | + | | class TheClass { } | TheClass = [[Object]] [[End]]; | Turbo Pascal OOP | | |
| 37 | + | | class TheClass\<T\> { } | [[Generic]] TheClass = [[Class]]\<T\> [[End]]; | Generics are classes only as of 2.2.2, likely to support more in the future | | |
| 38 | + | | TheClass() | [[Constructor]] CtorName | Constructor name is by convention either Init or Create | | |
| 39 | + | | continue | [[Continue]] | | | |
| 40 | + | | do while | [[Repeat]] [[Until]] [[Not]] | | | |
| 41 | + | | do while ! | [[Repeat]] [[Until]] | | | |
| 42 | + | | enum TheEnum | TheEnum = ( MINVALUE .. MAXVALUE ); | | | |
| 43 | + | | enum TheEnum = {MINVALUE, MAXVALUE} | TheEnum = ( MINVALUE, MAXVALUE ); | | | |
| 44 | + | | TheEnum enumVar; | enumVar := [[Set]] [[Of]] TheEnum; | | | |
| 45 | + | | extends | SubClass = [[Class]](BaseClass) | class SubClass extends BaseClass --\> SubClass(BaseClass) | | |
| 46 | + | | final | [[Const]] | for constants, not uninheritables | | |
| 47 | + | | for ++ | [[For]] [[To]] [[Do]] | | | |
| 48 | + | | for -- | [[For]] [[Downto]] [[Do]] | | | |
| 49 | + | | if() | [[If]] [[Then]] | | | |
| 50 | + | | if() else | [[If]] [[Then]] [[Else]] | | | |
| 51 | + | | implements | SomeClass = [[Class]](SomeInterface) | | | |
| 52 | + | | import | [[Uses]] | | | |
| 53 | + | | instanceof | [[Is]] | | | |
| 54 | + | | interface | TheInterface = [[Interface]] | | | |
| 55 | + | | native | [[StdCall]] | For Windows | | |
| 56 | + | | native | [[CDecl]] | For Unix | | |
| 57 | + | | new primitive_type\[#\]; | [[SetLength]](ArrayVar, \#); | | | |
| 58 | + | | new Class(); | InstanceVar := TheClass.Create; | | | |
| 59 | + | | package pkgName; | [[Unit]] unitName; [[Interface]] [[Implementation]] [[End]]. | Note the period after End | | |
| 60 | + | | private | [[Private]] | | | |
| 61 | + | | protected | [[Protected]] | | | |
| 62 | + | | public | [[Public]] | | | |
| 63 | + | | return | FunctionName := | | | |
| 64 | + | | return | [[Result]] := | ObjFPC or Delphi modes | | |
| 65 | + | | return | [[Function|Exit()]] | ObjFPC modes | | |
| 66 | + | | static | [[Static]] | | | |
| 67 | + | | static | [[Class]] [[Function]] | | | |
| 68 | + | | static | [[Class]] [[Procedure]] | | | |
| 69 | + | | super | [[Inherited]] | Parent constructor call | | |
| 70 | + | | switch case break | [[Case]] [[Of]] [[End]] | | | |
| 71 | + | | switch case break default | [[Case]] [[Of]] [[Else]] [[End]] | | | |
| 72 | + | | synchronized | [[TCriticalSection]] | | | |
| 73 | + | | this | [[Self]] | | | |
| 74 | + | | throw | [[Raise]] | | | |
| 75 | + | | throws | | | | |
| 76 | + | | transient | | | | |
| 77 | + | | try { } catch | [[Try]] [[Except]] | | | |
| 78 | + | | try { } catch finally | [[Try]] [[Finally]] | | | |
| 79 | + | | void | [[Procedure]] | | | |
| 80 | + | | volatile | | | | |
| 81 | + | | while | [[While]] [[Do]] | | | |
| 82 | + | ||
| 83 | + | ## Translating Java data types | |
| 84 | + | ||
| 85 | + | | Java type | [[Pascal]] [[Data type|type]] | Size (bits) | Range | | | |
| 86 | + | |----|----|----|----|----| | |
| 87 | + | | byte | [[Shortint]] | 8-bit | -128 .. 127 | | | |
| 88 | + | | short | [[Smallint]] | 16-bit | -32768 .. 32767 | | | |
| 89 | + | | int | [[Longint]] | 32-bit | -2147483648..2147483647 | | | |
| 90 | + | | int | [[Integer]] | 32-bit | -2147483648..2147483647 | | | |
| 91 | + | | long | [[Int64]] | 64-bit | -9 223 372 036 854 775 808 .. 9 223 372 036 854 775 807 | | | |
| 92 | + | | float | [[Single]] | 32-bit | 1.5E-45 .. 3.4E+38 | | | |
| 93 | + | | double | [[Double]] | 64-bit | 5.0E-324 .. 1.7E+308 | | | |
| 94 | + | | boolean | [[Boolean]] | | [[False]] [[True]] | | | |
| 95 | + | | char | [[WideChar]] | 16-bit | | | | |
| 96 | + | | String | [[String]] | | | | | |
| 97 | + | | | | | | | | |
| 98 | + | | | | | | | | |
| 99 | + | ||
| 100 | + | ## See also | |
| 101 | + | ||
| 102 | + | - [[Using Pascal Libraries with Java]] | |
| 103 | + | ||
| 104 | + | --- | |
| 105 | + | *From the Free Pascal wiki, page "Pascal for Java users", as it stood on 2019-03-04 after a change by Djzepi, 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).* |
