How to configure JDK 1 in Win9X 1.1 What is JDK JDK is an abbreviation for Java Develop Kit. It is an early Java development package name. It has been extended to this day! When JDK issued a version 1.2 in 1998, Sun used Sun Company used new Name Java 2 Platform comes Java to translate into Chinese is "Java Platform", modified JDK called J2SDK, Java 2 (Platform) Software Develop Kit, and is divided into standard version (Standard Edition), also known as J2SE, Enterprise It is also known as J2EE, microReition, also known as J2ME. They have different purposes, but the most basic development kit is still J2SE.
1.2JDK's latest version of JDK's latest version can be downloaded in java.sun.com, until 2002-6-5, J2SE is released to 1.4.0. In Win32 (WIN9X or WINNT / 2000 / XP), there is English and international version (International), the international version of the tool has Chinese tips! JDK download address is 1.4 version http://java.sun.com/j2se/1.4 /Download.html 1.3 version http://java.sun.com/j2se/1.3/download.html does not recommend 1.2 previous version unless you have special requirements! Use J2se 1.4 English version in this document
1.3 Installing J2SDK JDK downloaded from SUN is an executable file, about 30 megabits, direct execution. Note that it requires an installation directory, which is JDK1.x.x by default! This directory is modified! To facilitate the following description, it is assumed to be installed in the D: / J2SDK / SE14 directory. Finally, JDK will automatically install a Java runtime environment (Java Runtime Enveronment) in C: / Program Files / JavaSoft / ... Don't get it with the JDK directory above!
2.JDK details
2.1JDK's virtual machine JDK is divided into two parts. First, the Java runtime environment mentioned above is the development environment. They have a Java virtual machine that has a JRE directory in the directory of the Java runtime environment and development environment, respectively, this is the real Java virtual machine! The virtual machine of the Java runtime environment is: C: / Program Files /javasoft/.../jre 1.4 Possible: C: / Program Files / Java / J2RE1.4.0 Java development environment Virtual machine in: D: / J2SDK / SE14 / JRE has many java.exe in the entire Windows environment Executable files, ultimately they are called virtual machines that call one of the above! Selecting the virtual machine to use the Java Runtime Environment menu in the Java Plug-in, the Java Rutime Environment menu on the Advanced tab to use the Java runtime environment Virtual machine. This two virtual machines installed in the same JDK basically no difference!
2.2 Executable Document Java.exe and Javaac.exe Selection These two tools are used to perform Java programs and compile java programs! There are multiple Java and Javac files on machines with JDK! We can set the environment variable Path To choose to use a Java.exe or JavaC.exe file! Multiple versions of Java.exe and JavaC.exe cannot be universal, and you can't modify the location! That is to say when you move the java.exe under the Windows directory to JDK installation. In the directory, it may not be executed (early java.exe is like this, there is no such statement after 1.3, everyone can try it, 1.3 seems to get the location of the virtual machine through the registry, not relative path! ). Recommended Java.exe under the C: / J2SDK / SE14 / BIN directory, this is a habit, there is no necessary reason! At this time, PATH can be set to Path = C: / J2SDK / SE14 / BIN;% PATH%, pay attention There is also a java.exe !! also even if you don't set the PATH, you can execute the Java program! In the PATH variable, the higher the executable of the directory will have the higher priority execution! When there is file C.EXE in the directory A and directory B, if a in Path is in B, the c.exe under the A directory is executed instead of the B / C.EXE2.3 path, which is an old problem. After 1.2, ClassPath will no longer need to set the path of the system class! ClassPath is set to set the class or third-party library written by the user! For example, the user will compile the class in the x: / pathto / classes directory, In the Classes directory, the package directory, such as COM / Some / ... may also be used directly when the class file helloWorld.class is executed, the current directory is any!> java -cp x: / pathto / classes HelloWorld -cp followed by ClassPath The effect of setting the environment variable ClassPath is the same! You can also use compressed files, such as ZIP or JAR in ClassPath. If the user puts helloworld.class into some.jar files!> Java -cp x: / patto / some .jar HelloWorld When mixing multiple directory or JAR files, Java virtual machine performs the first category!> java -cp x: / pathto / classes; x: /pathto/some.jar HelloWorld will not perform Some. HelloWorld.class in Jar
2.4 Compile HelloWorld.java
2.4.1 Compiling the java program for the unpacking (public bag) HelloWorld.java is as follows: // This is not used here! // package nyra.pljc.helloworld.win9x;
Public class helloworld {public static void main (string [] argv) {system.out.println ("Hello, World!");}}
Note that Java is case sensitive, please pay attention to the case!
HelloWorld is saved in x: /mywork/helloWorld.java, pay attention to the file name, and the classes applying to public can only save in the same name file (case in cases)! Compile, the current directory is any!> Javac -SourcePath x: / mywork HelloWorld.java Note SourcePath is the source file directory! You need to use ClassPath when you need to reference other classes (CPATs) as follows:> javac -sourcepath x: / mywork -classpath x: / otherclass helloWorld.java2.4.2 compile The content of the packageful Java program HelloWorld.java is as follows: // Note, the package !! package nyra.pljc.helloWorld.win9x;
Public class helloworld {public static void main (string [] argv) {system.out.println ("Hello, World!");}}
Note that Java is case sensitive, please pay attention to the case!
HelloWorld is stored in x: /mywork/helloWorld.java, pay attention to the file name, and the classes applying to public can only be saved in the same name file (case in cases)! Source files do not have to be saved in the package directory (Nyra / PLJC / HelloWorld) / win9x) Next! Compile, the current directory is any!> javac -sourcePath x: / mywork -d. helloWork -d. HelloWorld.java Note -D. refers to generate a package directory and class file in the current directory, if not specified -D Generate HelloWorld .class in the current directory, execute Java HelloWorld will prompt this class because there is no package directory, so be sure to use -D to generate a class file in the original file directory (x: / mywork), use -DX : / mywork
2.4.3 Compilation File Finding Sequence When you need class StrangeClass, Java will look for the StrangeClass.class file Java program first check the bootstrap core class directory, if there is no target check the EXTENSION class directory, and its directory in the JAR file (this directory in the virtual machine directory JRE / lib / ext), if you do not check the directory and JAR file specified by ClassPath, if there is no {{{∷}}} check the current directory! If Javac is executed, if it is java.exe directly prompts that there is no class! Check if there is a source file if you need a class source file. If you have to compile it, if you don't check the list of compilation files, there is no need for a source file, if you have it, if you have it, if you don't prompt the lack of class!
3. FQA this FQA part from BBS Shuimu Tsinghua Station Smth.org Forum (this is not a good FQA, I am going to rewrite one, the right to rewrite one, the right is in full!) Error 1: 'Javac' is not internal or external command, nor can be run Program 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 whe98; C: /JDK1.2/bin, then under the control panel -> System -> Advanced -> Environment Variables -> System Variable ... I saw? Double click on Path, add C: /JDK1.2/bin in the back. Of course, we assume that JDK is installed in a C: /JDK1.2 directory (a little Tang Yan?) ... It seems to restart the system to work ... (// know! // Tomato) Good, 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 called "HelloWorld.java". PUBLIC CLASS HelloWorld {^ This problem is because your name is inconsistent with the name of the file. (Who said, clearly seeing that people have such a writable) OK, accurately, can define multiple classes in a Java source program, but the classes with public attributes can have one, and they are related to the file name Consistent. 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 are different, so ... oh ... good, change, 嘻 ... ... javac helloworld.java ... (咦, how is it?) / / Faint this is the compilation pass! See if you have a HelloWorld.class? (Hehe .. Teaching :) Java HelloWorld (!! I know, not java helloWorld.class 哟)
* Error 4: Exception in thread "main" java.lang.noclassdefounderror: helloworld huh, this is the famous 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 "." The current directory can be used. Of course, this is a bit trouble (it is "too much trouble"!), We can set the default classpath in the environment variable. Methods are set by the above settings. Set ClassPath = .; c: /jdk1.2/lib/dt.jar; c: /jdk1.2/lib/Tools.jar The two suggestions behind it also set up. Java-ClassPath. HelloWorld (I don't want to learn Java again) * Error 5: Exception in thread "main" java.lang.nosuchmethoderror: main (// 咣) Don't stay. Look at your code, the problem is in the definition of the main method, write it to the place, is it written? Public static void main (string args []) {// One word should not be poor, don't ask why ... Yes, including uppercasements! Java-ClassPath. HelloWorld (listening to the heavens!) Hello World! (Faint! Finally ...)