Java environment variable settings

Source: Internet
Author: User

Author: scruffybear

Release time: 13/10/2006

Company: watchdata

If any reprint is found, indicate the source and maintainArticleIntegrity. Thank you!

The Java environment has been configured many times. Every configuration goes online to find the configuration method, which is now recorded to avoid repeated efforts.

Configuration of JDK environment variables:

JDK version: jdk1.6.0

First install JDK in C. After installation, the directory is: C:/program files/Java/jdk1.6.0.

Right-click my computer and select Advanced ---> environment variable. The configuration is as follows:

Java_home = C:/program files/Java/jdk1.6.0;

Path = % java_home %/bin;

Classpath =.; % java_home %/lib/dt. jar; % java_home %/lib/tool. jar;

Click OK.

Helloworld. Java classic testCode:

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

Command Line input: javac helloworld. Java

Generate helloworld. Class

Command Line input: Java helloworld

Print "Hello World!" on the screen! "

Set java_home, classpath, and path as follows:
1. Set java_home:
1. For reference convenience, for example, if your JDK is installed in the C:/program files/Java/jdk1.6.0 directory, set java_home to the directory path, to use this path in the future, you only need to enter % java_home % to avoid entering a long path string for each reference;
Ii. Normalization principle: when your JDK path is forced to change, you only need to change the variable value of java_home. Otherwise, you need to change any document that uses the absolute path to reference the JDK directory, if you haven't completed the changeProgramIf JDK is not found, the system crashes!
3. The third-party software will reference the agreed java_home variable. Otherwise, you will not be able to use the software normally. After using Java for a long time, you will know that if a software cannot be used normally, think about the problem.

2. Set classpath:
This is a very interesting question. Of course, it is also a question that affects beginners. The purpose of this variable setting is to allow the program to find the corresponding ". for example, compile a Java program ---. java,. class class file. If you execute Java A in the current directory, the corresponding result will be obtained (provided that you have set classpath ". "). now. when the class is moved to another directory (for example, "E:/") and Java A is executed, there will be a noclassdeffinderror exception because it cannot be found. class file, now you add classpath :".; e:/"run Java A again to see what the result will be ~~ :)~~~, Everything is normal. The Java Command finds the. Class file through classpath!

3. Set path:
The principle is very simple. Do you want to use % java_home %/bin/Java to execute Java commands at any time? Of course not, so, you can add % java_home %/bin to the path. In this way, we can use Java to execute commands in any path. (When you enter your code in the Command Prompt window, the operating system will find the corresponding application in the current directory and PATH variable directory and execute it .)

In addition, jcreator4.0 is installed, which is easy to use and has a syntax prompt function. I thought it wasn't. Remember that jcreator2.5 was installed after jcreator2.5, and jcreator2.5 needs to be set before it can be used, in configure-> Option-> Workspace-> Class View, select the prompt option on the right, click OK, and enter ". ", the class method is prompted in the drop-down box, hooray!

 

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.