For Java beginners, often start with "ask a simple question". Say "Hello", is it the simplest problem? Ok, the words retired, let's say "HelloWorld!" In Java ... First, we have to assume that our platform is Windows JDK (LINUX environment is similar). This environment is quite common, foundation, and entry. Determine JDK installed correctly, if you don't have you download the latest version from Sun's official website (of course, it doesn't matter if you have a little older version, but it is recommended to install 1.4, I use J2SDK1.4.2), the next step is to be careful Try to HelloWorld source code on a tutorial: // HelloWorld.java Public Class HelloWorld {public static void main (string args []) {system.out.println ("Hello World!");} The storage, then compile, Javac ... The problem is coming:
* Error 1: 'Javac' is not internal or external command, nor is it runable or batch file. (Javac: Command Not Found) The reason is that the environment variable Path is not set. Path =% Path% is added to AutoExce.Bat under Win98; C: /J2SDK1.4.2/bin ,WIN2000 Next Control Panel -> System -> Advanced -> Environment Variable -> System Variables ... What is it? Double click on Path and add C: /J2SDK1.4.2/bin later. Of course, we assume that JDK is installed in the C: /J2SDK1.4.2 directory, usually 2000 or XP does not seem to restart the system. 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. Java. OK, Javac HelloWorld.java (this time should I become?)
* Error 3: HelloWorld.java: 1: public class helloworld Must Be defined in a file callad "HelloWorld.java" .public class helloworld {^ This problem is because your name is inconsistent with the name of the file. Accurately, a plus class can be defined in a Java source program, however, classes with public attributes can only have one, and they are consistent with the file name. Also, the main method must be placed in this public class, so that Java can be enabled. Another point is that the Java language is strictly sized, and beginners should pay attention. Like the above case, helloworld and helloworld think it is different, so ... oh ... good, change, 嘻嘻 ... javachelloWorld.java ... (咦, how is it?) // Faint is compiled! See if you have a HelloWorld.class? (Hehe .. Book in book:) Java HelloWorld * Error 4: Exception in thread "main" java.lang.noclassdeffounderror: helloWorld huh, this is the famous class Path (ClassPath) problem. In fact, class paths are the concepts in Java involved in the compilation process. ClassPath is to specify where to find the class, it is as simple as it is. Since our HelloWorld is not used in other (non-java.lang package) classes, there is no encounter when compiling. When running, you have to indicate where your class is. Solution, you can run java -classpath. HelloWorld "with the following command". "Represents the current directory. Of course, this is a bit trouble, we can set the default classpath in the environment variable. Methods are set by the above settings. Set ClassPath = .; C: /J2SDK1.4.2/lib/dt.jar; C: /J2SDK1.4.2/Lib/Tools.jar The two suggestions behind it are also available in the future. Java-ClassPath. HelloWorld (should come out)