Basics of the Java Language

Time to learn a little about the Java Language before you write any code. Java is an attempt to come up with a machine independant language for the World Wide Web. Java's closest relatives are the C family of languages, C, C++ and Objective C. In fact, I think that Java is what happens when C becomes Object-Oriented the right way. Java does not have all of the features of C++ but this is, in my opinion, a good thing. Java can best be described as a merging of C and some of the qualities of languages like ADA and Pascal. If you do not have any experience with any of these languages then I suggest that you skip ahead to the next subject.

Java has eliminated pointers. No more of the problems associated with peope mismanaging pointers, but it loses the powerful ability to do pointer arithematic. Java has implemented a garbage collection scheme to reclaim memory that is no longer being used.

Java does not support the struct or union datatypes. Everything in Java is classes, classes, and classes. No function may appear outside of a class definition.

Java is object-oriented. Java has classes, the ability to override functions, and the ability to create functions with the same names but that take different types of parameters. Java has single inheritance, one class can only inherit from one other class.

Java created a base language class called String which allows the easy manipulations of strings. No longer does the programmer have to worry about null terminated strings and forgetting the space for the null.

Java has the idea of packages like in Ada. The main difference is that the base packages are automatically usable at any time during a Java program or Applet with a fully qualified name. For example, declaring a string variable as such: java.lang.String str is perfectly legal. The import keyword is simply the equivalent of the USE keyword in Ada. There is no equivalent of the Ada WITH keyword.

Java classes have the same three parts as C++ classes, a private part, a public part, and a protected part. The private part of a Java class contains functions and variables only visible by that class, the public part contains functions and variables available to anyone, and the protected part contains functions and variables only available to that class and those classes that directly inherit from this class.

Java does not allow operator overloading.

Java has made goto a reserved word but does not implement goto.

Java is a strongly typed language.

Java does not have a main routine which gets called to start an Applet. The closest equivalent to main is the run function. An applet must override the run function and put all the main loop code there.

Java Applets have the C++ idea of a constructor called the init function. The init function as constructor is specific to applets, regular Java classes have constructors exactly the same as C++ constructors. In other words, Java classes use the class names with a different set of parameters to denote constructors with different sets of arguments.

Java Applets have the C++ idea of a destructor called the finalize function. The trick here is that since there are no pointers, the garbage collector will call the finalize routine right before an object gets collected. The garbage collector can be called anytime so do not count on calls to the finalize function to cause the timely clean up of your objects.

I believe that these parts of the Java language will help to propel it to become one of the most widely used languages around the world. Now on to the Applet tag lesson!



Prev Subject Next Subject