| Java | Smalltalk | |
| This and That | ||
| this.getClass() | self class | |
| null | nil | |
| this | self | |
| super | super | |
| Basic statement structure: | ||
| /*This is how you comment in Java*/ | "This is how you commend in Smalltalk" | |
| ; | . | |
| //Comment | N/A | |
| Message Sends | ||
| anObject.foo() | anObject foo | |
| foo() | self foo | |
| anObject.foo(a,b) | anObject foo: a with: b | |
| aDict.atKey_put(key,value) | aDict atKey: key put:value | |
| anObject a; b | ||
| Instance Variables | ||
| x | x | |
| this.x | x | |
| anObject.x | N/A | |
| Control Structures | ||
| if (isTrue) {...} | (isTrue) ifTrue:[...] | |
| if (...){...} else {...} | (...)ifTrue:[...] ifFalse:[...] | |
| switch(...) | N/A | |
| while (isTrue) | []whileTrue:[] | |
| for (...;...;...) | N/A aCollection do:, collect:, etc anInterval do: (number) timesRepeat:[] | |
| try {} catch (Exception e) {} | Exception handle:[:e/...] do:[...] | |
| Declaring Classes and Interfaces | ||
| class Foo{ | Object subclass: #Foo | |
| class Bar extends Foo{ | Bar subclass: #Foo | |
| Interface Foo{ | N/A | |
| Interface Foo extends Foo{ | N/A | |
| class Bar implements Foo{ | N/A | |
| Typing | ||
| Object anObject; | absolute value of :anObject | |
| Object aString; | N/A | |
| Object aString; | N/A | |
| int anInt; | N/A | |
| Object foo() | foo | |
| String foo() | N/A | |
| void foo() | N/A foo | |
| Casts | ||
| (Bar) x | N/A x isKindOf: Bar x respondsTo: #messageForABar (...DoesNotUnderstand...)handle:[:e/...] do:[x messageForABar] | |
| Access Control | ||
| public...foo() | foo | |
| protected foo() | N/A | |
| public x | N/A | |
| protected x | x | |
| private x | N/A | |
| Blocks and Anonymous Classes | ||
| new Function2Arg() {publicObject valueWith_with(Object a, Object b) {return (String) a + (String) b;}} | [:a :b / a,b] | |
| null | [/^'This breaks out of everything'] | |
| new Function2Arg() {public Object valueWith_with (Object a, Object b) {return c + (String) a + (Sring) b; }} | [:a:b \c,a,b] | |
| Miscellaneous | ||
| "\"" | '"' | |
| "'" | "'" | |
| "Hi\the\u0032re\n" | "hi\there"withCrs | |
| Printing | ||
| System.out.println("Text"); | Transcript show:'Text' | |
| Printing-variables | ||
| System.out.println(a); | Transcript show:(a) printString | |
| Printing-newline | ||
| System.out.println("Text"); (Automatic with println) | Transcript show: 'Text'; cr. | |
| Running | ||
| java file | Select Text, left-click, 'do it' | |
| Assignment | ||
| a=4 | a :=4 | |
| Equality | ||
| a==b (double "= =" | a = b (single "=") | |
| Function - Return Value | ||
| return value | ^value | |
| Terminology | ||
| Function | method |