PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/cecil/JVM/Example4.java

http://github.com/tybor/Liberty
Java | 51 lines | 26 code | 9 blank | 16 comment | 0 complexity | 2ace339b4cebf9f34ced76da3613f8a0 MD5 | raw file
 1import root4.*;
 2
 3public 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}