View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Dicussion 4 - Daniel King

Java-to-Smalltalk Guide:

One major difference between Java and Smalltalk is typing. Unlike Java's static typing, Smalltalk uses dynamic typing. In Java, you must declare if something is an int or double or even objects such as ArrayList. However, in Smalltalk you can store whatever you like in any variable. Though this may cause problems with incorrect types, it makes the language more flexible.

Everything in Smalltalk is an object. This means that you can call methods on anything, whereas in Java, primitives such as int, double, and boolean have no methods. Methods are also different in Smalltalk. You call a method by simply putting a space after the object and then the name of the method. In Java, you must put a '.', the method name, and () even if you don't use any parameters. Methods in Smalltalk are really messages, you have an object and you send it a message. The object can also return, just like Java; however, in Smalltalk, '^' is the return keyword, whereas Java uses 'return'. Parameters in Smalltalk are written right after a message ending with a ':'. The colon indicates that it takes a parameter. To take in more than one parameter, the message must be in the form 'message1: param1 message2: param2'. In Java, parameters are within the parantheses, separated by commas.

Order of operations in Smalltalk is also different. Unlike the mathematical order of operations in Java, Smalltalk basically just goes from left to right. Though, parenthesis can be used to give certain operations precedence.

Blocks are something Smalltalk has but Java does not. Blocks in Smalltalk can be used almost like methods; they can take in values, perform some operation, and effectively return the result. A common use of blocks is for the condition of a while loop, and the code to execute each iteration. Though the condition of a while loop is a block, the condition of an if statement is not.

Smalltalk is more uniform than Java; however, it can be difficult to learn Smalltalk because of the lack of an API. You must use browsers and inspectors to learn new objects and methods.

Link to this Page