The Java Dot Notation

The Java Dot Notation provides Jscheme with full access to all Java constructors, methods, and fields for all Java classes on the current classpath. The syntax is very simple as explained in the box below and demonstrated in the examples on the rest of this page.

Java literals have the same syntax as Java members except for a possible "." or "$" prefix or suffix. Overloaded methods and constructors are disambiguated dynamically at runtime. Adding a "#" to the end of a Javadot symbol allows access to private fields, methods, and constructors (and to members with protected, package, and public visibility as well).

SyntaxType of MemberExample
"." at the end constructor(Font. NAME STYLE SIZE)
"." at the beginning instance member(.setFont COMP FONT)
"." at beginning and "$" at the end instance field(.first$ '(1 2))
"." only in the middle static member(Math.round 123.456)
".class" suffix Java classFont.class
"$" at the end static fieldFont.BOLD$
"$" in the middle inner classjava.awt.geom.Point2D$Double.class
"$" at the beginning packageless class$ParseDemo.class
"#" at the end private access($# 'a)

Examples of Java Literals

(import "java.awt.*") The import statement allows Java package names to be omitted in Java literals, just as in Java:
import java.awt.*;
(define win (Frame. "Hello"))
(define L (java.awt.Label. "Hi"))
A constructor
is signified by trailing "." as in "Class."

The particular constructor is determined dynamically by analyzing the types of the arguments. The corresponding Java would be
Frame win = new Frame("Hello");
Label L  = new Label("Hi");
(.resize win1 200 300)
(.Container.resize win2 200 300)
(.java.awt.Component.resize win3 200 300)
An instance method
is signified by a leading "." as in ".Name"

The examples at left would be written in Java as:
  win1.resize(200, 300);
  ((Container) win2).resize(200,300);
  ((java.awt.Component) win3).resize(200,300);
(System.exit 0)
(java.lang.Math.sin 3.1415926)
A static method
is signified by "." only in the middle as in "Class.Name"

The examples at left would be written in Java as:
(.println System.out$ "hi")
(set! U.useJavaSyntax$ #t)
A static variable
is signified by a "$" at the end and no leading "." as in "Class.Name$"

The examples at left would be written in Java as:
U.useJavaSyntax = true;
(define a (.Pair.first$ x))
(define b (.SubPair.first$ x))
(define c(.Pair.first$ x newval))
(define d (.SubPair.first$ x newval))

(define L '(1 2 3))
(define e (.first$ L))
(.first$ L 5)
An instance variable
is signified by a "$" at the end and a leading "." as in ".Class.Name$" or ".Name$"

Instance variables are viewed as get/set functions,
while static variables are viewed as Scheme variables which can be evaluated and set!'d.
The examples at left would be written in Java as:

Object a=((Pair)x).first
Object b=((SubPair)x).first
Object c=((Pair)x).first = newval;
Object d=((SubPair)x).first = newval;

Pair L = new Pair(new Integer("1"),
         new Pair(new Integer("2"),
         new Pair(new Integer("3"),Pair.EMPTY)));
Object e = L.first;
L.first= 5;
(define c1 Object.class)
(define c2 Line2D$Float.class)
(define c3 int.class)
(define c4 float[][].class )
(define c5 Float[].class)
The suffix ".class" signifies a class literal.
The examples at left would be written in Java as:
Class c1 = Object.class;
Class c2 = Line2D.Float.class;
Class c3 = int.class;
Class c4 = float[][].class;
Class c5 = Float[][].class;

Note that in Jscheme, "$" is used to indicate inner classes rather than "." as used by Java.
(define win 
  (constructor "Frame" "String"))
(define frame-add 
  (method "add" "Frame" "Component"))
Jscheme also provides a mechanism for precisely and unambiguously specifying a method or constructor by giving its name, class, and argument types.