The programming language that we're going to be using in this book is called Java. It's a language invented by James Gosling (http://java.sun.com/people/jag/) at Sun Microsystems.
2.1.1. History of Java
Back in 1990 Sun created Project Green to try and predict the next big thing in computers. The goal of the project was to try and develop something to position Sun ahead of its competitors. They thought that the next big thing would be networked consumer electronics devices like set-top boxes for downloading video on demand. They tried to develop a prototype using C++, but after many problems they decided to develop a new object-oriented language which they originally named Oak, after a tree outside James Gosling's office. They created a demonstration but the cable companies weren't really interested and the future of the project was in doubt.
At a brainstorming session they decided to try to reposition the language for use with the Internet. They created a Web browser that had programs (applets) embedded in HTML pages to do 3D rotation of a molecule and animation of a sorting algorithm. They showed this at a conference. At that time Web pages didn't respond to user action. They simply displayed text and unchanging graphics. The audience was amazed to see the user rotate a 3D molecule on a Web page.
A patent search found that there was an existing programming language with the copyrighted name Oak, so the team brainstormed new names at a local coffee house and Java was selected. Java was released for free in 1995. Since then it has become one of the fastest adopted technologies of all times. It is now used for more than just Web pages. It is used in many devices from cell phones to Web servers. For more on the history of Java see http://java.sun.com/features/1998/05/birthday.html.
2.1.2. Introduction to Objects and Classes
Java is an object-oriented programming language. This means that the focus is on objects (who) as well as procedures (what). Objects are persons, places, or things that do the action in a situation or are acted upon.
An example might help you to understand what focusing on the objects means. When customers enter a restaurant a greeter will welcome them to the restaurant and show them to their table. A waiter will take the order and bring the drinks and food. One or more chefs will cook the food. The waiter will create the bill and give it to the customers. The customers will pay the bill.
How many people does it take to get a customer fed in a restaurant? Well, you need at least a customer, greeter, waiter, and a chef. What other things are doing action or being acted upon? We mentioned order, table, drink, food, and bill. Each of these are objects. The objects in this situation are working together to feed the customer.
What types of objects are they? We have given names to each thing we mentioned: customer, waiter, food, and so on. The names we gave are how we classify these objects. You probably know what we mean by a customer or food. But the computer doesn't know what we mean by these things. The way that we get the computer to understand what we mean is by defining a class. A class in Java tells the computer what data we expect objects of that class to have and what they can do. We would expect that food would have a name, a price, and a way to prepare it. We would expect that a customer would know what they can afford to pay and how to pay a bill.
Every object of the same class will have the same skills or operations (things it can do) and data or variables (things it knows about). For example, each object of the order class should know which customer placed that order and what food is in the order. An object of the chef class should know how to prepare the food.
There can be many objects of the same class. A restaurant might have three chefs, ten waiters, two greeters, and 100 food objects on its menu. On a given day and time it might have 100 customers.
Why don't restaurants just have one type of employee? One person could greet the customers, take the orders, cook the food and deliver the food. That might be okay if there is only one customer but what about when there are many customers? You can imagine that one person wouldn't be able to handle so many tasks and food would get burnt, orders would take too long to fill, and customers wouldn't be happy. Restaurants break the tasks into different jobs so that they can be efficient and effective. Object-oriented programs also try to distribute the tasks to be done so that no one object does all the work. This makes it easier to maintain and extend the program. It can also make the program more efficient.