How to configure JDK in Windows 2000

Source: Internet
Author: User

Java beginners are often confused about how to configure the Java Development Environment. many friends on the Forum are asking questions about JDK configuration, especially when the Java file is compiled after the configuration, the error message is:

Microsoft Windows 2000 [version 5.00.2195]
(C) Copyright 1985-1998 Microsoft Corp.
C:/> javac helloworld. Java
C:/> JAVA helloworld
Exception in thread "Main" Java. Lang. noclassdeffounderror: helloworld

C:/>

The error message is shown above. The source code is as follows:

Class helloworld {
Public static void main (string [] ARGs ){
// Display "Hello world! "
System. Out. println ("Hello world! ");
}
}

After the translation is run, how does one get exception in thread "Main" Java. Lang. noclassdeffounderror: helloworld ??????? /

For the above problems, we have always solved the problem by adding the path of the directory where the helloworld. Java file is located to the classpath parameter, for example, set classpath = % classpath % ;.;...... (Pay attention to the ".;" here. Let's test it later to see what it means ). I tried it. It seems I can't. I don't know if I have not configured it. I don't know whether the netizens who have answered this question have actually put it into practice. So I tried it myself.

I use win200020.jdk1.30and download j2sdk1_3_0-win.exe in java.sun.com. then click Install to install the default system path on the C: disk, that is, C:/jdk130. After the installation is complete, you need to configure the environment, which involves three parameters: path, classpath, and java_home. In my computer-> properties-> advanced-> environment variables, add these three variables respectively. Their values are:

Name = Value

Java_home = C:/jdk130 (installation path)
Classpath =.; C:/jdk13/lib/tools. jar; C:/jdk13/lib/dt. jar; C:/jdk13/bin;
Path = C:/jdk13/bin;

Then you can confirm.

Note: classpath is used to specify the directory where all referenced classes are located. It allows users to place their classes in different directories, but should let JDK compilation tools know where they are. For example:

Set classpath =.; C:/jdk13/lib/tools. jar; C:/jdk13/lib/dt. jar; C:/jdk13/bin;

The first dot in the command specifies the current working directory of the classpath. This dot is very useful. You can use it instead of entering the complete current directory path. Java programs allow this.

In D: Create a subdirectory Java and write a Java file named hello. java: Enter the DOS mode, enter the Directory D:/Java, and then type javac hello. java, compiled. Then you can run the generated class file using Java hello. The result is output normally. If we add package hello; In the first sentence of the hello. Java file, and then compile the file without any errors, we will see the following error message during runtime:

Exception in thread "Main" Java. Lang. noclassdeffounderror: Hello (wrong
Hello/Hello)
At java. Lang. classloader. defineclass0 (native method)
At java. Lang. classloader. defineclass (classloader. Java: 486)
At java. Security. secureclassloader. defineclass (secureclassloader.
1)
At java.net. urlclassloader. defineclass (urlclassloader. Java: 248)
At java.net. urlclassloader. access0 (urlclassloader. Java: 56)
At java.net. urlclassloader. Run (urlclassloader. Java: 195)
At java. Security. accesscontroller. doprivileged (native method)
At java.net. urlclassloader. findclass (urlclassloader. Java: 188)
At java. Lang. classloader. loadclass (classloader. Java: 297)
At sun. Misc. launcher $ appclassloader. loadclass (launcher. Java: 286)
At java. Lang. classloader. loadclass (classloader. Java: 253)
At java. Lang. classloader. loadclassinternal (classloader. Java: 313)

At this time, during compilation, javac-D. Hello. Java will generate a new subdirectory under the current directory, whose name is hello.

We can use two methods to run the compiled file. In the current directory, enter: Java Hello/hello or Java hello. Hello, so that we can see the running result.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.