![]() Home | ![]() Back | ![]() Contents | ![]() Next |
/* Standard Java syntax */ // Use a hashtable Hashtable hashtable = new Hashtable(); Date date = new Date(); hashtable.put( "today", date ); // Print the current clock value print( System.currentTimeMillis() ); // Loop for (int i=0; i<5; i++) print(i); // Pop up a frame with a button in it JButton button = new JButton( "My Button" ); JFrame frame = new JFrame( "My Frame" ); frame.getContentPane().add( button, "Center" ); frame.pack(); frame.setVisible(true); |
/* Loosely Typed Java syntax */ // Use a hashtable hashtable = new Hashtable(); date = new Date(); hashtable.put( "today", date ); // Print the current clock value print( System.currentTimeMillis() ); // Loop for (i=0; i<5; i++) print(i); // Pop up a frame with a button in it button = new JButton( "My Button" ); frame = new JFrame( "My Frame" ); frame.getContentPane().add( button, "Center" ); frame.pack(); frame.setVisible(true); |
try { int i = 1/0; } catch ( ArithmeticException e ) { print( e ); } |
try { ... } catch ( e ) { ... } |
// Arbitrary code block { y = 2; // Untyped variable assigned int x = 1; // Typed variable assigned } print( y ); // 2 print( x ); // Error! x is undefined. // Same with any block statement: if, while, try/catch, etc. if ( true ) { y = 2; // Untyped variable assigned int x = 1; // Typed variable assigned } print( y ); // 2 print( x ); // Error! x is undefined. |
for( int i=0; i<10; i++ ) { // typed for-init variable j=42; } print( i ); // Error! 'i' is undefined. print( j ); // 42 for( z=0; z<10; z++ ) { } // untyped for-init variable print( z ); // 10 |
button = new java.awt.Button(); button.label = "my button"; // Equivalent to: b.setLabel("my button"); |
b = new java.awt.Button(); b{"label"} = "my button"; // Equivalent to: b.setLabel("my button"); h = new Hashtable(); h{"foo"} = "bar"; // Equivalent to: h.put("foo", "bar"); |
i=5; iw=new Integer(5); print( i * iw ); // 25 |
import javax.xml.parsers.*; import mypackage.MyClass; |
import *; |
Tip: The BeanShell which() command will use the classpath mapping capability to tell you where exactly in your classpath a specified class is located: bsh % which( java.lang.String ); Jar: file:/usr/java/j2sdk1.4.0/jre/lib/rt.jar |
@gt | > |
@lt | < |
@lteq | <= |
@gteq | >= |
@or | || |
@and | && |
@bitwise_and | & |
@bitwise_or | | |
@left_shift | << |
@right_shift | >> |
@right_unsigned_shift | >>> |
@and_assign | &= |
@or_assign | |= |
@left_shift_assign | <<= |
@right_shift_assign | >>= |
@right_unsigned_shift_assign | >>>= |
![]() Home | ![]() Back | ![]() Contents | ![]() Next |