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
  • Print
  • 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.

They have

  • 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.

Comments (3)

  1. Posted by Confused
    I have been working on this JAVA program and can not get it to give me just the years I ask for, for example the input is the salary, a percentage increase and # of years.....when I put 4 years it prints out 7 or 8...please help or advise of my error if possible..thanks.....code is attached... import java.util.Scanner; public class teacherpay { public static void main (String [] args) { double Salary; double percentIncrease; int cntr = 1; double yearWork; double endRaise; Scanner reader = new Scanner(System.in); System.out.print("Enter beginning yearly salary: "); Salary = reader.nextDouble(); System.out.print("Enter desired % increase per year in decimal format: "); percentIncrease = reader.nextDouble(); System.out.print("Enter number of years worked: "); yearWork = reader.nextDouble(); endRaise = (Salary * percentIncrease); while(yearWork <= 10){ Salary += endRaise; endRaise = (Salary * percentIncrease); System.out.println ("Your salary will be $" + Salary + " during year " + cntr); yearWork++; cntr++; } } }
  2. Posted by joe
    Im not sure what your trying to do. your comment was really unclear but if you email me exactly what your trying to do I can help you. import java.util.Scanner; public class Test { public static void main(String [] args) { double endRaise; Scanner input = new Scanner(System.in); System.out.print("Enter beginning yearly salary: "); double Salary = input.nextDouble(); System.out.print("Enter desired % increase per year in decimal format: "); double percentIncrease = input.nextDouble(); System.out.print("Enter number of years worked: "); double yearWork = input.nextDouble(); endRaise = (Salary * percentIncrease); if (yearWork <= 10) { System.out.println("Your salary increase will be " + endRaise); if (yearWork > 10) System.out.println("Your salary increase will be " + endRaise + "During year " + yearWork); } }}
  3. Posted by jack
    hi my names jack I'm 14 years old iv just got in to java and thats what i want to when I'm a little bit older and i was wondering if some people could send me some website names that are good to lern on send me an email(jkdcv1@gmail.com) ty.

Leave a Reply


Post Comment

Connect with For Dummies

Sign Up for RSS Feeds

Computers & Software

Inside Dummies.com