You are on page 1of 6

Computer Physics Communications 156 (2004) 199204

www.elsevier.com/locate/cpc

Easy Java Simulations: a software tool to create


scientific simulations in Java
Francisco Esquembre
Universidad de Murcia, Departamento de Matemticas, Campus de Espinardo, 30071 Murcia, Spain
Received 15 April 2003; received in revised form 31 July 2003

Abstract
We introduce Easy Java Simulations, Ejs, a tool created by science teachers to help teach and learn science. Ejs allows users
to create simulations using their knowledge of the scientific model. The author needs to supply a small amount of code for the
model; the tool provides a graphical drag-and-drop interface to build the program. The resulting Ejs generated program is an
independent, high quality Java application or applet ready to be published on a Web server. Ejs can serve as an effective teaching
and learning tool if used in an appropriate pedagogical setting; for instance, to help students create their own simulations in
order to express their conceptions on how a given scientific process works.
The Ejs program and documentation can be freely downloaded from the site http://fem.um.es/Ejs.
2003 Elsevier B.V. All rights reserved.

1. Introduction
Simulations are playing an increasingly important
role in the way we teach or do science. This is
specially true in education, where computers are being
used more and more as a way to make lectures more
attractive to students and to help achieve a deeper
understanding of the subject being taught. However,
it cannot be said that computer simulations are used
by most teachers. In many cases, this is due to the fact
that teachers are reluctant to use a technology they do
not fully understand or control. In many others, that
they cannot find a product that completely meets their
educational needs.
A good solution to both problems is to help teachers create their own simulations. We have found that,
E-mail address: fem@um.es (F. Esquembre).
0010-4655/$ see front matter 2003 Elsevier B.V. All rights reserved.
doi:10.1016/S0010-4655(03)00440-5

by creating a simulation, many teachers get a new perspective of the phenomenon they are trying to explain,
which almost always increases their enthusiasm for the
use of this technology with their students. An alternative approach, and a very promising one, is to let
students create their own simulations, thus engaging
in what is called by educational researchers constructive modeling [1]. This has the advantage of getting
students to do science in an exploratory and constructive way, achieving many of the recommended bestpractices in the classroom [2].
Creating a simulation by oneself requires extra effort. The starting point, and this is the important part,
is a full understanding of the phenomenon being simulated. From this, some (sometimes a lot of!) technicalities are needed in order to express the behavior of
the phenomenon in computer form.

200

F. Esquembre / Computer Physics Communications 156 (2004) 199204

This paper describes Easy Java Simulations (Ejs for


short), a software tool that addresses this problem. Ejs
has been specifically designed to teach how to create scientific simulations in Java, in a quick and simple way. Its audience is composed of science students,
teachers, and researchers who have a basic knowledge
of programming, but who cannot afford the big investment of time needed to create a complete graphical
simulation. They may be able to describe an algorithm
in terms of a computer language, but still need an extra effort to create a sophisticated, interactive graphical
user interface, in the style of simulations and software
programs one can find nowadays in the Internet.
With this situation in mind, Ejs helps someone who
wants to create a simulation to concentrate most of
his/her time in writing and refining the algorithms of
the underlying scientific model (which is his/her real
expertise) and dedicate the minimum possible amount
of time to the programming. And by doing so, they
can still obtain an independent, high performance,
Internet-aware, final product. The program provides
simplified input forms that correspond to the common
structure found in most simulations, so that authors
need to provide the Java code relevant to the model
(for which they have full responsibility) and design
the user interface for the simulation, using high-level
components. Ejs then generates all the code needed for
the complete simulation, compiles it, and creates the
extra material needed, such as an html page, to publish
the simulation on the Internet.
Another goal of Ejs is to show teachers how to
structure a simulation so that it can be correctly converted to a computer program. Ejs provides extensive
scaffolding for this purpose.
The choice of Java as development language is justified in terms of its wide acceptance by the scientific
community, and the fact that it is supported on several
software platforms. This implies that Ejs, and the simulations created using it, can be used as independent
programs under different operating systems, or be distributed via the Internet and run within html pages by
most popular web browsers. (html stands for the Hyper Text Markup Language.)

2. Structure of a simulation
Easy Java Simulations helps create discrete computer simulations. A discrete computer simulation, or
simply a computer simulation, is a computer program
that tries to reproduce, for pedagogical or scientific
purposes, a natural phenomenon through the visualization of the different states that it can have. Each
of these states is described by a set of variables that
change in time due to the iteration of a given algorithm.
Ejs provides a simplified implementation of the
Model-Control-View design pattern and tools that help
create each of these parts. This paradigm states that a
simulation is composed of three parts:
The model, which describes the phenomenon
under study in terms of
variables, that hold the different possible states
of the phenomenon,
interrelationships among these variables (corresponding to the laws that govern the phenomenon), expressed by computer algorithms.
The control, which defines certain actions that a
user can perform on the simulation.
The view, which shows a graphical representation
of the different states that the phenomenon can
have. This representation can be done in a realistic
or schematic form, but in such a way that the
user appreciates the most relevant aspects of the
simulated phenomenon.
These three parts are deeply interconnected. The
model obviously affects the view, since a change in the
state of the model must be made graphically evident
to the user. The control affects the model because
control actions can (and usually do) modify the value
of variables of the model. Finally, the view affects the
model and the control, because the graphical interface
can contain components that allow the user to modify
variables or perform the predefined actions.
Indeed, modern computer programs are interactive,
which means that the user can modify the programs
logic by clicking or dragging the mouse, hitting the
keyboard or a button on the programs interface (or
view). Thus, the view itself can be used to control the
simulation.

F. Esquembre / Computer Physics Communications 156 (2004) 199204

Thus, creating a simulation in Ejs consists finally in


defining its model and its view, establishing the mutual
connections needed for
the correct visualization of the state of the phenomenon being simulated, and
the appropriate interaction of the user with the
view.

201

In this way, we finally obtain three parts for


our pedagogical simulation: Introduction, Model and
View. Corresponding to this, the Ejs interface is divided into these same three parts. See Fig. 1.

3. Building a simulation using Ejs


3.1. Including narrative

This explicit separation reinforces conceptually the


central role of the model of a simulation. It is the
model which defines what the program simulates and
how. Notice also that there may be different views
for a given model. It also makes the task of creating
a simulation more modular and promotes reusability,
since the parts can be created independently in time,
or by a collaborative group of students, for instance.
Finally, and though it is not really part of a
simulation, it is always convenient to include some
textual description of what a simulation does, or
instructions on how to operate it, specially if we plan
to use it with others, students or colleagues [3]. This is
the purpose of the extra part that we have added to this
structure and that we call Introduction.

In order to encourage authors to provide instructions and explanatory narrative as an integral part of
their simulations, Ejs provides a special-purpose interface that helps create a collection of html pages in
a WYSIWYG (what you see is what you get) editor.
The author can then create as many html pages as (s)he
wants (similar to the one shown in Fig. 2) with the necessary information and/or instructions for the students
as (s)he finds necessary for the pedagogical objectives
of the simulation.
Ejs will not only create the necessary program files,
but will also use these information pages to create a
whole structured set of html pages that includes a page
with the simulation embedded as a Java applet.
The result is a complete pedagogical setting: narration plus simulation that can be readily published on a
web server.
3.2. Creating the model
We create the model of a phenomenon when we define what its relevant quantities (or, in programming
terminology, variables) are, set their values at a given
initial moment, and establish the rules that govern how

Fig. 1. Ejs being used to create the view of a simulation.

Fig. 2. Html page created with Ejs built-in editor.

202

F. Esquembre / Computer Physics Communications 156 (2004) 199204

Fig. 3. Ejs table of variables for the pendulum.

Fig. 5. Evolution page for the pendulum.

on them. We then say that there are constraints


among these variables.

Fig. 4. Further tables of variables for our example.

these quantities change. We will illustrate this process


by a simple example. (The complete example is available on the site http://fem.um.es/publications/2003/
EjsIntroduction.html.)
Suppose that we want to create a simulation of an
undamped pendulum. We will first need to provide
variables that describe the state of the system. Fig. 3
shows the table created with Ejs that contains the
relevant physical variables for the pendulum itself.
There are two other tables used to declare and
initialize further variables. The second table contains
other variables such as time, its increment for each step
of the simulation, gravity, and rectangular coordinates
for our system. Finally, the last table defines variables
related to the different types of energy. See Fig. 4.
Once our variables are defined and initialized, we
need to specify how they change. The state of a model
at a given moment (the values of its variables) can
change due to two reasons:
the inner dynamics of the simulation, which we
call evolution, and
the influence of external agents; i.e. the direct
interaction of the user. In this second case, it
is possible that the user changes one or more
variables that affect others which are dependent

Both processes of change are ruled by equations


that describe the laws under which the evolution
takes place or the interdependence of the magnitudes,
transcribing them into mathematical formulae. We
conclude that to specify the model of a simulation we
need to set the initial state, the evolution equations,
and the constraint equations.
In our example, the evolution equations are not
trivial. They need to express how the pendulum moves
when time increases. In our lectures we show that the
equation for the pendulum can be described by the
formula:
gravity
d2 angle
sin(angle).
=
2
length
d time
This means that we need to provide the code to numerically solve this second-order differential equation.
Fig. 5 shows the corresponding panel in Ejs, where we
have implemented the Verlet algorithm [4].
You will notice that this panel displays further
controls. The slider is used to set the speed at which
the simulation will run, that is, how many times per
second the evolution equations will be called. The
check box indicates that the simulation should start
automatically when loaded.
To finish the model for our example, we may need
to indicate how to compute the value of other variables
that depend on the new state of the pendulum. For
instance, we want to calculate the position and velocity
of the bob in rectangular coordinates in order to
display the pendulum on the screen. We may be also
interested in displaying the kinetic, potential and total
energy of the system. Please notice that the values of
these variables have changed, not as a direct effect
of the evolution, but as a secondary effect of it. If,

F. Esquembre / Computer Physics Communications 156 (2004) 199204

203

Fig. 6. Constraint page for our example.

Fig. 8. View tree for our simulation.

Fig. 7. Solving differential equations using Ejs built-in editor.

for instance, the user decides to change the initial


conditions of the pendulum directly (even when the
simulation is paused), these variables need to be
updated. For this reason, we do not write the relevant
code in an evolution page, but rather in a constraint
page. The relevant code is shown in Fig. 6. Our model
is now ready.
As this example shows, the family of models in
which evolution equations are given by the numerical solution of ordinary differential equations are
fairly common. Describing evolution using differential
equations is rather simple; solving the equations using
appropriate numerical algorithms can be tedious (if
not technically difficult). For this reason, Ejs includes
an editor that helps specify this type of model as well
as automatically creates code, using different standard
algorithms, to solve the equations. Fig. 7 shows an alternative to the previous evolution page using this editor.
3.3. Building the view
In Ejs, a view is created by adding graphical elements that work like building blocks which altogether form the interface of the simulation. The system
provides a wide variety of different elements, based

Fig. 9. Final view for our simulation.

on graphical classes from the Open Source Physics


project [5]. Users can drag any of these elements in
order to add it to the simulation view. Since there are
elements that can host other elements, the result is a
tree-like structure. Figs. 8 and 9 show the tree that we
have created for our pendulum simulation, as well as
the resulting user interface.
In order to connect model and view, we need to
edit the properties of the different view elements to
configure them to use the values of the variables of
the model. For instance, the graphical element called
bob in the view tree has been told to position itself at
the point given by the variables (x, y). Ejs takes care
of all the internal coding needed to cause the bob to
move when the values of x and/or y change.
But this connection works in both directions since,
if the user clicks and drags with the mouse on
the blue circle to reposition it on the screen, the

204

F. Esquembre / Computer Physics Communications 156 (2004) 199204

new coordinates will be taken as values for the


model variables x and y. This connection mechanism
allows really easy creation of dynamic interactive user
interfaces.

4. Using the simulation in a pedagogical setting


Simulations created with Ejs can be run in two
forms. The first one is running the generated simulation as an applet using any of the most popular Web
browsers. Simulations created with Ejs are, once generated, independent of it. A Java applet is a special
form of application that is designed to be run within
a Web browser. The browser loads a file, called an
html page, that includes a special tag (or instruction)
which loads the applet. The browser can then run the
applet embedded into the html narrative or within its
own window. The html page and the files necessary to
run the applet may reside either in a local disk or in an
Internet location, served to the user by a Web server.
Readers who are unfamiliar with Java applets are encouraged to visit the home pages of Ejs [6] to run some
ready-made examples (some rather sophisticated) created with Ejs.
The second possibility consists in running the simulation using Ejs itself as launching pad. This option
has a very important advantage: the user (typically a
student) can learn how the author actually simulated a
given phenomenon. This has, in our opinion, a great
pedagogical added-value.
Using technology for technologys sake in our
classrooms doesnt necessarily leads to better learning.
However, using technology in pedagogically sound
ways can effectively enhance the conceptual understanding of our students, as well as contribute to making our teaching more attractive and effective. In this
sense, before deciding what use to give to our simulations or to tools such as Ejs, it is worth revising some
of the recommendations for best-practices that can be
found in the literature. For a survey see [7].
Using Easy Java Simulations as a tool to let
students see how we, teachers, create simulations
using Ejs (i.e. letting them read our code for our

simulations) and asking them to understand, modify,


or improve our simulations as well as create their
own ones, can help create an environment in which
students become involved in effective pedagogical
methods known as Interactive Engagement [8], where
conceptual understanding is promoted through handson, but also head-on, open-ended activities that take
place in group, with the assistance of an instructor, and
that are enriched with discussion with peers and/or the
teacher.

Acknowledgements
I would like to thank Wolfgang Christian for
introducing me to the Open Source Physics project, on
which Ejs is based. I would also like to thank Fu-Kwun
Hwang for continuous and fruitful discussions on the
use of Ejs as well as for his contributions to the latest
code. Part of this work is supported by Fundacin
Sneca, the Center for Coordination of Research of the
Region of Murcia, Spain.

References
[1] J. Nersessian, Should physicists preach what they practice?, Sci.
Educ. 4 (1995) 203226.
[2] L.M. Lederman, American renaissance in science education,
FERMILAB-TM-2051, 1998.
[3] M. Euler, A. Mller, Physics learning and the computer:
A review, with a taste of meta-analysis, in: Research in Science
EducationPast, Present, Future, IPN, Kiel, 1999.
[4] H. Gould, J. Tobochnik, W. Christian, An Introduction to
Computer Simulation Methods, 3rd edn., in preparation; See
also http://sip.clarku.edu/3e/.
[5] W. Christian, M. Belloni, An open source library for science
and mathematics teachers and curriculum authors, this issue;
See also http://www.opensourcephysics.org.
[6] F. Esquembre, Easy Java simulations web pages, http://fem.
um.es/Ejs.
[7] F. Esquembre, Computers in physics education, Comput. Phys.
Comm. 147 (2002) 1318.
[8] R.R. Hake, Towards paradigm peace in physics education
research, Presented at the Annual Meeting of the American
Educational Research Association, New Orleans, April 2000.

You might also like