Monday, August 4, 2008


Java is a language for writing web pages; it's like HTML and VRML

Java isn't a page description language like HTML. It's a programming language. Description languages specify content and placement; programming languages describe a process for generating a result. Where there is generally a direct mapping between an HTML description of a document and the result, the relationship between a Java program
and its result is likely to be more complex. It's a little like the difference between a list of square roots of numbers from zero to 10 and a program to calculate the list.

Here's an HTML table of square roots:

sqrt(1) = 1
sqrt(2) = 1.41421
sqrt(3) = 1.73205
sqrt(4) = 2
sqrt(5) = 2.23607
sqrt(6) = 2.44949
sqrt(7) = 2.64575
sqrt(8) = 2.82843
sqrt(9) = 3
sqrt(10) = 3.16228


And here's the result of a Java applet:

import java.awt.*;

public class SqrtList extends java.applet.Applet {
public void paint(Graphics g) {
g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
for (float i = 1; i <= 10; i++) g.drawString("sqrt(" + i + ") = " + Math.sqrt(i), 0, (int)i * 16 - 3); } }





0 comments: