How to Compile a Java Program in TextPad

To compile a Java 4E program in TextPad, choose Tools→Compile Java or use the keyboard shortcut Ctrl + 1. The javac command compiles the program, and the compiler output is displayed in the Tool Results pane of the TextPad window.

If the program compiles successfully, the message Tool completed successfully appears in the Tool Results pane. If the compiler finds something wrong with your program, one or more error messages are displayed, as shown in the figure.

image0.jpg

In this example, eight compiler error messages are displayed:

javac 1.8.0-ea
C:\Users\Doug\Documents\Java 4E\Manuscript\Apps\Book 1\Chapter 3\HelloApp.java:5: error: unclosed string literal
 printHello("World!);
  ^
C:\Users\Doug\Documents\Java 4E\Manuscript\Apps\Book 1\Chapter 3\HelloApp.java:5: error: ';' expected
 printHello("World!);
  ^
C:\Users\Doug\Documents\Java 4E\Manuscript\Apps\Book 1\Chapter 3\HelloApp.java:8: error: illegal start of expression
 public static void printHello(String greetee)
 ^
C:\Users\Doug\Documents\Java 4E\Manuscript\Apps\Book 1\Chapter 3\HelloApp.java:8: error: ';' expected
 public static void printHello(String greetee)
 ^
C:\Users\Doug\Documents\Java 4E\Manuscript\Apps\Book 1\Chapter 3\HelloApp.java:8: error: illegal start of expression
 public static void printHello(String greetee)
  ^
C:\Users\Doug\Documents\Java 4E\Manuscript\Apps\Book 1\Chapter 3\HelloApp.java:8: error: ';' expected
 public static void printHello(String greetee)
   ^
C:\Users\Doug\Documents\Java 4E\Manuscript\Apps\Book 1\Chapter 3\HelloApp.java:8: error: ';' expected
 public static void printHello(String greetee)
   ^
C:\Users\Doug\Documents\Java 4E\Manuscript\Apps\Book 1\Chapter 3\HelloApp.java:12: error: reached end of file while parsing
}
 ^
8 errors
Tool completed with exit code 1

If you double-click the first line of each error message, TextPad takes you to the spot where the error occurred. If you double-click the line with the unclosed string literal message, for example, you’re taken to line 5, and the insertion point is positioned at the spot where the compiler found the error. Then you can correct the error and recompile the program.

Often, a single error can cause more than one error message to display, as is the case in the fiture. The error is that a closing quotation mark is left after the word Hello in line 5. That one error caused all eight error messages!

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.