DJ (Declarative Java) is an extension of Java that supports constraint programming over finite-domains. DJ can be used for two purposes: Firstly, DJ can be used for constructing graphical user interfaces (GUIs). Unlike in Java where the users have to choose appropriate layout managers and sometimes have to determine the sizes and positions of graphical components, the users of DJ only need to specify the components that compose a GUI and the relationship among the components by using constraints. The geometric attribute values of the components are all determined by the system. Secondly, DJ can serve as a general tool for describing and solving Constraint Satisfaction Problems (CSPs). For a CSP, the user cannot only describe the variables and the constraints in the problem, but also describe how to display the solutions graphically.
DJ retains the object-oriented feature of Java. A DJ program consists of several classes and optionally several constraint definitions. Besides variable and method declarations, a class can also include component declarations, attribute declarations, and constraints. Component declarations declare the components that make up the class. A component is an instance of some base class or user-defined class. Constraints are relations among component attributes. Unlike variables, attribute values are determined by the system based on the constraints.
The constraint technology has been recognized as an effective
technology for constructing GUIs [1,3,5]. There are
already many GUI development tools that allow the users to specify
some kind of constraints. Examples of these tools include Amulet
[5], ThingLab II [1], TclProp [4], and LIFE
[2]. Although using these systems makes GUI
development much easier than using conventional languages, the
following two factors make these tools unacceptable to many users:
First, these systems do not support nondeterminism and are far from
being declarative. They require a one-to-one mapping between a GUI
specification and the final layout. To enforce this, these systems
either only support a restricted form of constraints, such as one-way
constraints in ThingLab, or require the user to provide sufficient
information. Second, these systems are all interpreters. Besides the
problem of low efficiency, interpreter-based GUIs are difficult to be
integrated into other applications. Compared with these systems, DJ
has the following three attractive features: (1) it is truly
declarative and very easy to learn; (2) GUI specifications are
compiled into Java, and thus can be easily integrated into other Java
applets or applications; (3) the mapping from GUI specifications to
Java programs is one-to-many rather than one-to-one, and the system is
able to help the users select satisfactory layouts .
A compiler for DJ has been implemented in B-Prolog[6]. For a DJ program, the compiler first extracts the CSP from the program, and then invokes the constraint solver to solve the problem and determines the attribute values for the components. It finally generates a Java program as well as an HTML file from the original DJ program and the solution obtained by the constraint solver.
This article describes the DJ language and gives several examples. More examples can be found from DJ's WEB page at:
http://www.cad.mse.kyutech.ac.jp/people/zhou/dj.html