Java setting environment variables and running Java programs under DOS

Source: Internet
Author: User

In the school training these days, the teacher took us to start a deep review of Java. This is the first day of the content OH

For "Java setting environment variables and running Java programs under DOS", many beginners are unfamiliar, but understanding this is very important for later learning.

Http://blog.sina.com.cn/s/blog_639403840100i5rt.html

Let's look at what DOS is.

dos

The most frequent use of our computers is DOS. DOS is the abbreviation of the English disk Operating system, meaning "disk operating system", as the name implies, DOS is mainly a disk-oriented system software, said Simple, DOS is a person to the machine command set, is stored in the machine hardware inside some command sets, with DOS, We can easily understand how to give the machine commands, do not have to go into the machine hardware structure, and do not have to memorize those boring 2-digit machine commands, just through some of the English-speaking DOS commands, we can easily complete the majority of daily operations. In addition, DOS can effectively manage a variety of hardware and software resources under its control, reasonable scheduling, all the software and hardware under the DOS monitoring and management, orderly operation.

Common Command editing (used in Java runtime) 1 dirNo parameters: View the files and folders that are currently in your directory. 2 CDCD Directory Name: Enter a specific directory. cd\ back to the root directory. CD.. Go back to the top level directory. 3 MD RdMD Directory Name: Create a specific folder. (Dos under the habit called Directory, win under the custom called the textfolder. )Rd Directory Name: Deletes a specific folder. 4 deldel file name: Deletes a file. del * *: Deletes all files under the current folder. del cannot delete a folder. 5 Setdisplay, set, or delete environment variables. If there are no parameters, the set command displays the current environment settings. 6 Exitexit the Cmd.exe program or present7 Ipconfigdisplays all current TCP/IP network configuration values, refreshes Dynamic Host Configuration Protocol (DHCP), and Domain Name System (DNS) settings. Use ipconfig without parameters to display the IP address, subnet mask, and default gateway for all adapters. So how do you run Java in a DOS environment?First, learn to configure the Java Runtime Environment Open Environment Variables dialog box1. First right click on My Computer, select the Properties option;2. Then click Advanced System Settings and then the System Properties box, in the Advanced tab we can see the environment variable button;3. Click the environment variable to pop up the dialog box, we usually set the path or Classpath Assuming that the JDK is installed on D:\java\jdk1.5.0_08To start the configuration:1. New (if there is no) java_home, the variable value is D:\java\jdk1.5.0_082.PATH Variable value is%java_home%\bin;%java_home%\jre\binthe value of the 3.CLASSPATH variable is.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar (to Add. Indicates the current path) the next test is whether the configuration is successful:under DOS input "Java-version", "Java", "Javac" several commands, appear screen, indicating the environment variable configuration success; Next Compile the program" Start"->; " Run, type "cmd";first, compile a. java fileLet 's start with your first Java program.javac file name. java--in order to generate a. class file (Javac is compiled Java code)Java file name (this step does not suffix) (Java is running Java program) However, in some special cases we may use temporary environment variable configuration. What would you do if we borrowed someone else's computer but couldn't change someone else's computer settings? I think the best way is a mobile flash drive plus temporary environment variable configuration.
Temporary environment variable configuration you can use DOS commands, enter set on the cmd command line, you will see all the environment variables in your computer, and you can display all the variables of path by entering set pathsetting a temporary PATH environment variable is just a matter of typing:
Set Path=f:/demo/java, which has no effect on the configuration in the computer system.   Another input is:
Set path=f:/demo/java;%path%
This means that a path is added to the original setting and has no effect on the configuration in the computer system.
A summary is:
set is used to view all environment variables of this machine;
Set Variable name: View a specific environment variable;
Set Variable name =: empty an environment variable;
Set Variable name = specific value: Defines a specific reference for the specified variable;
Set Variable name = specific value;%path%: Adds a new value based on the original environment variable.
Note: This configuration is only valid for the current DOS window, and the configuration disappears after the window is closed.
Similarly, the temporary configuration of the CLASSPATH environment variable is the same Note: Pathpath allows the system to identify Java commands under any path, set to:%java_home%\bin;%java_home%\jre\binClasspath is the Java load class or lib path, only the class is in Classpath, the Java command is recognized, set to:.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar (to Add. Indicates the current path)%java_home% is referring to the previously specified java_home;  Javac Javac is the Java language programming compiler. The Javac tool reads the definitions of classes and interfaces written by the Java language and compiles them into a class file of byte code. Javac can implicitly compile some source files that are not mentioned in the command line.     The difference between JDK and JRE
http://blog.csdn.net/forwayfarer/article/details/3321410 (favorite blog, for reference)
http://www.cnblogs.com/myitm/archive/2011/05/03/2035942.html (favorite blog, for reference)
the JRE (Java Runtime enviroment) is the Java Runtime environment. For users of Java programs, not developers. If you download and install only the JRE, your system can only run Java programs. The JRE is the set of environments necessary to run a Java program, including the JVM standard implementation and the Java Core Class library. It includes Java virtual machines, Java platform core classes, and supporting files. It does not contain development tools (compilers, debuggers, etc.).

The JDK (Java Development Kit), also known as J2SDK (JAVA2 Software Development Kit), is the Java SDK, which provides a Java development environment that provides tools such as compiler Javac Used to compile Java files into a class file) and the runtime environment (provides JVM and runtime helper packages for parsing class files to make it run). If you download and install the JDK, you can not only develop Java programs, but also have a platform to run Java programs. The JDK is the core of the entire Java, including the Java Runtime Environment (JRE), a stack of Java tools Tools.jar, and the Java Standard Class library (Rt.jar).
Total: The JRE mainly contains: Java Class Library class file (all packaged in the Lib directory as a jar) and virtual machine (jvm.dll); The JDK mainly consists of the Java Class Library's class file (all packaged in the Lib directory as a jar) and comes with a JRE.

Brief introduction of the role of Java_home,path and CLASSPATH environment variables
http://blog.sina.com.cn/s/blog_896994ae0101266a.html (favorite blog, for reference)
1. Path environment variable. The function is to specify the command search path, execute commands under the I command line as Javac compiles the Java program, it looks in the path specified by the path variable to see if the appropriate command program can be found. We need to add the bin directory in the JDK installation directory to the existing path variable, and the bin directory contains the frequently used executables such as Javac/java/javadoc wait, and after setting the path variable, you can execute the Javac/java tool in any directory.
2. Classpath environment variables. The role is to specify the class search path, to use the already written classes, the premise is to be able to find them, the JVM is through the classpth to find the class. We need to set the Dt.jar and Tools.jar in the Lib subdirectory of the JDK installation directory to classpath, of course, the current directory "." must also be added to the variable.
the new version of the software, Classpath seems to have no use, because when the installation of the JDK has been selected and can be added
3. Java_home environment variables. It points to the JDK's installation directory, and software such as Eclipse/netbeans/tomcat finds and uses the installed JDK by searching for java_home variables.   
 

Java setting environment variables and running Java programs under DOS

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.