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

Smalltalk vs. Java - Vinutha Prabhakar

OOP is a programming language model organized around the use of "objects" rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it and produces output data. Smalltalk and Java both are example of object-oriented programming.

Smalltalk is the language that has started the OOP revolution. Certainly, there was some important work before Smalltalk, for instance like Simula and Clu, but iwas Smalltalk that first embodied and articulated the fundamental concepts of OOP. Smalltalk is an objected-oriented, dynamically typed, reflected programming language. It was designed and created in part for educational use, more so far constructionist learning, at Xeror PARC by Alan Kay and several others durin gthe 1970s, influenced by Lips, Logo, Sketchpad, and Simular.

Java, the language, is a high-level object-oriented programming language, influenced in various ways by C, C++, and Smalltalk, with ideas borrowed from other languages as well. James Gosling created the Java language in June 1991 for use in a set top box project. It was fairly secure and its security was configurable, allowing network and file access to be restricted. Java's design, industry backing and protability have made Java one of the fastest growing and most widely used programming languages in the modern computing industry.

Both Smalltalk and Java are object-oriented languages. Classes form the main abstraction. State is captured in class (static) variables and instance variables. Behavior is implemented in methods, executed as the result of sending a message (invoking a method). Both languages provide single inheritance. Methods are dispatched "virtually." Classes can redefine behavior from inherited classes, and its instances can thereby subsume multiple roles. Both languages translate into bytecodes that are then executed by a virtual machine. Although the nature of the bytecodes is quite different, the two languages have the same execution model. Studies have shown that the use of programming language influences how designers and programmers think about a problem and how they come up with a solution. One important factor is memory management. In that respect, Smalltalk and Java are very similar. Both are garbage collection to retrieve instances that are no longer references, and in this way memory is released.

Perhaps the biggest impact when moving from Smalltalk to Java is the notion of typing. In Java, each variable (class variable, instance variable or temporary) is declared not only with a name but also with a type. Often the grounds for religious discussions, typing has its advantages and disadvantages. One advantage is that the compiler is able to do type checking, avoiding many "DoesNotUnderstand:" messages. Furthermore, a compiler can implement more efficient method dispatching when all the types of the arguments are known in advance.

Some basic comparison between Java and Smalltalk are as follows:

Java Smalltalk
This and That
this.getClass() self class
Basic statement structure:
/*This is how you comment in Java*/"This is how you commend in Smalltalk"
Message Sends foo
foo()self foo,b)anObject foo: a with: b
aDict.atKey_put(key,value)aDict atKey: key put:value
anObject a; b
Instance Variables
Control Structures
if (isTrue) {...} (isTrue) ifTrue:[...]
if (...){...} else {...}(...)ifTrue:[...] ifFalse:[...]
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
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
(Bar) x N/A
x isKindOf: Bar
x respondsTo: #messageForABar
(...DoesNotUnderstand...)handle:[:e/...] do:[x messageForABar]
Access Control
protected foo()N/A
public x N/A
protected xx
private xN/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]
System.out.println("Text");Transcript show:'Text'
System.out.println(a);Transcript show:(a) printString
(Automatic with println)
Transcript show: 'Text'; cr.
java fileSelect Text, left-click, 'do it'
a=4a :=4
a==b (double "= ="a = b (single "=")
Function - Return Value
return value^value

Note: In some cases I used "\" to incidate "|"

Links to this Page