home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_show / cecil / JVM / Example4.java < prev    next >
Text File  |  1999-06-05  |  1KB  |  52 lines

  1. import root4.*;
  2.  
  3. public class Example4 {
  4.  
  5.     public static void main(String[] args) {
  6.     /* To run this example, procede like this :
  7.        
  8.            compile_to_jvm root4
  9.            /bin/rm -f root4.class
  10.            javac Example4.java
  11.            java Example4
  12.        
  13.     */
  14.  
  15.     root4 root;
  16.     string eiffel_string;
  17.  
  18.     /* To initialize the Eiffel runtime :
  19.      */
  20.     _any._initialize_eiffel_runtime(args);
  21.   
  22.     /* Creation of the root object :
  23.      */
  24.     root = new root4();
  25.     eiffel_string = ( string )( root.get_string() );
  26.     root.put_string( eiffel_string );
  27.  
  28.     // print the capacity and count of the string.
  29.     System.out.println( "eiffel_string capacity: " +
  30.                 eiffel_string.capacity +
  31.                 ", count: " +
  32.                 eiffel_string.count );
  33.  
  34.     // Build a Java String from the Eiffel string, and print it.
  35.     String eiffel_string_in_java = new String( eiffel_string.storage,
  36.                            0,
  37.                            eiffel_string.count );
  38.     System.out.println( "Java printing the converted eiffel: '" +
  39.                 eiffel_string_in_java + "'" );
  40.  
  41.     // Build and Eiffel string from a Java String, and print it from Eiffel.
  42.     // Note that the byte buffer does not have to be null terminated.
  43.     String js = "Hello from Java";
  44.     string new_eiffel_string = new string();
  45.     new_eiffel_string.storage = js.getBytes();
  46.     new_eiffel_string.capacity = new_eiffel_string.storage.length;
  47.     new_eiffel_string.count = new_eiffel_string.storage.length;
  48.     
  49.     root.put_string( new_eiffel_string );
  50.     }
  51. }
  52.