Getting Started with Java Programming
The late 1980s saw several advances in software development, and by the early 1990s, many large programming projects were being written from prefab components. Java came along in 1995, so it was natural for the language's founders to create a library of reusable code. The library included about 250 programs, including code for dealing with disk files, code for creating windows, and code for passing information over the Internet. Since 1995, this library has grown to include more than 2,700 programs. This library is called the API — the Application Programming Interface.
Every Java program, even the simplest one, calls on code in the Java API. This Java API is both useful and formidable. It's useful because of all the things you can do with the API's programs. It's formidable because the API is so extensive. No one memorizes all the features made available by the Java API. Programmers remember the features that they use often, and look up the features that they need in a pinch.
So many ways to write computer programs
To write Java programs, you need three tools:
- A Java compiler
- A Java Virtual Machine.
- The Java API.
You have at least two ways to get these tools:
- You can download these tools from the Sun Microsystems Web site.
- You can use the tools that come with a commercial product.
- If you own a copy of Borland JBuilder, Metrowerks CodeWarrior, IBM Visual Age for Java, or IBM WebSphere Studio Application Developer (WSAD), then you already have the tools that you need.
Two bags of goodies
Sun's Web site bundles the basic Java tools in two different ways:
- The Java Runtime Environment (JRE): This bundle includes a Java Virtual Machine and the Application Programming Interface. With the JRE, you can run existing Java programs. That's all. You can't create new Java programs, because you don't have a Java compiler.
- The Software Development Kit (SDK): This bundle includes all three tools — a Java compiler, a Java Virtual Machine, and the Application Programming Interface. With the SDK, you can create and run your own Java programs.
Note that an older name for the Java SDK is the JDK — the Java Development Kit. Some people still use the JDK acronym, even though the folks at Sun Microsystems don't use it anymore.
How do you type this stuff?
A computer program is a big piece of text. So to write a computer program, you need a text editor — a tool for creating text documents. A text editor is a lot like Microsoft Word, or like any other word processing program. The big difference is that the documents that you create with a text editor have no formatting whatsoever. They have no bold, no italic, no distinctions among fonts. They have nothing except plain old letters, numbers, and other familiar keyboard characters. That's good, because computer programs aren't supposed to have any formatting.
A document with no formatting is called a plain text document.
Documents without formatting are fairly simple things, so a typical text editor is easier to use than a word processing program. (Text editors are a lot cheaper than word processing programs, and they're lightning fast. Even better, text editors take very little space on your hard drive.)
You can use a word processor, like Microsoft Word, to create program files. But, by default, word processors insert formatting into your document. This formatting makes it impossible for a Java compiler to do its job. Using word processors to write Java programs isn't recommended. But, if you must use a word processor, be sure to save your source files with the .java extension. (Call a file SomeName.java.) Remember, also, to use the Save As command to save with the plain text file type.
Using a customized editor
Even if you don't use an integrated development environment, you can use other tools to make your programming life easy. Think, for a moment, about an ordinary text editor — an editor like Windows Notepad. With Notepad you can
- Create a document that has no formatting
- Find and replace characters, words, and other strings
- Copy, cut, and paste
- Not much else
Notepad is fine for writing computer programs. But if you plan to do a lot of programming, you may want to try a customized editor. These editors do more than Windows Notepad.
- Syntax highlighting
- Shortcuts for compiling and running programs
- Explorer-like views of your works in progress
- Code completion
- Other cool stuff
When it comes to choosing a custom editor, two favorites are JCreator and TextPad. JCreator has lots of cool features, including tools to write some boilerplate Java code. TextPad has fewer Java-specific features, but TextPad is a great general-purpose text editor.