Introduction to JDK environment variables and Java simple syntax

Source: Internet
Author: User

Dos Interface Input Path parameter:

If the JDK environment variable is not configured, the usual way to compile is to copy and paste the path of the Javac.exe program into CMD, and then add the path to the Java file to compile it:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/9D/35/wKioL1l7P2CSU5BvAAF-Bdk_UCo462.png-wh_500x0-wm_ 3-wmp_4-s_2131216545.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth sections -12.1850.png "alt=" WKIOL1L7P2CSU5BVAAF-BDK _uco462.png-wh_50 "/>

meaning: Locate the Javac.exe program, and then tell the path (parameter) that you want to compile note: a space is struck between the two.


PATH Configuration and function:

Because the above approach is too cumbersome, we need to configure the environment variable so that CMD can execute the javac command directly:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/9D/35/wKioL1l7P2jybIbaAAvW3KMkyPQ537.png-wh_500x0-wm_ 3-wmp_4-s_3327398801.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.18116.png "alt=" Wkiol1l7p2jybibaaavw3kmkypq537.png-wh_50 "/>

Note: After the configuration is complete , the DOS interface needs to be restarted before the new configured path information can be loaded , and a semicolon of the English symbol type will be used at the end.


In addition, if you configure the Java_home Environment variables can be directly copied the following two sentences paste up on it, note that the two sentences to separate:

%java_home%\jre\bin

%java_home%\bin

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/9D/35/wKiom1l7P2qC-4mYAAXQfsk7ovI597.png-wh_500x0-wm_ 3-wmp_4-s_2140829115.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.18266.png "alt=" Wkiom1l7p2qc-4myaaxqfsk7ovi597.png-wh_50 "/>


Restart the DOS interface to write shortcut commands:

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/9D/35/wKioL1l7P4bTxfHeAACvbSMzxDk223.png-wh_500x0-wm_ 3-wmp_4-s_1273958106.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.18288.png "alt=" Wkiol1l7p4btxfheaacvbsmzxdk223.png-wh_50 "/>


in the figure“Javac"is the use ofPathconfigured in theJDKToolboxbindirectory path to searchJavacGeneral case, ifdosdisplay in the interfaceJavacorJavais not an internal or external command, it isPathenvironment variable not configuredJDKof thebindirectory, or configured without a restartdosinterface. There is also the usual case where the environment variable does not need to be case sensitive.

In fact, the path path in the environment variable is equivalent to a shortcut path, the role of configuring the bin directory of the JDK is to quickly find to compile and run the program, This simplifies compiling and running commands.



CLASSPATH Configuration and function:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/9D/35/wKiom1l7P43AYNGmAArYHFnzWiU401.png-wh_500x0-wm_ 3-wmp_4-s_2174168230.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.18532.png "alt=" Wkiom1l7p43ayngmaaryhfnzwiu401.png-wh_50 "/>


It is important to note that in the figure . ( point ) is used to search for a local path, because in front of it, search the local path before searching C:/java Test If you do not add this point, you can only search for the path specified in the configuration, which is the path you class the path where the file is stored, and if the JAVA_HOME environment variable is configured, you can directly copy the following path using:

.; %java_home%\lib;%java_home%\lib\tools.jar

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/9D/35/wKioL1l7P5DRn0TKAAVa4ymJiUs879.png-wh_500x0-wm_ 3-wmp_4-s_750129182.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.18694.png "alt=" Wkiol1l7p5drn0tkaava4ymjius879.png-wh_50 "/>

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/9D/35/wKiom1l7P5GCVSapAAGge6tcqYc018.png-wh_500x0-wm_ 3-wmp_4-s_954922273.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.18697.png "alt=" Wkiom1l7p5gcvsapaagge6tcqyc018.png-wh_50 "/>

The "Java" in the diagram is also the path path to find the java.exe program, if not configured or not found will be an error When found, the Java virtual machine is started and the virtual machine is ready to load the HelloWorld class, then find helloworld.class This bytecode file, the lookup will first access the CLASSPATH environment variables have no configuration, if not configured will be the current local path to search, configured to follow the configured path to search.


No search will result in an error:

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/9D/35/wKioL1l7P5GA1k09AADiCINEzII350.png-wh_500x0-wm_ 3-wmp_4-s_2515744377.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.18879.png "alt=" Wkiol1l7p5ga1k09aadicinezii350.png-wh_50 "/>


When the search is over, it will load and run and run the results according to the code:

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/9D/35/wKiom1l7P5LzfNNuAAFhu04Q5Kc050.png-wh_500x0-wm_ 3-wmp_4-s_1836271927.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.18892.png "alt=" Wkiom1l7p5lzfnnuaafhu04q5kc050.png-wh_50 "/>

Configuration The CLASSPATH path function is used to search for a compiled class file, and to find out whether some dependent classes exist during compilation.


CLASSPATH the role of the compile time:

If you need to find some dependent classes at compile time, you will find that the paths to these classes are configured in the CLASSPATH Environment variables, also will be in the current path search and configuration of the path under the search, no search to the error, the search will verify these classes.



configuration and function of Java_home:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M01/9D/35/wKiom1l7P5eQfSSrAAigSyKSqaI854.png-wh_500x0-wm_ 3-wmp_4-s_4057080681.png "style=" Float:none; "title=" vip14-end bowl blowing Water-3rd and fourth -12.181105.png "alt=" Wkiom1l7p5eqfssraaigsyksqai854.png-wh_50 "/>

Note: The bin directory is not the total directory where the bin is located

Configuration Java_home is mainly used for some software needs to use this environment variable

System Environment Variables some of the errors that may be caused after PATH:

Path=...jre1.6\bin;...jdk1.8\bin;

as above,the JRE in path configuration is in the lower version and runs in front of the JDK High version because the Java can only be up-compatible, is not backward-compatible; this happens when the jdk has just been installed and the environment variable is installed, download the Oracle or some java software products, because the software is generally stable and compatible or uses a lower version of the jdk.

System Environment Variables some of the errors that may be caused after classpath:

environment variables are configured  CLASSPATH, you must add .; as a local path lookup, otherwise the class file directory will be error compilation can not run.



Code writing specifications and daily considerations:

1. first write the code structure, put the parentheses and then fill the code, so as not to miss out the parentheses appear unnecessary error.

2. write code, each write two or three lines on the shortcut key to save, to form a good habit of frequent preservation, in order to avoid the power outage, program crashes, the system blue screen and other unexpected situations, resulting in code loss.

3. regular backup of files and project projects to avoid accidental or accidental deletion of the case.

4. The name of the file to be named with the representative of the content of this file, if often with the default new file / folder or use the same name, can easily lead to confusion, Because you can't find what you want from a bunch of files with similar names or near-consistent documents. Usually to keep the computer desktop neat, do not put important files or project files directly on the desktop, as far as possible only to put software, files / folders, documents shortcuts, because you accidentally deleted the shortcut also saved, if directly deleted files or project documents to play off, In particular, the project documents are mostly fragmented, even if the use of recovery software can not be fully restored, so need to develop a good use habits.

syntax rules for Java:

1.java is strictly case-sensitive, such as int a;inta; in java A and a are two different variable names. So when writing code, pay attention to capitalization, don't confuse.

   2. / half-width symbol ) c/c++

3. all the syntax symbols in Java are half-width symbols ( English symbols ), note that if you are using full-width notation ( Chinese symbol ) is an error.

4. The name is best used by everyone to understand the way to name, do not necessarily require the use of English is the most important is in the team development of the people can understand, English is poor can use pinyin, pinyin also spelled bad can use Pinyin first letter, are not able to use Chinese is also reluctantly.

some specifications for class names in Java:

1. in the code, with the public modifier in front of class, the name of the class must be the same as the file name, or the compilation will not pass. and a source code file in front of the class, can only write a modifier with public , and as long as the class is preceded by The public will be the same as the file name.

   2. Span style= "font-family: ' The song Body '; Color:rgb (0,0,0); font-weight:normal;font-size:20px;" > dos interface to compile with this source file name and public class consistent name, with the name of the other class inside the compiler does not pass, because the compiled class The file name is to be declared in the code with the public

3. when multiple classes are declared in a source file, the compiler generates a class file of different names depending on the class name . But note that, try not to declare more than one class in a source file, declare a good, or need to find a class when it is cumbersome and easy to confuse the code, so declaring multiple classes is undoubtedly to find trouble for themselves.

Java Annotations:

annotations serve only as a description, and are not executed as code during compilation:

1. single-line comment //: A single-line comment can only write one line of comment content.

2. Multiline Comment / * */: Multi-line comments can write multiple lines of comment content.

3. document Comment /**

*

*/:

document annotations can use the Javadoc program to generate HTML documents that are easy to share with the code at the time of team development. and Java has a lot of standard help documents to view.


This article is from the "12831981" blog, please be sure to keep this source http://12841981.blog.51cto.com/12831981/1951850

Introduction to JDK environment variables and Java simple syntax

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.