Analysis of Java environment Configuration

Source: Internet
Author: User


 

For beginnersJavaFor example, it must be a matter of hand writing.JavaProgramLet's take a look. This is also in line with the programmer's psychology. It is better to write a program on your own to see a high sense of accomplishment.

Well, we started to write the program. There seems to be something you haven't done before writing. By the way, it's necessary software, for example, before we writeC ++The program uses a lotVc6.0And so on. It doesn't matter what we use to edit a program. If you want to use Notepad, I have no objection. It mainly involves the tools required for program compilation and execution. InJava, As mentioned earlier, to divide the source program into two parts, you must first compile the source program into bytecode.JavaThe Virtual Machine interprets the execution bytecode. So the most important thing is to haveJavaCompiler and interpreter.JDK.JDKWe can download it from the official website.

Many books, except for the first chapterJavaIn addition to the Development and features of languagesJavaEnvironment configuration, and then teach you step by step to configure the environment, the general person can follow this step is easy to configure. However, we do not quite understand why we need to configure the environment, and maybe we have installedVc6.0Or largerVSSuch software does not need to be configured. Now I will focus on why I want to do this.

First, go to the official website to downloadJDK,JavaThe version has been upgraded quickly.1.7BeforeJavaAlso belongsSunIn the company,JDKIt has been free since last year.OracleAcquiredSunAfter that, I began to make some strategic adjustments. For example, I closed some open-source things and started to charge fees. All.1.7There are also paid versions. Of course, we usually use desktop application development1.6Is enough. After the download, the installation starts:

 


 

You can check the upper-right corner.SunOfLogoUnfortunately....Well, I am reluctant for myself.SunQuiltOracleSome of the open-source things we know before are acquired.SunWith the efforts made on open-source software, how can a technology-focused company have some problems in management, and ultimately cannot escape the fate of being acquired.

Next, selectJDKThe default installation path is"C:/program files/Java/", We will follow the default installation. After the installation is successful, you will be prompted to installJRE(Javaruntimeenvironment),JREIt can run, test, and transmit applications on it.JavaPlatform. It includesJavaVirtual Machine,JavaThe platform's core classes and support files. Therefore, this must also be installed. Otherwise, there is no necessary Library Function Support.JavaProgram, and noJVMTo execute the bytecode.

After the installation is completeC:/program files/Java/There will be two folders, one of which isJDK, One isJRE, Such. Next we will start writingJavaProgram.

 

 

Now we can use NotePad to write the simplestJavaProgram:

Public class hellojava {<br/> Public static void main (string [] ARGs) {<br/> system. Out. println ("Hello Java !"); <Br/>}< br/>

OK!Save as file nameHellojava. Java, Put inCUnder the root directory.

OpenDoSCommand Line, switchCUnder the root directory of the disk, useJavacTo compile our source program, but an error is prompted:

 

YesJavacIt is not an internal or external command, but we have installedJDK, In the folderJdk1.6.0 _ 22/binBelow isJavac.exeWhy can't I find this program?

The reason is that we installedJDKDoes not modify the registry of the system, so run it directly under the command lineJavac,JavaThe system does not know where to find these executable programs. To makeJavac,JavaPrograms can be found and run under any directory in the system, andJavaThe interpreter knows where to find the class to be referenced, and the developer needs to set the system environment variable.

The setting is simple. Right-click my computer"->"Attribute"->"Advanced"->"Environment variable": Modify the two values in "system variables:

1. AddPath:SetJDKCan be added to the executable file directory, my default installation location, that is,"C:/program files/Java/jdk1.6.0 _ 22/bin;", Followed by";",

 

2. AddClasspath:SetJREThe default installation location, that is,".; C:/program files/Java/jre6/LIB;", Note that you must add"."This indicates that the library file is first searched in the current directory of the project, and some class libraries written by the user will be loaded in,

 

Done. If you compile it again, there will be no problem. During execution, you should note that it is used"Java hellojava"Do not add a suffix to this command.. Class, Execute the programJavaWhat follows isMainThe name of the class where the function is located, not the file name of the bytecode! Pay special attention to it!


Okay, it took a lot of nonsense.JavaThe environment configuration mainly focuses on the reason for such configuration, but there are not too many configuration details. I believe that after you understand the principle, it will be easy to configure successfully. In the future, many software will be configured in the same way.PHP + MySqlMany configurations are also required to create webpages.

Now you can writeHellojavaCommand Line program!

 

 

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.