CS 3230 - Chap 1 Notes

Introduction to Java

Just to give a brief overview of this semester's material, if you look at page xviii (Preface) in your book, you will see a bulletted list about a third of the way down the page; all that stuff we will cover in class. About two thirds of the way down the page, you will see another list; that stuff we will not cover in this class.

Two Components of Java Technology

The Language

This is the syntax that Java programs are written in. The Java Language Specification can give you all the gory details (they even have the grammar written in BNF notation. Yee haw.) A program written in Java is compiled to bytecode (see below). (Java code can also be compliled to a native executable; more on this below.)

The Virtual Machine

This is a device constructed in software (or hardware) that accepts bytecode and interprets it. Like a regular hardware architecture, it has an instruction set and an "executable" format. The Java Virtual Machine Specification can give you all the details.

Several languages besides can be compiled down to bytecode and run in a VM including Python and Perl.

How Java Differs from C / C++ (p.3)

If you already know C++, then you know 80%-90% of Java already. There are, however, some notable differences.

If you want to read up on other differences between Java and C++, check out this page, this page, this page, or this page.

Garbage Collection

In C you need to make explicit calls to malloc() (and friends) to allocate memory. You likewise use free() to deallocate memory. In C++ you use the keywords new and delete. In Java, there is a new keyword, but no delete. Ojbects are implicitly deleted when they go out of scope or are no longer needed. This is known as garbage collection.

References rather than Pointers

Java does not have pointers the way C / C++ does. This means it has no * (pointer/dereference) or & (address-of) operators. Pointers are a source of many bugs and a difficult concept for many beginners. Java features instead a "safe" version of pointers called references, which cannot have pointer arithmetic performed on them and must point to a vailid address or null. (Which also means an intruder cannot exploit them subvert / gain access to a system.)

No Global Namespace

In C and C++ you can #define a value or declare a variable as global. You cannot do this in Java. Everything must belong to a class or package. It might hurt a little at first if you are used to declaring global variables, but it pays dividends in the long run.

Alternative approach to Multiple Inheritance

Unlike C++, a Java class can have only one parent (C++ classes can inherit from numerous parents). However, most of the features of multiple inheritance are implemented in the form of interfaces.

Design Goals (or "White Paper Buzzwords" -- p.3)

Here's the official whitepaper that gives this list of buzzwords.

History of Java (p.9)

Here is a brief synopsis of what your book has to say about Java's history:

The following links can give you more information about the history of Java:

Common Misconceptions About java (p. 11)

Your book gives a list of these, I won't go over them but rather let you look at them on your own time.

The only one I will call attention to is that Java and JavaScript are two totally different animals. Here's a breakdown of some of the differences:

Java JavaScript
Compiled + Interpreted Interpreted
Strongly Typed Weakly Typed
Object Oriented Object Based
Owned by Sun Developed by Netscape, owned by no one
General-Purpose Made for Web browsers (active content)

So what similarities do they have? They have some syntactic similarities and they have the letters 'J', 'a', 'v', and 'a' in common. Netscape originally called the language "LiveScript" but wanted to ride the coattails of Java's popularity while Sun was pouring marketing dollars into it.

Shortcomings of Java

Like all other technologies, Java has it's strong points and its weak points as well. It is worth noting that most of the weak points were/are political and not technical.

Slow

This is not exactly news by now. Java runs pretty slow. There are some things which can help speed up Java, though. One is the JNI (Java Native Interface) which gives Java programs access to system-specific shared libraries. Another is JIT compilers which can compile heavily-used parts of the code to native bytecode on the fly.

There are also a few Java to native-code compilers: one called Jikes from IBM and GCJ from GNU / Cygnus. Both of these are licensed as open-source.

Too Much Hype Too Early

Sun & co. were blaring the Java horn long before Java had the features and maturity that people needed. As soon as the 1.2 JDK is released (aka "Java 2") I think we will all have a much more complete development environment.

More Open Process Needed

Sun made much of the development to Java behind closed doors. A number of people who were adopting the technology needed some features which weren't present and felt they were being excluded from the development of the spec. Fortunately, Sun has opened up the process for submitting bugs and taking suggestions for future improvements, but it doesn't compare to the wide-open process that you see with, say, Perl.

License Problems

Sun's Grand Vision was to have Java running on everything. The way they licensed the technology though, you'd think they only wanted it running on Windows and Solaris. The case has been made for other platforms (i.e. Linux) and Java is getting ported to more platforms here and there.

Tight Control

Sun jealously and earnestly defends the Java trademark. Java fans who have written little games using the word "Java" in it's name have, for example, been surprised when they received letters from Sun telling them to rename their project or stop distributing it. See J*va Invaders as an example (you will need to scroll down the page a bit).

On the other hand, Sun's ownership of the trademark (and technology) has prevented Microsoft from "embracing and extending" Java with their "J++" variant. (An offensive tactic Microsoft has successfully used against other technologies deemed "ungood". N.b. This is why Microsoft came out with C#; they were unsuccessful in hijacking Java.) So, from a different point of view, Sun's defense of it's intellectual properties has been a good thing.