DJ is a language that amalgamates Java and Constraint Programming. Developing GUIs including applets in Java is a time-consuming process. The users have to choose appropriate layout managers and sometimes have to determine the sizes and positions of graphical components. There are many visual tools for creating Java programs without the need to write any code. However, none of these tools supports constraints. DJ, as an extension of Java, significantly simplifies the process of constructing GUIs and Java applets. The users only need to specify the components that compose a GUI and the relationships among the components by using constraints. The layout for the components is automatically determined by the system. As a constraint programming language, DJ improves the current constraint languages in that problems and solutions can be described in the same language. And most importantly, because DJ is a compiling language that uses Java as the object language, results can be distributed on the World Wide Web as Java applets and/or included in other larger applications.
DJ is an extension of Java that supports constraint programming and retains the object-oriented feature of Java. A DJ program consists of several classes and optionally several constraint definitions. In addition to field and method declarations, a class can also include dj-field declarations, constraints, and actions. Dj-field declarations declare the components that make up the class and the attributes of the class. Constraints are relations among components or component attributes. Unlike member variables in Java that can be updated, dj-fields are single-assignment variables whose values are determined automatically by the system based on the constraints over them. An action associated with a component specifies the action to take when some event happens to the component.
The extension to Java's syntax is kept as small as possible. A constraint has similar syntax to that of a conditional expression in Java, and a constraint definition is like a method declaration except that the body is a sequence of constraints. Because of this similarity, users who know Java and constraint programming can master the new language in a very short time.
A compiler for DJ has been implemented in B-Prolog1, a constraint logic programming system. 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 manual describes the DJ language and gives several examples illustrating how to write DJ programs. More examples can be found from DJ's WEB page at http://www.cad.mse.kyutech.ac.jp/people/zhou/dj.html.