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

Discussion 4 - David Eakes

Discussion 4: Java-to-Smalltalk tutorial


The "Hello, World" program:
Java:

public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello, World.");
}
}


or as a Java GUI:


import java.awt.Dimension;
import javax.swing.;
public class HelloWorldGUI {

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(300, 50));
panel.add(new JLabel("Hello, World."));
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}
}


Smalltalk:

|t|
t := TextMorph new.
t contents: 'Hello, World.'.
t openInWorld.


In Smalltalk, with morphic, it's very easy to make a call to TextMorph to bring up any text to the main window. In Java, you can get a String to show up in either the console or you have to code up a GUI to display them in. Java code is C-based. Instances have names and must be defined before use. This is not the case in Smalltalk.

Java: Object o = new Object();
Smalltalk: s := Object new.

This look at the syntax brings up an interesting point. In Java, to access an instance, the statement looks connected and enclosed, like the line: panel.setPreferredSize(new Dimension(300, 50));
Everything is enclosed or connected.
Whereas, in Smalltalk, the code is more like a sentence.

These are a few subtle differences, there are many many others. I could list them out, but then you wouldn't learn anything! This is a tips page for going from Java to Smalltalk.

As a final thought, in Java you could look at a source file and edit it based on already existing classes. However, in Smalltalk, you're actually editing the language. That's probably one of the biggest things to remember.

Links to this Page