Java learning without detours tutorial (7.Eclipse environment construction)

7. Eclipse environment construction

In the previous chapters, we were familiar with compiling and running Java programs in the DOS environment. For large-scale programming, development tools are essential.
The most commonly used Java development tool is Eclipse. In the next tutorial, we will write, compile and run programs based on Eclipse development tools.

This chapter will introduce the installation and basic operation of Eclipse.
1. Eclipse installation and startup
is the same as installing ordinary Windows programs. It can be downloaded from the official website and installed. I will not introduce it in detail here.
I installed Eclipse OXYGEN
. After the installation is complete, there are files in the installation directory: eclipse.exe and eclipse.ini
. The startup parameters are configured in eclipse.ini, including the occupied memory size and so on.
Double-click eclipse.exe to start eclipse

When you start Eclipse, the workspace selection interface will appear, just enter your own workspace directory, such as (c:\workspace).
If there are multiple workspaces, you can switch between workspaces by selecting file/swich workspace after the startup is complete.

 

After Eclipse starts successfully, the welcome interface appears, just close it.

2. Compilation/Running Environment
In order to compile and run Java programs normally, we need to specify the path of JDK in eclipse.

Select Window->Preferences from the menu to pop up the properties interface.

In the properties interface, select Java->Installed JREs, the right window displays the JDK selection interface.
Click Add.

Select Standard VM, click Next, and the Add JDK interface will pop up.

Click Directory, select the path of the JDK, as shown in the following figure:

 

Click Finish, check the added JDK, and click Apply and Close to complete the JDK setting.

3. New Java project
After the JDK is set up, let's run a simple Java program.
First, create a new Java project.

Select file->New->Java Project from the menu bar

In the pop-up window, enter the project name, the workspace is default, and click Finish to complete the new Java project.

 

Then, we create a new package.
Right click on src New->Package

In the pop-up window, enter the package name and click Finish.

Under the newly created package, create a new Java file.
Right click on the new package name New->Class

In the pop-up window, enter the class name and check public static void main, as shown in the following figure:

This way we create a Java file that contains the main method entry.
We enter a line of code as shown below:

The program will output the two parameter values ​​passed in.

4. Run
the Java program by right-clicking and selecting Run As->Run Configurations.
Note: If you do not need to read in any parameters, select Run As->Java Application.

On the pop-up window, select Java Application and click the New icon in the upper left corner.

The system automatically creates a run setting with the class name.
Select the class name, select the Arguments tab on the right tab interface, and enter the operation parameter setting interface.

In the Arguments tab, enter the parameter values ​​to be set, separated by spaces, then click Run to run the program.

Output the results of running the program in the Console tab.

 

5. Project configuration
Let's take a look at the actual location of the newly created Java file and the compiled class file:
in the root directory of the project, there are src and bin directories, where the src directory stores source files, and the bin directory stores cheap files. .

The source files of the src directory are as follows:

The compiled files in the bin directory are as follows:

 

The above location information can be specified in the following interface:
right-click the project name and select Properties.

In the pop-up interface, select Java Build Path, and
the Source tab on the right displays the directory where the source file is located and the directory where the compiled file is located.

Project tab Other projects referenced by this project.

The Libraries tab can set the class files required for project compilation.

The order of compilation of the project can be set in the Order and Export tab


6. Automatic compilation and manual compilation
After Eclipse is installed, the default is automatic compilation, that is, when the source file is saved, it is automatically compiled into a class file.
This setting can be modified in Project->Build Automatically, as shown in the
figure below.
Note: Clean is empty . The file generated after compilation.

If you do not check Build Automatically, you need to manually start the compilation process,
right-click the project name, and select Build Project to start compiling the project.

 

Copyright statement: The copyright of this tutorial belongs to java123.vip, and any form of reprinting and citation is prohibited.

The original post was published in: http://www.cnblogs.com/java123vip/p/8999150.html

 

Guess you like

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