In Java, what does path and classpath mean?

Source: Internet
Author: User

Path, where the program (such as Java and javac) to be called during Java compilation is located
. It is generally the bin directory of JDK, for example:
C:/program files/Java/jdk1.5.0 _ 22/bin
Classpath class path. When compiling and running a Java program, if you call other classes, find the desired class in classpath.

Or it can be understood as the storage path of the class file.
.

 

 

 

In Windows, Java mainly uses three environment variables, java_home (which can be set to be easy to understand ),
Classpath and path. The following analysis is performed one by one.

Java_home points to the JDK installation path, such as X:/jdk_1.4.2. In this path, you should be able to find the bin, Lib, and other directories. It is worth mentioning that JDK Installation
You can select any disk directory for the path, but we recommend that you have a lower directory level. If you have a deep directory, for example, X:/xxxxxx/XXXXX/xxxx
/Xxxx/xxx ......


Then, you will be tired of the following steps and future applications. Setting method:

Java_home = x:/jdk_1.4.2

The path environment variable exists in Windows. You only need to modify it to point it to the JDK bin directory, in this way, you do not need to enter a large string of paths when compiling and executing programs in the console. The setting method is to keep the original path content and add % java_home %/bin to it.


(Note: If you do not know about the DOS batch processing, you may not understand the meaning of the content caused by %. In fact, the environment variable java_home set in the previous step is referenced here.
You can also write X:/jdk_1.4.2. You can open a console window and enter echo


% Java_home % ):

Path = % java_home %/bin; % PATH %

Similarly, % PATH % references the previously set path environment variable. You just copy the previous value.

I put the classpath environment variables at the end, because you may encounter inexplicable and strange problems later. More than 80% may be caused by incorrect classpath settings, so be careful.


Classpath =./; % java_home %/lib/tools. Jar

The first thing to note is the front "./;". If you cannot see it clearly, I will read it for you-the backslash. This tells JDK to search for the class file in the current directory first.
-- Why does this happen? This is caused by the Linux security mechanism. Linux users understand that Windows users are hard to understand (because the default search order of Windows is to search first ).
Search for the current directory, then the system directory, and then the PATH environment variable)


So if you like Linux, you may want to study Linux.

Why is the specific file tools. Jar specified after classpath? Not specified? Obviously, no. I can do that again! :)

This is determined by the import mechanism and jar mechanism of the Java language. You can check the information to solve this problem.


The specific setting method is as follows:
Right-click Win2k/XP and choose "my computer"> "properties"> "advanced"> "environment variable". Modify the value in the system variable box below.


The Win9x user modifies the autoexec. BAT file and adds it to the end:

Set java_home = x:/jdk_1.4.2

Set Path = % java_home %/bin; % PATH %

Set classpath =./; % java_home %/lib/tools. Jar

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.