Introduction to Java


Java is an object-oriented language

On the internet you can find a wide variety of hosts (computers), each with some things that it will do for you. You accomplish jobs by asking hosts to do them for you, and a complicated job might require you to exploit the capabilities of several hosts.

Java is a programming language that encourages you to build programs by mimicking the idea of the internet within your program, on a much smaller scale. You create types of hosts, where a host of a given type has certain capabilities, and then you create particular hosts of a given type in a way similar to how an automobile factory creates many cars of a particular model. Finally, all of those hosts interact with one another to solve a problem.

The types of hosts are called classes and the hosts themselves are called objects. Every object belongs to a class.


Computation

Many of the computational ideas in Java are similar to the ones that you have studied using Cinnameg. For example, there are numbers, expressions, variables, if-statements and while-loops. They look a little different in Java, and the next few chapters explain how to use them.

To make it clear what is Java, we show things that are written in Java in dark blue.


Free form

Like Cinnameg, Java is free-form. That means that the end of a line is normally treated like a space. You can run a statement across several lines without a problem.


Comments

You write a comment in a program just to help explain things to a person reading the program. The compiler ignores it.

There are two kinds of comments in Java. The first kind starts with // and goes to the end of the line. (This is an exception to the rule that the end of a line is like a space.) For example,

  // This is a comment.
  // It would be nice if it had
  // something useful to say.
The second form starts with /* and ends on */. For example,
  /* This is another comment.
     It can go over several lines.
  */


Java library documentation

Part of what we describe here is the Java language, and part is the Java library. For example, when we describe what if-statements look like, we are describing the Java language, but when we describe operations that are available for strings, we are describing the Java library. (When you are learn Spanish, you need to learn rules for how to form sentences from certain kinds of words, and you also need to learn a vocabulary of words that you can use. The library is a bit like the vocabulary, while the language is like the general rules.)

Documentation on the Java library is available online. See Java 1.6 classes. To find documentation on a particular class, click on the class in the left-hand frame, then find what you are looking for in the right-hand frame.