This is part of the labels / documentation for <a href='http://jcm.chooseclimate.org'>Java Climate Model</a><hr/>

#javafuture	¨fut		§The future development of the graphical interface of JCM depends on the evolution of Java Virtual Machines in web browsers (see @aboutjava). Currently most people are using Internet Explorer as their web browser. This contains Microsoft's Java Virtual Machine, which works very fast, but is based on the old 1.1 specifcation of Java. So JCM currently supports Microsoft's JVM as the 'lowest common demoninator', however to do this many wheels were reinvented, to implement components/tools which already exist in later versions of Java  (e.g. lighweight GUI components and event handling, text parsing, collections, java2D graphics etc.). So future development of JCM would be much easier if the latest version of Java were included in all web browsers. The legal case between Sun and Microsoft specifies that Microsoft must drop it's old JVM at the beginning of 2004, however whether another JVM will be included with IE thereafter is still disputed.

Meanwhile, beyond the current version of JCM (July 2003) it is anticipated that new features (especially those mainly for research rather than educational purposes) will be developed using the latest features of java (1.4/1.5), and only retrofitted to support old web browsers if this still seems necessary next year.
  As JCM becomes used more for new research and for organised student courses, the issue of supporting casual web surfers becomes a lower priority (as serious users can install the latest  version of java).  However a web-browser version (with limited features) is still needed to catch peoples interest initially.

#aboutjava		§Java is an computer language,
  developed by <a href="http://java.sun.com"  target="new">Sun microsystems</a>.
  It has an object-oriented structure similar to C++.
  ££jvm ££whyjava 
  <hr>See also<li>@javafuture<li>@writejava

#jvm		§Java is semi-compiled, operating via a "java virtual machine" (JVM).

  The original source code is written as plain text files (ending in .java).
  This must be compiled to java bytecode class files (ending in .class).
  These class files are then interpreted by the JVM.

  Note many class files may also be packaged together in a "java archive" (.jar) file, which is compressed like zip to make it easy to send across the web.

  The class files are the same for any type of computer,
  but the java virtual machine (JVM) is different and must be set up locally,
  as it converts java bytecode to raw machine code, and interacts with the operating system.

  The JVM may be built into a web browser for running applets.
  Internet Explorer and Netscape provide their own JVMs,
  which differ between versions and platforms.
  It's also possible to use a JVM without a web browser (e.g. Sun JRE).

  In theory, this JVM arrangement means you can "write once run anywhere",
  yet the calculations run much faster than directly interpreted languages such as basic or javascript.

  The JVM also incorporates security checks which restrict what an applet loaded across the web can do -for instance it can't load or save files locally, only on the server from which it came.
  This makes it "safe" for applications in web browsers. Also, java was designed to make it easy to communicate across the web, with many networking and "internationalisation" features.

see also<li>@startjcm   <li><a href="../struc/javaproblem.html" target="_new">Problems with Java in your browser?</a>

#whyjava		§Java is currently the only computer language which can both make big calculations efficiently, and draw vector graphics in a web browser (without plugins).
  Hence it is the only way to make a climate model working fast on the web
  (note interactive tools in other languages, require that the server sends a new graphic every time you change something, which is intrinsically much slower).

  The modular "object oriented" structure is good for making an interactive graphical-user interface where the flow may jump about, and where components may be reused in different ways. However java has a steep learning curve, you have to construct a basic framework, before you can develop anything interesting.

 See also:   <li>@struccode  <li>@writejava

#writejava		§££getjdk ££simpleapplets ££javasyntax ££compiletips

#getjdk		§JVMs are built into most web browsers, however to compile your own code you also need the Java Development Kit (JDK or SDK) from Sun microsystems
  (Java was invented by Sun, which is still the best source for the basic tools,
  although the specification is open so others can also develop them)



Go to
  <a href="http://java.sun.com/" target="new">http://java.sun.com/</a>
  and to products and APIs (top-left menu), then pick a version to download.

  This is a dilemma: the basic web browsers (NS4.6+, IE4or5) use a variant of Java 1.1 (with some features missing), but Sun is now promoting Java 1.4 (or even 1.5). JCM is still based on 1.1 for this reason. If you start with JDK 1.1, you won't be confused by many new features that won't work in many web browsers. However, the JDK doc and tools are better in later packages.  <li>See also @javafuture

  Also download the Java Tutorial from Sun
  which you can find under the docs and training section (top-left menu)
  This is a good introduction to the language,
  but has much more detail than you need at the beginning!

  Note as well as the main tutorial package (also big!),
  you are advised to download the old archive "creating a user-interface AWT only",
  since the newer "Swing" classes aren't available in most web browsers.

  Unpack and setup the package on your computer according the instructions included

  Then you can, in theory, start compiling code by typing instructions
  at the DOS prompt (in Windows) or a terminal window (Unix).
  The JDK documentation explains this,

  However you could soon get bored typing in commands this way.

  To make it easier, you can set up windows explorer to compile java files, just by right-clicking with the mouse. This involves some tricks using DOS batch routines,
  which I got from a small package called JDEX.

  Alternatively, use a code-editing tool. I like the <a href="http://mathsrv.ku-eichstaett.de/MGF/homes/grothmann/je/" target="_new">"Java Editor"</a> by Réné Grothmann.  It's simple but flexible to use, and written in Java 1.1 so you can use with wjview (see @startjcm).

#simpleapplets		§An interactive, object-oriented code has no simple beginning and end, but you must start somewhere.

  The best way to learn is by trial and error,
  frequently checking the API documentation that comes with the JDK
  which describes each class in detail.

  An applet is a special class that appears in a web browser.
  Here is the simplest possible:
  <pre>
  import java.applet.Applet;  import java.awt.<li>; 
  public class Myapplet extends Applet {
  public void paint(Graphics g) { g.drawString("Hello",4,20); }
  }
  </pre>

  The first line imports the necessary java packages (awt=abstract window toolkit).
  The next specifies you are adding to the existing Applet class.
  The paint method will be called by the browser which provides the graphics context "g".
  All applets must have either a paint or an init method, which must be declared "public".

  Copy the four lines above into a text file called Myapplet.java.
  Then compile this file, which should produce Myapplet.class
  Then make a very simple web page (put it in the same directory).
  <pre>

  &lthtml&gt&ltbody&gt
  Below is my applet&ltp&gt
  &ltapplet width=100% height40% code="Myapplet.class"&gt&lt/applet&gt
  &lt/body&gt&lt/html&gt

  </pre>

  Then just open that web page, in internet explorer.
  You should see it says "Hello" inside the grey rectangle.

  The example below is more fun, it makes a wavy sea with floating balls.

  <pre>

  import java.applet.Applet;  import java.awt.<li>; 
  public class Wave extends Applet {

  boolean loop; int i,x,y,w,h;

  public void paint(Graphics g) {
  w=this.size().width; h=this.size().height;
  i=0; while(loop) {
  i++; if (i&gt1256) i=0;
  for(x=0; x&ltw; x++) {
  y=(int)((0.5<li>h + (0.4<li>h)<li>Math.sin((double)(x+i)/50.0) + (0.05<li>h)<li>Math.sin((double)(x+i<li>4)/10.0) );
  g.setColor(Color.cyan); g.drawLine(x,0,x,y);
  g.setColor(Color.blue); g.drawLine(x,y,x,h);
  if (((x+(int)(1.5<li>i))%80)==0) {g.setColor(Color.yellow);g.fillOval(x-10,y-8,12,12);}
  if (((x+(int)(2.0<li>i))%150)==0) {g.setColor(Color.red);g.fillOval(x-20,y-16,20,20);}
  }}}

  public void start(){loop=true;}
  public void stop(){loop=false;}
  }

  </pre>

  Now you need this web page to run it:

  <pre>

  &lthtml&gt&ltbody&gt
  &ltapplet width=100% height40% code="Wave.class"&gt&lt/applet&gt
  &lt/body&gt&lt/html&gt

  </pre>

  Once you see what it does when you run it,
  you might be able to understand how the code works,
  by reading my notes on java syntax appended below.

  Notes specific to code above:

<li>start() and stop() are called when you open and close the page (applies to any applet)  <li>while(loop){} will keep looping so long as loop is true  <li>%80 calculates the remainder after dividing by 80  <li>the g.methods are part of java.awt.Graphics but it should be fairly obvious what they do  <li>note the type conversions (double) (int) etc.

  Changing the applet size will change the wave speed too, since the java is calculating as fast as it can. Math.sin is a rather slow function, so you could make this more efficient by storing an array of y values before the main loop.

#compiletips		§This keeps changing with new versions of JDK, JCM etc. Please email ben@chooseclimate.org

#compiletipsold		§Internet Explorer's JVM starts up the first time it meets an applet, and then stays open as long as Explorer does (note your desktop is also a copy of Explorer!). This JVM doesn't check whether you have changed a class file. So to force the JVM to start again after you changed a java class file, use CTRL-F5 immediately after refreshing or reopening the web page. 

 You can instead use the java appletviewer supplied with JDK, which always refreshes. However beware it doesn't understand percentage width/height in the html applet tag! 

 If the compiler reports an error, you won't get any class file, instead a text file describing the errors. 

 But if it succeeds, that doesn't mean you won't sometimes get errors, or "runtime exceptions" which may stop the applet from working. These will usually be reported in "Standard Output". In a web browser, the standard output is the Java Console, which you can find in the view menu in internet explorer (or tools in netscape). If it's not there, you need to enable it first by changing the web browser settings ("java console" or "java logging" under advanced options). The java console also catches anything you write to System.out, e.g. 
 System.out.println("Got to here OK"); 
 (you can put this into your code for debugging)

#javasyntax		§Please see the simple introduction page found in the  jcm/code directory of the package (<a target='_new' href='../code/simplejavasyntax.html'>Here is a link to simplejavasyntax.html'</a>