Java does not detour tutorial (1. Environment construction)

Source: Internet
Author: User
Tags echo command

1. Environment construction
Before we start writing the first Java program, we need to do some simple preparatory work.

1.1 Remember DOS?
We can operate our computer through a graphical interface. But as a programmer, you first need to learn to use the command line to operate the computer, because not all computers provide a graphical interface.
DOS can be used to execute commands in a Windows environment.
You only need to remember about 5 commands, you can complete the basic operation of the computer.

We start the DOS environment first: enter CMD in the file browser's address bar, and return as shown.



The current directory is displayed to the left of the cursor.
This tutorial example is in the C-drive operation, so if it is not C-drive, input C: Enter, switch to the C drive.

Next we will learn 5 commands:
Directory creation
Directory switching
View the list of files/folders in the current directory
Open the specified file
Help

Note: Directories and folders are a concept that will no longer be described later

1. Catalog Creation
Command: MD directory name
(abbreviated for Make directory)
Note: The commands are separated by a space and will no longer be described later.
The directory structure we will create is as follows:
C:
-work
-001
-002
Enter the following command in the DOS window to create the above directory
MD c:\work
MD c:\work\001
MD c:\work\002

2. Directory switching
Command: CD directory name
(Abbreviation for Change directory)
We enter the following command into the directory you just created
CD C:\work
You can see that the current directory has become c:\work

3. View the list of files/folders in the current directory
Command: Dir
(Abbreviation for directory)
Enter Dir to display the following

There are four folders, respectively.,.., 001,002
Where 001,002 is the folder we just created
. For the current directory
.. To the top level directory

We enter the CD.
Can be seen or in the current directory,
Enter CD:
You can see the go to the top level directory
Input CD work\001
You can see that you've turned to c:\work\001.
Enter CD: \.. \
You can see it go to the upper parent directory.

4. Open the specified file
Command: More
We create the file a.txt under window, the content is ABC, put in the C:\work directory.

DOS Environment Enter the work directory input after entering the following command
More A.txt

You can see the contents of the file displayed

5.help
Enter help to display all supported commands in the DOS environment.

If you do not know how to use the command, enter the command name/? This displays how the command is used.
such as Dir/?

Start a program
Under Window We double-click A.txt to start Notepad to display the contents of the file.
We can also do this in DOS:
Input notepad.exe A.txt
For simplicity, we usually omit the. exe
Notepad a.txt

So we started Notepad under DOS to open the A.txt file.
Where Notepad is the program name, A.txt is the parameter passed to the program, and if no arguments are passed, the program is opened by default
Notepad

Why
Now we have basically mastered the DOS operation.
Think about it, why do I enter Notepad, DOS can start Notepad program?
Yes, DOS needs to know the location of the Notepad.exe and then start it.

Let's see if DOS knows where the Notepad program is, enter where Notepad returns, as

OK, that is dos know Notepad Notepad program is located under the following path:
C:\Windows\System32\notepad.exe

So where does this program sit and where is the path set?

In a DOS environment, there is a variable named path, which stores the path information of the program.
We enter the following command to see the value of the variable path: (The echo command outputs the contents of the specified variable, where the variable name is enclosed in%)
Echo%PATH%

You can see C:\Windows\system32 in them.
In other words, when DOS starts a program, look for the corresponding file under the variable path, then execute the file if found, because it is related to the startup environment, so we can call this environment variable.

So, how do you add or modify the value of the environment variable path?
In Windows, you can right-click My Computer-〉 System Properties-〉 advanced system settings, environment variables, click New or double-click an existing environment variable to modify or add a new environment variable.
Environment variables are separated by semicolons.

Here, we have mastered the Java program to write the necessary DOS Foundation, please remember the heart.

1.2 Java Environment Setup

In the previous section we learned how to start a specified program in a DOS environment, and in this section we will start the Java program in a DOS environment.

First, as with other windos programs, we will install Java programs, download Java programs on Oracle's official website to local, double-click to complete the installation like other programs, and note the path to the program installation.
I installed it under the C:\Program files\java\jdk1.8.0_161.

Verify that the installation is successful:
Enter the following command under DOS (please replace yourself with your own installation directory, later)
C:\Program files\java\jdk1.8.0_161\bin\java-version
C:\Program files\java\jdk1.8.0_161\bin\javac-version

If the version number is displayed correctly, the installation is successful.
The above Java,javac command exists in the bin directory of the installation directory, where Javac is the compiler Java program Command and Java is running Java program commands.
But if every run to enter the full path, it is inconvenient, we can run up in the section of the Notepad program, in any directory, directly enter Java or Javac can.
Yes, we need to add the installation path to the environment variable path.

The new version of the JDK will automatically configure the path variable above, and if you are using an older version of the JDK, you will need to configure the CLASSPATH environment variable while configuring the path.
During the Java compilation process, an environment variable named Classpath is found to complete the compilation of Java, which should contain the class files required for Java compilation.
So we also need to add the following environment variables:
Variable name: CLASSPATH
Variable value:.; C:\Program Files\java\jdk1.8.0_161\lib\tools.jar
Where. Represents the class file under the current directory in which the program executes, Tools.jar represents the system class file that loads Java.

Restart the DOS environment, enter java-version and javac-version correct display version number, then complete the Java environment Setup.

Note: Although the above configuration is not required for the new version, it is recommended that the reader do it yourself as described above, and do not omit this step, which is the first step in starting the Java program.
Because in the real world you will encounter various versions of the JDK, a lot of boot loading problems are caused by the incorrect environment variables.

Copyright Notice: This tutorial copyright belongs to JAVA123.VIP All, prohibit any kind of reprint and reference.

Java does not detour tutorial (1. Environment construction)

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.