1. a language
2. a place
3. a coffee
1. the sun
2. the sun corp.
3. c and c++
Java and ActiveX are not the same thing at all. First of all, ActiveX only works on the Windows operating system, whereas Java is now implemented on almost every modern platform. Secondly, ActiveX makes it awfully easy to meddle with someone's networked PC. Third, Java, because it is not a Microsoft product and runs on almost any machine, will tend to undercut Microsoft's market share and monopolistic influence on the development of internet software. Fourth, there is a large and diverse community of developers who are working on Java projects because they want to, and not because they are forced to. Fifth, Java is a fairly elegant (if imperfect) language.
Like .cgi scripts, Java programs are interpreted at run-time. On certain platforms, such as Linux and now Mac, it is possible to treat Java programs as though they were standard binary applications: double clicking or "launching" these programs works just as it would with a binary. But this is just an automation of the interpretation process. Java files are compiled, but they are not compiled into binary executables, but rather, into a "byte code" that is decipherable by each platform's implementation of java. In other words, you DO have to compile any java program you write, but there is an additional interpretive step that occurs when you want to see it work. This stage is handled by a java-capable browser, such as Netscape, or by the JDK (Java Development Kit).When using a browser, you will be looking at a sub-species of Java program called "applets". They are small applications which appear within tags like
<APPLET CODE="file.class" HEIGHT=100 WIDTH=300>
</APPLET>
This means that there will be a 300x100 rectangle that contains the applet contained in file.class. But it is not essential that a Java program be an applet. For example, the first few excercises that we will create will not be applets. If a Java program is not an applet, then it must have a "main" method. In C and C++ parlance, this is not a new concept, but those who are new to programming must know that this is the place where execution of a program commences.
What does it look like? I suggest you telnet to newmedia and peruse (with an editor) some of the examples in the /usr/local/java/demo/ folder, or you could just look in the text book.Java has many data types that are the same as C, C++:
int a whole number -32768,...,-3,-2,-1,0,1,2,3,...,32768
char a whole number -128,...,-3,-2,-1,0,1,2,3,...,128
Note: normally a char is used to store an ascii value, eg.
myChar = 'A';
where 'A' is the ascii number that corresponds to the letter..
long a whole number that can be enormous, either positively or negatively
float a number with decimal notation capability, eg. -3.21 or 10.516
double a number with more precision than a float, eg. 1.021542
Generally, it has control structures that are much like C:
if( x == 1 ) x++;
will work either in C or Java, where x could be an int, for example.
There is also a Boolean (true/false) type in Java, so one could query: if( myBool ) myBool = false;
which would test the boolean variable myBool and if it's true, makes it false.
Note that one cannot, as in C, test for an integer as in:
if( x ) x++;
This makes sense in C, but Java doesn't think an integer is "true" if non-zero.
Demo
1. Make a file that contains
class helloworld {2. Save the file as helloworld.java
public static void main(String arg[]){
System.out.println("hello world");
}}
3. Type
javac helloworld.java
at the command line. If there are error messages, try to figure out why. You probably mistyped something.
4. If you get a proper .class file, execute it by typing:
java helloworld
Which should produce the wanted greeting.
Helpful Links
The explanatory white paper on Java
Basic information about Java
Documentation on Java