Ejs Tips and Pitfalls:
Ejs Best Practice

Joshua Bloch is his book Effective Java uses the following example to point out that grammatical correctness is not the only criterion for effectively conveying information to a reader. "Spouse of me this night today manufactures the unusual meal in a home.  You will join?"  So it is with modeling.  Defining a problem and organizing its solution requires more than mathematical correctness.  Ejs promotes an integrated understand of the modeling process by exposing and providing access to the underlying assumptions in the physical model. It encourages revision and testing of the model and the distribution of the model including narrative and documentation. Finally, Ejs is both simple to use and sufficiently advanced to handle complex models that occur in professional practice.

Easy Java Simulations simplifies the modeling process by breaking it into activities that are selected using radio buttons as shown above: (1) documentation, (2) modeling, and (3) interface design. The html-based documentation is accessed by selecting Introduction. The physics is accessed by selecting Model which provides access to the data and the methods (Java code) by which the model can change. A plot is a visual representation of data and is an example of a View. Because it is possible to have multiple views of the same data and because the model and its views are controlled by buttons and other user interface components, Ejs provides a graphical drag-and-drop editor for these objects thereby eliminating much coding. The Ejs model-view-controller paradigm is well known in computer science and provides a solid foundation for software development.

Ejs Best Practice

Copy from others.

A good way to learn is to study the work of others.  Run the examples in this package to obtain an overview of Ejs.  The Pendulum model creates a data graph, the Collision  model model uses a sophisticated differential equation solver, and the Free Fall model uses a state event to detect a collision.  Copy our examples into your Ejs _user directory and examine how each model is implemented.  Click on the Model and View and then click the the various subpanels.  In particular, double-click on objects in the View's tree of elements and note how the appearance of objects are set.

It is straightforward to open two copies of Ejs and to copy code and objects from these simulations into your own simulation.

Organize your work.

Variables naturally fall into three categories:  dynamic variables that evolve in time and determine the state of the system, constants that characterize physical properties of the system but remain fixed, and auxiliary variables that are computed from the dynamical variables and the constants. Auxiliary variables that depend on dynamic variables are almost always recomputed after every time (evolution) step using a Constraints page.  Auxiliary variables that do not change can be computed using an Initialization page.

A little Java goes a long way.

Ejs is built on Java and this can be either a blessing or a curse depending on how you write your code. Small code fragments that perform specific and well-defined operations can make your model easier to understand.  Define these code fragments using a Custom page.  See, for example, how the custom newPosition() method in the Pendulum model computes polar coordinates from the bob's Cartesian xy-coordinates.  Double click on the bob object in the View tree of elements and notice that this method is invoked as an action whenever the bob is dragged.

The amount of Java that you need to learn to use Ejs to its full potential is not great, but it can present a barrier to the beginning user.  Java is that it is, after all, a professional and powerful programming language and is picky about syntax.  Capitalization matters, you must end every Java statement with a semicolon, you must indicate multiplication using an asterisk, you must know that the sine function is in the Math library and is named Math.sin.  Etc.

Read the manual.

The examples in this package are an introduction to Ejs and are not a substitute for the Ejs manual.  Readers should download and consult the Ejs manual for a complete description.