Forwarding the work from the AK47 from the Chinajavaworld Forum, it is the most comprehensive introduction to the beginning of Java, as of now.
For a Java's beginners compile the HelloWorld program, they can truly enter the rookie stage of Java.
I think of a variety of errors when I start compiling the HelloWorld program. Until I saw the following article, I finally finished my HelloWorld program.
So I put this article reprint this article
Ask the people who have a HelloWorld issue is too much, and often start with "ask a simple question". its
Recalling, I have come from this stage, saying "Hello", is really a simplest problem.
? ... // Think is good, the words come true, let's say "HelloWorld!" in java ...
First of all, we have to assume that our platform is Windows JDK (the Linux environment is almost almost). This environment
It is quite common, foundation, and entry. Determine the JDK that has been installed correctly, the next step is to be carefully knocked into a teaching
The HelloWorld source code, store, then compile, Javac ... The problem is coming:
* Error 1:
'Javac 'is not internal or external commands, nor is it runable or batch files.
(Javac: Command Not Found)
The reason is that no environment variable path is set. Add to use in AutoExce.bat under Win98
Path =% path%; C: /JDK1.2/bin ,win2000 Next Control Panel -> System -> Advanced -> Environment Variables -> System
Item ... I saw? Double click on Path, add C: /JDK1.2/bin in the back. Of course we assume that JDK is installed.
C: /JDK1.2 directory (a little Tang Yan?) ... It seems to restart the system to work ... (// know! // West
Orthoptics)
Ok, try again! Javac HelloWorld
* Error 2:
HelloWorld Is An Invalid Option OR Argument.
Please, give some professionalism, Java's source program is necessary to save .java file, and write all time
.java.
OK, Javac HelloWorld.java (this time should I become?)
* Error 3:
HelloWorld.java: 1: Public Class HelloWorld Must Be Defined in a File Called
"HelloWorld.java".
Public class helloworld {
^
This problem is because your name is inconsistent with the name of the file. (Who said, clearly seeing people have
Written this; () OK, accurately, in a Java source program can define multiple classes, however, has public
Attributes can only have one, and they are consistent with the file name. Also, the main method must put it in this public
In the class, this class can be java (run) this class. Another point is that the Java language is strictly sized.
Beginners should pay attention. Like the above case, helloWorld and HelloWorld think are different, so ...
Oh ... ok, change it, 嘻嘻 ... javac helloworld.java
... (咦, what is there?) // Faint This is compiled! See if you have a HelloWorld.class?
(HEHE .. Take the book :) Java HelloWorld (!! I know, not java helloworld.class
Yo)
* Error 4:
Exception in thread "main" java.lang.noclassdeffounderror: HelloWorld
Oh, this is the famous classpath problem. In fact, the class path is in the compilation process.
The concept of Java involved. ClassPath is to specify where to find the class, it is as simple as it is. Due to our
HelloWorld is not used in other (non-java.lang package) classes, so they did not encounter this problem when compiling. run
When you want to indicate where your class is. Workaround, you can run with the following command:
Java-ClassPath. HelloWorld
"." Represents the current directory. Of course, this is a bit trouble (it is "too much trouble"!), We can be in environment variables
Set the default classpath. Methods are set by the above settings. Set ClassPath to:
Classpath = .; c: /jdk1.2/lib/dt.jar; c: /jdk1.2/lib/tools.jar's two suggestions also
It is developed in the future.
Java-ClassPath. HelloWorld (I don't want to learn Java again.)
* Error 5:
Exception in thread "main" java.lang.nosuchmethoderror: main
(// 咣) Don't, stick to it. Look at your code, the problem is in the definition of the main method, write it to the place,
Is this written?
Public static void main (string args []) {// one word should not be poor, don't ask why ...
Yes, including case yours!
Java-ClassPath. HelloWorld (Listen to the heavens!)
Hello World!
(Faint! Finally ...)
Welcome to the Java world! Therefore, it is not a "simplest problem" that cannot be running helloworld is really a "simplest problem".
Attached: HelloWorld.java
// HelloWorld.java
Public class helloworld {
Public static void main (string args []) {
System.out.println ("Hello World!");
}
}