How to configure environment variables for beginners through Java is inspired by the beauty of the LINUX System

Source: Internet
Author: User
I learned how to configure environment variables through Java and feel the beauty of the LINUX system-Linux general technology-Linux programming and kernel information. The following is a detailed description. First, when JDK is installed on the XP system, the path is C: \ Program Files \ Java \ JDK1.6.0, in this case, if you open the Command Prompt window (you can select "run" in the "Start" menu of Windows 2000/XP and enter the "cmd" command to open the command character mode ), type C: \> javac and you will find that 'javac' is not an internal or external command, or a program or batch file that can be run. Although you know that JDK tool programs are located in the bin directory, your operating system does not know how to find these tool programs. Therefore, when you enter javac to try to execute the Compilation Program, the javac tool program cannot be found in the command line mode. You must tell the Operating System, under which Directories Should you try to find the tool programs you want to use. There are several ways to perform this setting. The easiest way is to set the Path environment variable in the system variable.

Set Path:

In Windows 2000/XP, you can select "my computer" on the desktop, right-click, select "properties", and switch to the "advanced" page, click the "environment variables" button below to edit the Path variable in the "environment variables" dialog box. Path = C: \ Program Files \ Java \ JDK1.6.0 \ bin open the cmd window and type: C: \> javac to display the Help content of javac. Indicates that the system has recognized javac.

Appendix:

Bin directory

Provides JDK tool programs, including javac, java, javadoc, and appletviewer.

Demo directory

Some sample programs compiled using Java.

Jre directory

JDK's own JRE.

Lib directory

Java tool classes actually used by the tool Program (for example, the javac tool program will actually use the com/sun/tools/javac/Main class in tools. jar ).

Src.zip

The source code compressed file of the API class provided by Java. If you need to check how some functions of the API are implemented in the future, you can view the source code content in this file.

Set Classpath:

The Java execution environment itself is a platform. The programs executed on this platform are compiled Java programs (after the Java program is compiled. class file ).

If you compare the Java execution environment to the operating system, if you set the pathvariable to allow the operating system to find the specified tool Program (find the .exe file in Windows), set the Classpath to allow the Java execution environment to find the specified Java program (that is, the. class file ).

There are several ways to set Classpath. The simplest way is to add the Classpath environment variable to the system variable. Add Classpath =. In "system variables" like PATH .; c: \ Program Files \ Java \ JDK1.6.0 \ lib \ toola. jar; C: \ Program Files \ Java \ JDK1.6.0 \ lib \ dt. jar;

Of course, you can also set java_home = C: \ Program Files \ Java \ JDK1.6.0

Compile the original program in Notepad as follows:

Public class Helloworld
{
Public static void main (String [] args ){
System. out. println ("Hello, World! ");
}
}

File Name: Helloworld. java

Stored in the C: workspace directory

Open a command line

> Cd C: \ workspace

> Javac Helloworld. java compilation is normal.

> Java Helloworld running error

Error message: Exception in thread "main" java. lang. NoClassDefFoundError: HelloWorld

Is the famous classpath problem. In fact, the class path is a concept in Java involved in the compilation process. Classpath is the class used to specify where to find it, which is so simple. Because our HelloWorld does not use other (non-java. lang Package) classes, this problem is not encountered during compilation. During running, you must specify where your class is. If there is a problem with the class path, the above error will occur during the runtime. however, there is no problem with my class path settings, which is quite depressing. If I use the baidu search solution, the settings according to what others have said are not solved, so I don't even understand it, I don't understand the error.

Try to use java-classpath. HelloWorld to output correct results. If you do not understand ("." indicates the current directory)

And then use java HelloWorld to run it without any errors. Strange.

It is really better to use other JAVA development tools. environment variables have been automatically configured. For example, how good is this program for Borland. I installed JDK in linux and configured environment variables, compile and run the following process:

Ahlian @ Ahlian :~ $ Cd/home/ahlian/workspace
Ahlian @ Ahlian :~ /Workspace $ javac HelloWorld. java
Ahlian @ Ahlian :~ /Workspace $ java HelloWorld
Hello World!

There is no error Report, which is perfect. I have always been very fond of ubantu LINUX. I feel that the interface is very friendly and a truly personalized system. You are welcome to use it.
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.