Here you will learn how to think about Java programs and programming.
Talking to the Computer
Programs consists of statements, like a book written in English consists of sentences. However, a program look more like a complex instruction manual than it look like a novel. Programs may be written using English words, but programming a computer does not even come close to having a conversation with a human being. The computer will follow the rules of the language blindly, and everything you say to the computer is treated in a mechanical fashion. The computer demands precise communications, and it will never try to second guess what you really meant to say.
There are a few important facts you should know about programs, that will save you a lot of trouble:
- The computer can process one and only one statement at a time — and no more.
- The computer will only be concerned about the current statement — and only the current statement.
- The computer will do exactly what the statements tell it to do — and nothing else.
Types of Programs
A Java program usually run either as an application, as an applet or as a servlet. Applets are highly specialized programs that run inside HTML pages. Servlets are highly specialized programs that run on Web servers. Applications are stand alone programs, and don't need a browser or a server in order to run. Applications behave similarly to programs written in other languages.
In this tutorial, a Java program refers to both applets, applications and servlets. However, most examples in this tutorial are applications and Swing applications, because applications are more general than applets or servlets. Also, it is difficult to make applets run under different browsers. Applets have limited screen estate and cannot easily resize inside an HTML page. Everything you can do with an applet, you can do with an application, except, of course, run inside an HTML page. You may also run applications using Internet with the Java Web Start Application Manager.
In this tutorial, we will concentrate on writing programs that are applications and Swing applications. When you write programs, keep in mind that programming languages are somewhat limited in how you may express what you want the computer to do.