1. Java Development Environment 1.1. Understanding the Linux operating system 1.1.1. The origin and development of Linux
Linux originated in 1991, 1995 popular, you can see next to this person, it is called Linux, he was in college when writing an operating system, was open source, so-called open source, that is, the opening of the code, that is, step by step how to do, can see. Say it is a Unix-like operating system, UNIX is an operating system, but it is charged, and Linux is free, of course, this is one of the reasons for its development.
At present, Linux is the mainstream server operating system, widely used in the Internet, cloud computing, smart phones (Android) and other fields. Because Java is primarily used for server-side development, there are many Linux-deployed environments for Java applications.
1.1.2. Linux directory structure
The directory structure of the Windows operating system is in drive letter units, C, D, E, and so on, the data is stored under the various drive characters, and the Linux operating system on the top level only a root directory root, all files are stored under this root directory.
If the Windows operating system inserts an external device (USB stick, etc.), the system is more than a drive letter H, the operation of the H-drive is the operation of the external device. The Linux operating system is a subdirectory named MNT under the root directory, in this directory, a directory will appear, assuming that sdcard, known as the Mount point, the operation of it is the operation of external devices.
Windows operating system after a user login to the system, all files have Add and remove permissions to change, that is: You can operate any directory, assuming that the C disk under the Windows directory deletion, it will cause system anomalies, security is poor. Linux operating system to strict permissions requirements, the user login is not to all directories have additions and deletions permissions, the default current directory is the root directory under the home directory soft01, called the home directory, the directory has the highest permissions, the remaining directory files are generally read-only, can not be arbitrarily deleted, This guarantees security.
1.1.3. PWD, CD, ls command
Most Linux operating systems used for servers do not provide a graphical interface, but rather operate through the command line, which differs from Windows. Linux provides a number of commands, the commands that are frequently used to manipulate directories are as follows:
- PWD: Used to display the current working directory.
- LS: Used to view the current working directory contents.
- CD: Used to change the current working directory.
1.1.4. Relative and absolute paths
The purpose of a path is to indicate the location of a file or directory within the file system, in two ways: relative and absolute. In general, which way to locate faster, we choose which path.
Relative path: The location of the file or directory relative to the current working directory. For example: The path "Soft01/workspace" represents the workspace under the soft01 directory in the current directory, with two more specific relative paths: "." Represents the current directory, "..." Represents the previous level of the directory.
Absolute path: The location of the file or directory relative to the root directory, with the absolute path starting with "/". For example: "/home/soft01", which represents the soft01 under the home directory under the root directory.
Another example of life, how to go to Carrefour? Take the current position as a base point, out of the classroom door, down the elevator to the 1 floor, out of the door to the right to go for about 300 meters, on the right side, this is the relative path. Fixed to lonzeal as the base point, Lonzeal take the subway, Big Bell Temple Station, go out straight for about 1000 meters, left is to, this is the absolute path.
1.2. Java Development environment 1.2.1. Java compilation Run process
The programmer writes a file with a. java suffix, which the operating system does not recognize correctly, so it is first compiled to generate so-called bytecode files (. Class), and bytecode files require the JVM to provide support for the running environment.
The JVM is a software that is installed in the operating system and is built on top of the operating system, providing a runtime environment for bytecode files, as shown in the effect – 1.
Figure-1
Java is officially provided with JVM software for different platforms, namely: The JVM is different on different platforms. But these JVMs follow the same standard, that is, they can run on different JVMs as long as they are standard. class files, and they run the same effect. This enables the so-called "one-time programming to be used everywhere". Effect – shown in 2:
Figure-2
Java programs Follow the principles of compiling first and then executing them. First, the Java source program (. java file) is compiled into a Java bytecode (. class file) through the Javac command, and then the JVM is started by the Java command, which loads the. class file and runs the. class file. Effect – shown in 3:
Figure-3
1.2.2. JDK, JRE, JVM relationships
The JDK (Java Development Kit) is the Java Development Kit, which contains the compilation, runtime, and other development tools necessary to write Java programs, as well as the JRE. Development tools such as the Javac command for compiling Java programs, the Java command to start the JVM running Java programs, the Javadoc command for generating documents, and the jar commands for packaging, etc.
The JRE (Java Runtime Environment) is a Java runtime environment that provides the software environment necessary to run Java applications, including Java virtual machines (JVMS) and a rich system class library. The System class library is the Java pre-packaged functional class, just use it directly, can greatly improve the development efficiency.
The JVM (Java virtual machines) is the Java VM that provides the runtime environment support for the bytecode file (. Class).
The JDK, JRE, and JVM relationship –4 are as follows:
Figure-4
As can be seen from the diagram, the JDK contains the compilation, running and other development tools and JRE, and the JRE contains the Java System Class library and the JVM, the minimum environment required to run a Java program is the JRE, and the minimum environment required to develop a Java program is the JDK, Because the JDK also contains a lot of commands to use.
1.2.3. Installing the JDK
You can download and install jdk:http://www.oracle.com/technetwork/java/javase/downloads/from the official address index.html, but when downloading the installation, you need to be aware of the correspondence between the operating system (OS) version and the JDK version, as shown in the following:
Figure-5
1.2.4. Configuring Environment variables
The JDK provides a lot of commands, like compile (Javac), run (Java), and so on, if you want to use these commands, you need to let the operating system can find the path of these command files, can be implemented by configuring the PATH environment variable.
The PATH environment variable is a series of directories where the operating system looks for the command in each of the directories in the PATH environment variable, in turn, and the error is not found when it is executed.
In a Linux system, the path to the configuration file is: The/etc/profile,profile file is the system initialization script, the script that executes automatically when the system boots, you can use the Cat command to view the contents of the configuration file, the command is as follows:
Cat/etc/profile
You can see that there is already a lot of configuration, set up in advance, no need to modify. The simplest way to configure the Linux operating system itself is as follows:
Export Java_home=/opt/jdkexport classpath=.export path=/opt/jdk/bin: $PATH
1.3. Eclipse IDE1.3.1. About Eclipse
Before learning the console version of the "Java HelloWorld" program, we use the simplest editing tools to write the source code, but in the real enterprise project, this primitive development method will bring a lot of tedious, repetitive, error-prone operation, greatly reduce the work efficiency, also is not conducive to the overall management of the project, In real-world scenarios, developers are always using powerful "integrated development environments" for code authoring, debugging, testing, committing, refactoring, and so on, such as Eclipse.
Eclipse is the current mainstream IDE development environment, and the so-called Integrated development Environment (ide,integrated development environment) is an application software designed for programmers that often have a powerful graphical interface. With the help of the IDE, programmers can compile, debug, Commit, refactor, and more efficiently. As a qualified programmer, you should have a high degree of proficiency in the mainstream IDE, but also to prevent "over-reliance on the IDE" issue.
There are a number of IDE environments for Java programmers to choose from, but the most mainstream is the famous eclipse. Eclipse is IBM's $ tens of millions of open source project that now almost dominates the IDE market. Beyond Open source, the biggest reason for Eclipse's success is that it is based on the "plug-in" feature. Eclipse itself is a platform framework that provides standard services, and many third-party vendors can extend eclipse's functionality by developing plug-ins, with a high degree of flexibility compared to other ide,eclipse with relatively fixed functionality.
Free eclipse can be downloaded from the Eclipse's official website (http://www.eclipse.org/downloads/). In the Eclipse download page, select "Eclipse Classic", which can be understood as no special install plug-in "Standard Edition" Eclipse, the other version, according to different needs to preset a specific plug-in.
After the eclipse download is complete, no special installation is required, just unzip the downloaded package in a folder. Since eclipse itself is written in the Java language, it needs to have a JRE environment, so the JDK (or JRE) must be installed first.
Below, let's briefly describe the steps to use for eclipse:
1) Step one: Open development tools Eclipse
The following dialog box pops up after Eclipse starts, as shown in 27.
Figure-27
The popup Dialog "Workspace Launcher" is used to select the "Workspace" (Workspace). The so-called "workspace" refers to the path that Eclipse uses to store the project files. Eclipse organizes the material through project. The source files, compiled generated class files, etc. written by the programmer are stored in the project folder in a specific directory structure.
2) Step Two: Create a Java project
Select Menu Action File (NEW Java project is used to create a project that is suitable for writing Java basic applications. In the dialog box that pops up, fill in the Project name (project name) and click the "Finish" button. -28 Shows:
Figure-28
When the project is created, it generates a folder with the same name as the project names in the workspace directory (specified at eclipse startup). Open this folder and you will see the directory structure shown in-29:
Figure-29
Where: the "src" folder is used to store user-written Java source files; the "bin" folder is used to store the class files generated by eclipse Auto-compiling. Eclipse has the ability to compile automatically, and when the user writes a Java source file, Eclipse automatically compiles the file to the system's JRE and stores the compiled class file in the Bin directory. In addition, the ". Classpath" and ". Project" two files, as well as the contents of the ". Settings" folder, are used by eclipse to maintain engineering information and can generally be ignored.
3) Step three: Create a class named HelloWorld
After the project has been created, you can create a Java source file from the menu operation "File" (New Class). In the popup dialog box, fill in the class name (name) and package name of the Java class you want to create, as shown in 30. (The meaning of the package will be detailed in the follow-up course.) )
Figure-30
After completing the class name ("HelloWorld" in this example) and the package name ("Day01" in this example), click the "Finish" button. Eclipse creates a source file named Helloworld.java.
4) Step four: Define the class
Write the HelloWorld program in Eclipse, as shown in 31.
Figure-31
After the program is written, verify that there is no compile error, you can run the program using the menu action "Run as (Java application"). The results of the run are displayed in the console view below the code. It should be noted here that this operation is essentially not different from the previous run of the Java program through the command line, it can be understood that eclipse calls the JDK Java command, with a more user-friendly graphical interface to implement the operation of the Java program.
Day 1: Industry overview, course system Introduction, Java Development environment