Java course - Introduction
What is Java?
Java's quite a new language which (unlike C++) wasn't forced to remain closely compatible with predecessors so it was able to take advantage of modern computing and programming developments. It was designed to be a "simple, object-orientated, distributed, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, and dynamic language". I won't go into all of those terms now but some are worth highlighting
- object-orientated (more purely than C++). A few non-object datatypes exist (integers, etc) but even they have object-based analogues.
- distributed (also via the WWW. Its rise coincides with the early days of the WWW)
- interpreted (an example later)
- portable (a good thing)
Since its birth in 1996 it's been updated several times (in contrast, C++ is about to undergo its first major update since 1998). This speed of change, and the occasional problem with portability, meant that Java wasn't in its early days the stable, same-everywhere platform that people were hoping for. For a history, see the wikipedia entry. The current version (2011) is called Java 7. It's quite like C# or modern C++. generics are rather like C++ Templates. There's no multiple inheritance (though Interfaces fulfill a similar role) and no operator overloading. It has garbage collection (so fewer bugs? Less programming effort? Slower, bumpier performance?)
What's it used for?
Almost everything except operating systems.
- Education - It's used at many universities as a first language. Several 4th years here use it for projects
- Industry - Used in anything from toasters and TV set-tops to full Word-like applications
- Android - Most Android Apps are written in Java, though Android is Linux-based and by the time the Apps are run they've gone through some conversions.
It still has trouble shaking off a reputation for slowness and memory-hungriness, but statistics suggest it's really not so bad.
Jargon
As well as using computer science terms like "object-orientated" the Java world has its own jargon too
- Java 2 Platform (Java 1.2 - we have Java 1.6).
- JDK - Java development kit (you need it to write programs)
- JIT - Just-In-Time compiler (runs Java faster)
- JRE - Java runtime environment (you need it to run programs)
- Applets - applications designed to be run via a WWW browser (an example later; shows the benefits of inheritance). Applets are an alternative to Flash.
- JavaBeans - JavaBeans architecture provides a way of designing reuseable software components
- Swing - better graphics! Project Swing classes enable programmers to specify a different look and feel for each platform, or a uniform look across all platforms.
- Packages - add-ons
The Package Tour
There's a lot to explore - over 2300 classes! All classes are in packages (usually easy enough to guess which package a class is in).
- Basic (java.lang, java.util, java.math, etc)
- Graphics (java.awt - Abstract Windowing Toolkit, javax.swing, etc)
- I/O (java.io, etc)
- Network (java.net, java.applet, etc)
- Components (java.beans, etc)
- DB (java.sql, etc)
- Text (java.text, etc)
import java.awt.Graphics means that the Graphics class in the java.awt package is made known to the current class. import java.awt.* imports the whole package but not sub-packages. java.lang is automatically imported.
It's not always obvious where things are
- BigInteger is in java.lang rather than java.math
- HTML handling is in javax.swing.text.html (in version 1.2 anyway)
To give you a flavour of what's possible, try the Java2D applet demo
OK, so how do I learn it?
Many books exist (though beware of versions). Don't expect an easy read: "Beginning Java 2" (Ivor Horton) is 1233 pages long; "Java in a Nutshell" (Flanagan) is 1225 pages long. Much information is online too. Here are 3 suggestions
- java.sun.com's tutorials - the home of Java
- Introduction to Programming Using Java by David J. Eck
- CUED's material - which includes short illustrative examples will, I hope, give you a feel for Java's style of programming and its power. Java's especially handy if your programs needs a little bit of network/web or graphics code. A Java program of a few dozen lines might do the job of 100s of lines of C++ code, and even then the C++ code might be OS-specific.
On the teaching system we have netbeans, a development environment for writing Java programs which also includes documentation.