Many people cannot perform Java programming well because they do not understand the Java Runtime Environment or understand it thoroughly. If a common Java program running environment is not set up. Let alone understand how to build the J2EE runtime environment. Therefore, this article first introduces how to build the runtime environment of common Java programs, and then introduces how to build a J2EE Runtime Environment on this basis.
1. What is JDK?
Everyone studying Java should know that Sun's Java technology platform has three well-known versions based on different application environments. They are j2se (used for development of common desktop applications ), j2EE (for enterprise-level application development) and J2EE (for development of mobile devices and other consumer electronic products ), sun provides the corresponding development kits (SDK: software development kit) for these three versions. I will not list them here. By the way, the latest SDK versions of j2se and J2EE are:
● J2se 5.0 JDK
● J2EE 1.4 SDK
It is worth mentioning that the JDK toolkit we usually refer to is the j2se SDK. This toolkit is the most commonly used by learners. Note that sun provides different JDK files for different operating systems, and these files are divided into offline and online versions, therefore, you must select the correct file during the download process.
So what exactly is there in the JDK toolkit? In fact, this includes Java program development tools (javac commands, etc.), runtime environments (Java commands, etc.) and core class packages. You can imagine that you want to run a Java program. You must install the JDK toolkit.
Ii. How to install JDK?
When we down j2se 5.0 JDK from the Network (it is an executable file named jdk-rj5_0-windows-i586.exe), the name will be different because of the different operating systems. The operating system I use is windows, have you found out ?), Double-click it to start installation. Note that the installation path is selected. We usually install it in the C root directory (which is also the default path of the installer ), the other job is to press Next one by one.
3. Build a running and development environment
Is it possible to compile and run the code after installing JDK? Don't be busy. Check with me:
1. Click the 'start' menu in the lower-left corner of the operating system desktop, select 'run', And Enter cmd in the open dialog box. Now, the Command Prompt window is displayed, we love the DOS interface.
2. Now you should see the prompt in the window. It usually looks like this: C: \ Documents ents and Settings \ Administrator>
3. Let's run the following command at the end of the prompt: Java. Is there a prompt like this?
Usage: Java [-options] class [ARGs...]
(To execute a class)
Or Java [-options]-jar jarfile [ARGs...]
(To execute a jar file)
......
This is the help information of the Java command. If so, the success is half done.
4. Next, try again: at the command prompt, tap javac. Is the help prompt for the javac command also displayed? I don't think so. As you may see, 'javac' is not an internal or external command, or a runable program or batch file.
Why is this happening?
This is because when the operating system executes a command, it first goes to the current directory to find the command file. If it cannot be found in the current directory, it will search for it in multiple paths indicated by the system variable path until it is found. If neither of the two locations is found, the above errors will be reported.
We certainly cannot find the javac command in the path c: \ Documents ents and Settings \ administrator. Isn't our JDK installed in the C root directory? While our javac and Java commands are in the bin folder under the JDK directory, there are many other baby commands in this folder. As shown in:
How can the operating system find the javac command? Very easy! We need to modify the path of the system variable so that we don't have to run the C: \ j2sdk1.4.2 _ 02 \ bin path every time we want to run this command. We will introduce how to modify the path in the fourth topic.
5. After adding a path: C: \ j2sdk1.4.2 _ 02 \ bin to the PATH variable, go to the command
If javac is entered, a prompt is displayed. This shows that we can start writing Java programs.
6. Let's write a hello. Java test. I created it in the E: \ lesson1 folder.
Input the following code and save it as hello. java.
Public class hello
{
Public static void main (string ARGs [])
{
System. Out. println ("Hello world! ");
}
}
7. Now let's go back to the command prompt. Enter javac hello. Java at the prompt.
Again. Why? Because the file is created under E: \ lesson1, but our current directory is not it. Enter 'e: 'At the prompt, and then press 'CD lesson1' to enter the directory where the Java file is located. Now press javac hello. Java to compile the file. Note that after compilation, A bytecode file named hello. class will be generated in the current directory. But there is no prompt on the screen.
8. Run the 'java hello' command again. Can I run it? Of course not. Why,
Because our bytecode files run in the Java virtual machine, the paths of all bytecode files to be used by the virtual machine must be found in an operating system variable named classpath. Otherwise, our virtual machine will not be able to find this bytecode file and thus will not be able to execute it.
9. What should I do? Run the following command: Set classpath = % classpath %; E: \ lesson1, and then run
Run the Java Hello command. The screen finally showed a cordial greeting: Hello world!
But something strange happened again. When we restart a command prompt window and run the Java file again, we cannot execute it again. The screen prompt is: exception in thread "Main" Java. Lang. noclassdeffounderror: Hello. The problem persists. The virtual machine cannot find the bytecode file again. Why? In fact, the system variables we set in the DOS window are only valid for the current window. To make our variable settings effective for any DOS window, we can also get the desktop. In the fourth topic, we will still discuss how to set the Java environment variable classpath.
Iv. settings of Path System variables and classpath Environment Variables
Why do we need to set the path and classpath variables? We have already introduced them in the previous topic. Next we will explain how to set it:
1. Right-click my computer, select the "properties" menu, and select the "advanced" tab in the pop-up dialog box. On the Advanced Tab page, click the 'environment variable 'button.
2. In the pop-up environment variable window, we will see that it is divided into two parts. Some are user variables, such as administrator user variables. Some are system variables. Generally, the number of variables that can be used at the command prompt is the sum of user variables and system variables. We don't care about user variables. Go directly to the system variable to find the PATH variable. Generally, after the system is installed, the PATH variable already exists here. However, the classpath variable does not exist.
The Environment Variable Window is shown in the figure below:
3. Find the PATH variable and double-click the variable name. The edit system Variable Window is displayed. Stop the cursor at the end of the variable Value dialog box, and add '; C: \ j2sdk1.4.2 _ 02 \ bin '. Note that the path after the semicolon is the path where the Java and javac commands are located. See the figure below:
4. What should I do if the classpath variable cannot be found? Very simple. Click Create in the system variable box. In the new system variable dialog box that appears, enter the name of the variable you want to add: classpath. In the variable Value dialog box, enter the path of the bytecode file you want to run. Description:
In the future, we will find that the bytecode files (class files) required for running virtual machines, including the classes provided by Sun. You must put the paths of these files under classpath. Otherwise, the program often cannot find the required class package during compilation. That's a headache. For example, there are many *. Jar files under the lib directory under the JDK installation directory. When our program uses classes in these compressed files, we need to add the paths of these files to classpath, for example, C: \ j2sdk1.4.2 _ 02 \ Lib \ DT. jar.
Note that there is a slight difference between adding a *. jar package and directly adding a *. Class file path. The former must contain the name of the jar package. The latter only requires the file path.
V. Establishment of J2EE Runtime Environment
To develop enterprise applications, we need to build a J2EE runtime environment. In fact, go to Sun's website to go down the J2EE 1.4 SDK development kit. Double-click the installation file, if the version you downloaded is the same as mine. Then the installation file will be the name: j2eesdk-1_4-dr-windows-eval.exe. We also installed the J2EE SDK in the C root directory.
Note that the establishment of the J2EE runtime environment is based on the establishment of the j2se runtime environment. Actually, I want to see why. Without JDK, where can I compile and run commands (Java and javac ). After installing the J2EE 1.4 SDK package, perform the following steps:
1. First, add the bin directory of J2EE SDK to the PATH variable right. For example, c: \ j2sdkee1.3.1 \ bin. How to add to it has been discussed previously.
2. Create two variables: java_home and set the variable value to the JDK installation directory. The other is j2ee_home. The variable value is the installation directory of the J2EE SDK. Description:
3. Add a key jar package to the classpath variable. It is the J2EE. jar package. For example, I added c: \ j2sdkee1.3.1 \ Lib \ J2EE. jar.
4. After all the work is done. You can verify whether the J2EE environment has been successfully built by using the following methods. Enter the command: J2EE-verbose at the command prompt. If the following J2EE server startup complete is displayed at the bottom of the screen, the J2EE server is successfully started. In the process of deploying and running our J2EE program. The server will continue to start.
Recommended for beginners a programming technology learning site, 96 stack Software Programming Network, http://www.96dz.com, which has c ++ video tutorial, C # video tutorial, Java video tutorial download, c \ c ++, Java, and C #. net and other programming technology abstracts, including the current mainstream Linux programming and web programming learning materials video tutorial download.