User Tools

Site Tools


Sidebar

Jump to
AmbientTalk
CRIME
iScheme

at:tutorial:symbiosis

This is an old revision of the document!


This Tutorial is still under heavy construction

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.

The reverse, namely that AmbientTalk objects can accessed from within Java is also possible. AmbientTalk objects are reified at the Java level such that the Java language can be used to send messages and create new objects.

This chapter explains how both sides of this symbiotic relationship between Java and AmbientTalk can be leveraged. The goal of this symbiotic relationship is to complement the advantages of both languages and to alleviate their disadvantages. For example, AmbientTalk can use the extensive class library from Java and Java can benefit from AmbientTalk's superior concurrency abstractions.

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:

>def Vector := jlobby.java.util.Vector
>><java:class java.util.Vector>

Creating Java objects

Creating a new instance of the Vector class is done by invoking the method new on the class object.

>def aVector := Vector.new()
>><java:[]>

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.

>aVector := Vector.new(30)
>><java:[]>

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.



Overloading

Using Java wrappers

Symbionts

Conversions

Thread-Actor Symbiosis

at/tutorial/symbiosis.1175868886.txt.gz · Last modified: 2007/04/06 16:21 (external edit)