Q&A ON Java Program


Q Is SunSoft Java WorkShop another programming language like Java, or is it something else?

A
Java WorkShop is a way to write Java programs in a graphical, point-and-click environment. It was produced by a division of Sun Microsystems, the developer of Java, as an improvement upon the Java Developer's Kit. Other products in the market offer similar features, such as Symantec Café, Microsoft J++, and RogueWave JFactory. For more information on these products, see Appendix B, "Java Programming Tools."

Q I have several word processing programs on my system. Which should I use to write Java programs?

A
Any of them will suffice, as long as it can save files as text without any special formatting. A word processor that shows the line number your cursor is located on is especially useful. (Microsoft Word, for example, shows the line number at the bottom edge of the window along with the column number.) Because the
javac compiler lists line numbers with its error messages, the line-numbering feature helps you debug a program more quickly.

Q How important is it to put the right number of blank spaces on a line in a Java program?

A
Spacing is strictly for the benefit of people looking at a computer program. You could have written the
BigDebt program without using blank spaces or the Tab key to indent lines, and it would compile successfully. Although the number of spaces in front of the lines isn't important, you should use spacing in your Java programs. Spacing indicates how a program is organized and which programming block a statement belongs to. When you start writing more sophisticated programs, you'll find it much more difficult to do without spacing.

Q A Java program has been described as a class, and it also has been described as a group of classes. Which is it?

A
Both. The simple Java programs that you create during the next few hours will create a single file with the extension
.class. You can run these programs with the java interpreter. Java programs also can consist of a set of classes that work together. In fact, even simple programs like BigDebt use other Java classes behind the scenes. This topic will be fully explored during Hour 10, "Creating Your First Object."

Q If semi-colons are needed at the end of each statement, why does the comment line // My first Java program goes here not end with a semi-colon?

A
Comments are completely ignored by the compiler. If you put
// on a line in your program, this tells the Java compiler to ignore everything to the right of the // on that line. The following example shows a comment on the same line as a statement:

debt = debt / 86400; // divide debt by the number of seconds

In this example, the compiler will handle the statement debt = debt / 86400; and ignore the comments afterward.

Q What is a character?

A
A character is a single letter, number, punctuation mark, or other symbol. Examples are T, 5, and %. Characters are stored in variables as text.

Q I get an Invalid argument error message when I use the javac tool to compile the BigDebt program. What can I do to correct this?

A
You are probably leaving off the
.java extension and typing the following command:

javac BigDebt

Make sure that you are in the same directory as the file BigDebt.java, and type the following command to compile the program:

 

javac BigDebt.java

Q I couldn't find any errors in the line where the compiler noted an error. What can I do?

A
The line number displayed with the error message isn't always the place where an error needs to be fixed in your program. Examine the statements that are directly above the error message to see whether you can spot any typos or other bugs. The error usually is within the same programming block.



Post a Comment

أحدث أقدم