There are too many people asking helloworld questions, and they often start with "Ask the simplest question. In fact, I have come from this stage. Is it really the simplest question to say "hello?
First, let's assume that our platform is Windows + JDK (similar in Linux ). This environment is quite common, basic, and entry-level. Confirm that JDK has been correctly installed. The next step is to carefully record the helloworld source code in a tutorial, save the disk, and then compile it. javac... the problem is coming:
* Error 1:
'Javac' is not an internal or external command or can be run.ProgramOr batch files.
(Javac: Command not found)
The cause is that the environment variable path is not set.
Add Path = % PATH % in autoexce. bat under Win98; C:/jdk1.2/bin
Choose Control Panel> system> advanced> environment variables> system variables under win2000? Double-click path and add C:/jdk1.2/bin to it.
Of course, let's assume that JDK is installed in the C:/jdk1.2 directory.
Okay. Try again! Javac helloworld
* Error 2:
Helloworld is an invalid option or argument.
Please give us some professionalism. The JAVA source program must be saved as a. Java file, and must be fully written during compilation. java.
OK, javac helloworld. Java (should this always happen ?)
* Error 3:
Helloworld. Java: 1: Public class helloworld must be defined in a file called
"Helloworld. Java". Public class helloworld {
This is because the name of your class is different from that of the file. (Who said it, obviously everyone else has written it like this) OK. To be precise, multiple classes can be defined in a Java source program. However, only one class with the public attribute can be created and must be consistent with the file name. Also, the main method must be placed in this public class so that Java (run) can be used. In addition, the Java language is case-sensitive and must be noted for beginners. As in the above example, helloworld and helloworld are considered different, so...
Oh... Okay, change it...
Javac helloworld. Java
... (Sorry, why is there nothing ?) // Faint. This is the compilation passed! Check if there is another helloworld. Class?
Java helloworld (not Java helloworld. class, because in the J2EE specification, the ". "indicates the path, if it is Java helloworld. class, the system will look for the class under the helloworld directory. class file, which of course cannot exist ).
* Error 4:
Exception in thread "Main" Java. Lang. noclassdeffounderror: helloworld
Well, this is the famous classpath problem. In fact, the class path is a concept in Java involved in the compilation process. Classpath is the class used to specify where to find it, which is so simple. Because our helloworld does not use other (non-java. lang Package) classes, this problem is not encountered during compilation. During running, you must specify where your class is. To solve this problem, run the following command:
Java-classpath. helloworld
"." Indicates the current directory. Of course, this is a little troublesome (it's too troublesome "!), We can set the default classpath in the environment variable. The method is as follows. Set classpath to: classpath = .; c:/jdk1.2/lib/DT. jar; C:/jdk1.2/lib/tools. the two suggestions behind jar are also set up for future development.
Java-classpath. helloworld (I will not learn Java again)
* Error 5:
Exception in thread "Main" Java. Lang. nosuchmethoderror: Main
(// Stick to it. Look at yourCodeThe problem lies in the definition of the main method. Is it correct? Is it written like this:
Public static void main (string ARGs []) {// do not make any difference in a word. Please do not ask why... correct, including the case!
Java-classpath. helloworld !)
Hello world!
(Faint! Finally ...)
Welcome to the Java World! Therefore, the failure to run helloworld is really not a "simplest problem ".
Appendix: helloworld. Java
// Helloworld. Java
Public class helloworld {
Public static void main (string ARGs []) {
System. Out. println ("Hello world! ");
}
}