Why configure environment variables?

I. Introduction

After working in Java for so many years, configuring environment variables is the first step, but why do you need to configure environment variables, and what is the use? Today, Nezha will take you to find out.

2. Baidu Encyclopedia

I have nothing to do with Baidu. Baidu is really good at explaining nouns.

1. Introduction to environment variables

Environment variables generally refer to some parameters used in the operating system to specify the operating environment of the operating system, such as the location of the temporary folder and the location of the system folder.

An environment variable is an object with a specific name in the operating system that contains information that will be used by one or more applications. For example, the path environment variable in Windows and DOS operating systems, when the system is required to run a program without telling it the full path where the program is located, the system should not only look for the program in the current directory, but also go to the path specified in path to find it. . Users can run processes better by setting environment variables.

2. The main role of environment variables

(1) Setting parameters

The role of the path environment variable is to tell the system that when the system is asked to run a program without telling it the full path where the program is located, the system should search in which directories besides the current directory for this program. And the path variable we usually configure is the full path of this directory.

In short, when running a command requires certain parameters, if it is not found in the current directory, it will automatically look for it in the environment variables.

(2) Software sharing

Many friends will install dual systems on their computers, such as installing Windows XP on the C drive and Windows 7 on the D drive. However, some software is often only installed in Windows XP system, and cannot be used normally in Windows 7 system. The more troublesome but effective method is to install it again. When we understand the purpose of environment variables, we can solve the problem of software sharing between dual systems.

(3) System operation

Why can't the software installed in Windows XP run under Windows 7 (except green software)? The reason is that when installing software, it is often necessary to copy some files to the system directory, and when using another system, it will be due to the lack of these files. Can not run. Therefore, we can solve this problem by setting environment variables.

3. Java environment variables

1. The composition of Java jdk (Java Development kit)

JDK is a software development kit for the Java language, mainly used for Java applications on mobile devices and embedded devices. JDK is the core of the entire java development, it includes the JAVA runtime environment (JVM+Java system class library) and JAVA tools.

The Java runtime environment (JRE) consists of a Java virtual machine (Java virtual machine, JVM) and some standard function libraries.

So here, we know the relationship between JDK, JRE, and JVM.

Next, let's look at the directory of the installed jdk.

The bin directory here is the executable file of Java, including the java, javac, and javadoc development instructions that we often use. The instruction programs used in the compilation and execution of our program are all in this directory.

2. Run javac

Because the environment variable is configured, if the cmd is not found in the current path, it will go to the environment variable path to find it. If it is running, if not, an error will be reported.

Configured Java environment variables:

3. If the environment variable is not configured, can the javac command run in the bin directory? Can it run in any other path?

Try it, it's simple, change the path of java_home

Can the javac command run in the bin directory?

Can it run in any other path?

4. So why can't the path of jdk be configured directly in path, but configure a JAVA_HOME separately?

Because this is a conventional thing in the Java development process, because when Java was first used, it was necessary to build and use a tomcat server, and it is also required now, but springboot integrates tomcat, and does not need to be started separately.

The variable set in tomcat is JAVA_HOME, which is used to access jdk. Because the path to install jdk is different for everyone, if you want to call it, you can only configure it in advance by assigning variables. The convention is greater than the configuration. , I believe that through this sentence, it should be the truth.

Everyone [ like , favorite, follow, comment ], if you are interested, you can find me and send it to you.

Pay attention to the [Nezha Learn Java] public account, three Java technology sharing articles every week, full of dry goods!

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324106293&siteId=291194637