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

Mini Java-to-Squeak Tutorial

Team Robot Chicken

Mini Java-to-Squeak Tutorial

Uploaded Image: RobotChicken.jpg
by: Amro Mousa, Elliott Clark, Brandon Reynolds, Jiasheng He


Mini Java-to-Squeak Tutorial

This is a mini Java to Squeak tutorial. This is not an outline on how to jump into Squeak, but a code comparison between very simple tasks written in many C-syntax type languages that will be useful to those starting their Squeak coding.

Random Fact: Squeak collections start counting at 1 (ONE), not 0 (ZERO)!

Each Section will be titled and following the title will be two short self explanitory code segments.

Assignment
Java
int x = 7;

Squeak
x := 7.

or
x _ 7.



Comments
Java
//This is a code comment

Squeak
"This is a code comment"



Strings
Java
String word = "my string";

Squeak
word := 'my string'.



String Concatenation
Java
String bah = "stri" + "ngs";

Squeak
bah := 'stri','ngs'.



Logical Operators
Java or
(this || that)

Squeak or
(this | that)


Java and
(this && that)

Squeak and
(this & that)


Java equal to
(this == that)

Squeak equal to
(this = that)


Statement termination
Java
int x = 5;

Squeak
bah := 5.


String to Int
Java
String bah = "5"; 
int i = Integer.parseInt(bah).

Squeak
bah := '5'. 
blah := bah asNumber.


Conditionals
Java
if (this == that) 
      { 
         ...
      }

Squeak
(this = that)
      ifTrue:
      [
         ...
      ]
      ifFalse:
      [
         ...
      ].


Notice the lack of the period (.) between the closing brace of ifTrue and the closing brace of ifFalse. If you do not want to handle the ifFalse case, you can simply put the period after the closing brace of ifTrue and not have an ifFalse block. Also note that a colon is required after the ifTrue and ifFalse.

Loops
Java
int i = 0;
      while (i < 10)
      {
         ...
         i++;
      }

Squeak
count := 0.
      [count < 10] whileTrue:
      [
	   ...
	   count := count + 1.
      ].


Java
for (int i = 0; i < 10; i++)
      {
         ..use i in here..
      }

Squeak
1 to 10 do:
	[ :i |
	    ..use i in here..
	].


Links to this Page