After a few years of internal use at Sun, Java was released on the web in 1993 and began to get public attention around 1995 with the official release of version 1.0. Version 1.1 became available in 1997. Note that there are enough differences between the versions that newer code will not run on older web browsers which are Java-enabled.
Java programs are activated in two stages. First, one compiles the Java code which results in a "class" file (written in byte-code). This compiled code can be interpreted by any machine that has a Java intepreter (or, if written for a web page, by a web browser). Because Java is not compiled directly for a specific platform, it is much slower than other languages. Because Java can be run on a variety of machines, it is more versatile than other languages for certain applications.
Applets are Java programs written for linking to web pages and useful especially for graphical features.
sum = 0;
// Test loop
for(int i = 1; i < 10; i++)
{
sum = sum + 1.0/i ;
}
There are some major differences in the languages, however.
class Testjava2 {
public static void main (String[] args)
{
double sum;
System.out.println("Test program");
sum = 0;
// Test loop
for (int i = 1; i < 10; i++)
{
sum = sum + 1.0/i;
}
System.out.println("Sum =" + sum);
}
}
The following is a sample C++ program equivalent to the Java program.
Notice that the main differences consist in the presence of the #include
statement, the main statement, and the output functions.
#include<iostream.h>
int main ()
{
double sum;
cout << "Test program" << endl;
sum = 0;
// Test loop
for (int i = 1; i < 10; i++)
{
sum = sum + 1.0/i;
}
cout << "Sum =" << sum << endl;
return 0;
}
javac Testjava2.java
java Testjava2
Note that one does not include the extension class in this
case.
This page is maintained by Dennis C. Smolarski, S.J.
dsmolarski@math.scu.edu
© Copyright 1998, Dennis C. Smolarski, SJ, All rights reserved.
Last changed: 6 December 1998.