JDK and IDE
TextPad
Download http://www.textpad.com. Install it on your computer.
Please note: It is important that you install JDK before you start installing TextPad! If you don't do it in that order, sometimes TextPad won't detect that you have JDK, and it won't add its Tools like Compile Java, Run Java Application, etc.
If you don't see Tools, External tools, Compile Java, then you probably did one of the following things:
- Forgot to install JDK, or
- Installed TextPad before you installed JDK.
If you are sure that you did install JDK, then you may have installed it after installing TextPad by mistake. You must have JDK already installed BEFORE you begin to install TextPad. If not, then TextPad doesn't detect JDK's presence, so it doesn't add its JDK Tools. If this is the case, you can also manually add the JDK Tools yourself. In TextPad, click
Configure -> Preferences -> Tools -> Add -> JDK Commands
This should add them for you. If you click as far as the Add button and don't see the option for JDK Commands, then your JDK installation is messed up and you should try it again.
To create a program, do the following:
- open Textpad,
- write your code and
- save it as filename.java (the filename must be the same as the name of the class of your program).
- click on Tools, External tools, Compile Java
- When there is no error in the Tool Output, click on Tools, External tools, Run Java application.
There is a missing semi-colon.
There is an error.
Fix the error.
A common compile-time error message
C:\java\examples\ch01\TestApp.java:6: ';' expected } ^
What it means
The first line in this error message displays the file name of the *.java file, a number indicating the line where the error occurred, and a brief description of the error. The second line displays the line of code that may have caused the error with a caret symbol (^) below the location where there may be improper syntax.
Solution
Edit the source code to correct the problem and compile again.
Another common compile-time error message
C:\java\examples\ch01\TestApp.java:1: class testapp is public, should be declared in a file named testapp.java
public class testapp ^
What it means
The *.java file name doesn't match the name of the public class. You must save the file with the same name as the name that's coded after the words "public class". In addition, you must add the java extension to the file name.
Solution
Edit the class name so it matches the file name (including capitalization), or change the file name so it matches the class name. Then, compile again.
A common runtime error message
Exception in thread "main" java.lang.NoSuchMethodError: main
What it means
The class doesn't contain a main method.
Solution
Run a different class that does have a main method, or enter a main method for the current class.