JAVA sets environment variables and runs java programs under DOS, environment variables java
During the past few days of school training, the teacher took us to an in-depth review of java. This is the first day.
Many beginners are unfamiliar with "JAVA setting environment variables and running java programs in DOS", but understanding this is very important for later learning.
Http://blog.sina.com.cn/s/blog_639403840100i5rt.html
Next, let's take a look at what dos is.
Dos
DOS is the most frequently used computer. DOS stands for "Disk Operating System". As the name suggests, DOS is mainly a Disk-oriented System software, DOS is a set of commands that people give to machines. It is a set of commands stored in machine hardware. With DOS, we can better understand how to give commands to machines, you do not have to have a deep understanding of the hardware structure of the machine, nor do you have to memorize the boring 2-digit machine commands. You only need to use doscommands that are close to the English language, we can easily complete the vast majority of daily operations. In addition, DOS can effectively manage various hardware and software resources under its control and reasonably schedule them. All software and hardware are under DOS monitoring and management, in an orderly manner.
Common command editing (used in java running) 1 dir No parameter: view the files and folders in the current directory. 2. cdcd directory name: enter a specific directory. Cd \ returned to the root directory. Cd .. return to the upper-level directory. 3. md rdmd directory name: create a specific folder. (Dos is used to calling directories, while windows is used to calling folders .) Rd directory name: delete a specific folder. 4. deldel file name: delete an object. Del *. *: delete all files in the current folder. Del cannot delete folders. 5. Set to display, Set, or delete environment variables. If no parameter exists, the set command displays the current environment settings. 6 exit to exit the cmd.exe program or the current 7 Ipconfig shows all the current TCP/IP network configuration values, refresh the Dynamic Host Configuration Protocol (DHCP) and Domain Name System (DNS) settings. You can use ipconfig without parameters to display the IP addresses, subnet masks, and default gateways of all adapters. So how to run java in the dos environment first, you must learn to configure the java Runtime Environment to open the environment variable dialog box 1. first, right-click on my computer and select Properties. 2. click Advanced system settings. The System Properties dialog box is displayed. On the Advanced tab, you can see the environment variable button. 3. click the environment variable to bring up the dialog box. Generally, we set path or classpath. Assume that JDK is installed on D: \ java \ jdk1.5.0 _ 08 to start configuration: 1. create (if any) JAVA_HOME. The variable value is D: \ java \ jdk1.5.0 _ 082. the PATH variable value is % JAVA_HOME % \ bin; % JAVA_HOME % \ jre \ bin 3. the CLASSPATH variable value is .; % JAVA_HOME % \ lib \ dt. jar; % JAVA_HOME % \ lib \ tools. jar (to add. indicates the current path.) Next, test whether the configuration is successful: Enter "java-version", "java", and "javac" under dos. "Several commands, the screen appears, indicating that the environment variable is successfully configured. Next, compile the program" start "->;" run ", and type" cmd ". Compile the program first. start your first java program under the java file. javac file name. java -- to generate. class file (javac is used to compile java code) java file name (this step should not be suffixed) (java is used to run java programs), but in some special circumstances, we may use temporary environment variable configuration. For example, when we borrow someone else's computer, but cannot change someone else's computer settings, what do you do? I think the best way is to configure a mobile USB flash drive with temporary environment variables.
For temporary environment variable configuration, run the doscommand and enter set in the cmd command line. You will see all the environment variables on your computer, by entering set path, all the variables in path can be displayed. To set a temporary path environment variable, you only need to enter:
Set path = F:/Demo/java. It does not affect the configuration in the computer system. Also input:
Set path = F:/Demo/java; % path %
This indicates that adding a path to the original settings does not affect the configuration in the computer system.
Summary:
Set is used to view all environment variables of the local machine;
Set variable name: view a specific environment variable;
Set variable name =: clears an environment variable;
Set variable name = specific value: Specify the variable definition;
Set variable name = specific value; % path %: Add a new value based on the original environment variable.
Note: This configuration method is only valid in the current dos window. When the window is closed, the configuration disappears.
Likewise, the temporary configurations of the classpath environment variables are the same.
Note: PathPath allows the system to recognize java commands in any Path, and set it to % JAVA_HOME % \ bin; % JAVA_HOME % \ jre \ bin CLASSPATH to the Path of the java loading class (class or lib, only the class in classpath can be identified by java commands :.; % JAVA_HOME % \ lib \ dt. jar; % JAVA_HOME % \ lib \ tools. jar (to add. indicates the current path) % JAVA_HOME % refers to reference the previously specified JAVA_HOME;
JavacJavac is a java programming compiler. The javac tool reads the definitions of classes and interfaces written in java and compiles them into class files of byte code. Javac can implicitly compile some source files not mentioned in the command line.
Differences between jdk and jre
Http://blog.csdn.net/forwayfarer/article/details/3321410 (favorite blog, learn from it)
Http://www.cnblogs.com/myitm/archive/2011/05/03/2035942.html (favorite blog, learn from it)
JRE (Java Runtime Enviroment) is the Java Runtime Environment. It is intended for Java program users rather than developers. If you only download and install JRE, your system can only run Java programs. JRE is a set of environments required to run Java programs, including JVM standard implementation and Java core class libraries. It includes Java virtual machine, Java platform core class, and support files. It does not contain development tools (compilers, debuggers, and so on ).
JDK (Java Development Kit), also known as J2SDK (Java2 Software Development Kit), is a Java Development Kit that provides a Java Development Environment (provides compilers such as javac, it is used to compile a java file into a class file) and a Runtime environment (JVM and Runtime auxiliary packages are provided to parse the class file for running ). If you download and install JDK, you can not only develop Java programs, but also have a platform to run Java programs. JDK is the core of the entire Java, including the Java Runtime Environment (JRE), a bunch of Java tools. jar and Java standard class library (rt. jar ).
Total: JRE mainly includes: class files of the java class library (all packaged into jar files under the lib directory) and virtual machines (jvm. dll); JDK mainly contains: class files of the java class library (all packaged as jar in the lib directory) and a JRE is provided.
Briefly describe the functions of JAVA_HOME, path and classpath Environment Variables
Http://blog.sina.com.cn/s/blog_896994ae0101266a.html (favorite blog, learn from it)
1. PATH environment variable. The function is to specify the command search path. Execute the command below the I command line, for example, when javac compiles a java program, it will go to the PATH specified by the PATH variable to check whether the corresponding command program can be found. We need to add the bin directory under the jdk installation directory to the existing PATH variable. The bin directory contains frequently used executable files such as javac/java/javadoc waiting, after setting the PATH variable, You can execute tools such as javac and java in any directory.
2. CLASSPATH environment variable. The function is to specify the Class search path and use the classes that have already been compiled. The premise is that you can find them, and JVM searches for classes through CLASSPTH. We need to set dt. jar and tools. jar in the lib subdirectory under the jdk installation directory to CLASSPATH. Of course, the current directory "." must also be added to this variable.
The new version of the software, classpath seems to be useless, because JDK has been selected during installation and can be added
3. JAVA_HOME environment variable. It points to the jdk installation directory. Eclipse, NetBeans, Tomcat, and other software find and use the installed jdk by searching the JAVA_HOME variable.