JAVA Basics Comb 1:java running environment, command line compilation execution, path and classpath role __java

Source: Internet
Author: User
Tags java se

1, Java Operating environment

Install Java is typically installed JDK, then what is JDK. What is JRE again.

(The following from the definition of Baidu)

The JDK (Java Development Kit), called Java Development Kit or Java development tool, is a program development environment for Java applet applets and applications.
The JDK is the core of the entire Java system, including the Java Runtime Environment (Java Runtime envirnment), some Java tools and Java core class libraries (Java APIs). No matter what Java application Server is in essence a version of the JDK is built in.
In addition, the Java SE API subset in the Java API Class library and the Java Virtual machine are collectively referred to as JRE (Java Runtime Environment), and the JRE is a standard environment that supports Java program operations.
The JRE is a running environment, and the JDK is a development environment. So the JDK is required to write Java programs, and the JRE is required to run Java programs. The JDK already contains the JRE, so as long as the JDK is installed, you can edit the Java program, or you can run the Java program normally. However, because the JDK contains a lot of content that is not relevant to the operation, it takes up a large amount of space, so running a normal Java program without installing the JDK requires installing the JRE.




2. Compile and execute Java programs at the command line (Windows)
To know how to compile the execution program at the command line, first we need to know the Java program's specific execution process. 
As shown in the figure above, a complete execution of a Java program is:
First, follow the Java syntax to write a source program with a. Java suffix
Secondly, the source program is compiled into a bytecode file through the Java compiler, that is, a file with a. class suffix
Then, the class loader, byte code calibrator, interpreter, and so on layer of running, into the operating system platform to understand the executable file. If the Windows operating system is turned into a file with the. exe suffix
Finally, the operating system platform is executed and the results are given.
The Cross-platform feature of Java is that when you convert a bytecode file into an operating system executable file in the third step, you can convert files that can be executed by different operating systems for different operating systems. The Java Virtual machine mechanism, one of the Java core mechanisms, is the role.      Java Virtual machine can be understood as a byte code for the machine instruction CPU, for different operating environment, there are different virtual machines. With a look at the execution of Java programs, we know how to compile and execute Java programs at the command line.       Compile first and then run. At the command line to jump to the program store path, compile: Input Javac *.java (* refers to the source program file name) to compile it into a bytecode file, after the execution of the command you will find that the program directory appears a corresponding. class file
Run: Not input Java *.class but input java * (* refers to the class name, which is the public class name in the program, is the same as the source file name of the program file.) Java syntax rules)


3, path and classpath function
  After installing the JDK, the general tutorials will let us configure path and classpath, but what they do. Why would you configure that?
Path
As I said before, compiling a Java program requires typing javac *.java at the command line

Enter Javac at the DOS command line on Windows:

is actually executing files under Windows--such as D:jdk\bin (compiled programs, where executable programs are stored) \javac.exe


So why does Windows know to go to this path to find Javac.exe this executable file?

When we enter the relevant command at the command line, Windows will generally go to the environment variables in the path of the directory to find out if there is a corresponding executable file, some words directly executed, no words will give relevant information.


Therefore, in order for the JAVAC command to take effect, we need to configure the environment variable path to add the Javac directory.

Locate the path in My Computer/attribute/Advanced/environment variable/system variable, open the Bin folder in the JDK, and locate the Javac.exe repository. Copy the address on the file bar, paste it into the directory behind the path, and separate the directory from the directory with a semicolon;


Classpath


System know where to find Javac, then configure classpath is to know where to find Java. No, you know where to find the Java command when you configure path. Javac.exe and Java.exe are stored together.


The reason for configuring Classpath is because multiple class files in a large project need to work together, one class to use another class, where to find another class. Where to find it.

The answer is to find it in the classpath.


So we add a classpath to my Computer/attribute/Advanced/environment variable/system variable. Also find the Lib (Class library) under the JDK, where there are a lot of class files, add the directory to the line. It is also used to separate.     (You can add;. , which is found in the current executable directory)


Some add home variables simply extract the first half of the path and Classpath d:jdk, followed by path and classpath need to be introduced


give a specific definition

 

path:windows the path to be searched when the system executes a command

 

Classpath:java The path of the class to be found at compile and run time



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.