User Tools

Site Tools


at:tutorial:symbiosis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
at:tutorial:symbiosis [2007/04/06 14:34] jdedeckerat:tutorial:symbiosis [2007/04/06 16:14] jdedecker
Line 1: Line 1:
-====== Symbiosis with Java ====== 
- 
 <note>This Tutorial is still under heavy construction</note> <note>This Tutorial is still under heavy construction</note>
 +
 +====== Symbiosis with Java ======
  
 AmbientTalk is fully implemented in Java and runs on top of the JVM.  Java provides an extensive class library that can be accessed from within AmbientTalk.  In other words, Java classes can be instantiated and messages can be sent to Java objects from within AmbientTalk. AmbientTalk is fully implemented in Java and runs on top of the JVM.  Java provides an extensive class library that can be accessed from within AmbientTalk.  In other words, Java classes can be instantiated and messages can be sent to Java objects from within AmbientTalk.
Line 10: Line 10:
  
 ===== Accessing Java classes ===== ===== Accessing Java classes =====
 +The complete set of classes that are available in the class path of a running JVM are accessible from AmbientTalk through the jlobby object.  For example, referencing the Java Vector class from within AmbientTalk can be accessed with:
 +
 +<code>
 +>def Vector := jlobby.java.util.Vector
 +>><java:class java.util.Vector>
 +</code>
  
 ===== Creating Java objects ===== ===== Creating Java objects =====
 +Creating a new instance of the Vector class is done by invoking the method new on the class object.
 +
 +<code>
 +>def aVector := Vector.new()
 +>><java:[]>
 +</code>
 +
 +All constructors defined in the corresponding Java class can be accessed too.  For example,  the Vector class also has a constructor that takes an initial capacity as its argument.  This constructor can be called using an integer as the argument of new.
 +
 +<code>
 +>aVector := Vector.new(30)
 +>><java:[]>
 +</code>
 +
 +===== Invoking methods on Java objects =====
 +In a similar fashion to calling constructors on Java classes we can also call other methods defined in the Java class.  For example, adding a elements to the vector can be done by invoking the add method.
 +
 +<code>
 +</code>
  
-===== Using Java wrappers ===== 
  
 ===== Overloading ===== ===== Overloading =====
 +
 +===== Using Java wrappers =====
  
 ===== Symbionts ===== ===== Symbionts =====
at/tutorial/symbiosis.txt · Last modified: 2013/05/17 20:25 by tvcutsem