Build Java environment variables under Linux and implement the first Java applet

Source: Internet
Author: User

1. First, we open the Linux operating system inside the virtual machine and then click on the virtual Machine option under the menu:

Under Virtual machine, click the Settings menu, as shown in:

Here I have added to the folder I need, I put it in the e-disk under the As folder in the end what put it?

These two compressed files, one is Android Studio compressed package, released last year, has been useless it, today originally wanted to install this software under Windows, Found that the required JDK is 1.7, and I am in the JDK version of Windows 1.6, so I intend to install jdk1.7 under the Linux operating system, and install Andoid Studio Tools, under the Linux system to play Android and Java, after all, Android is related to Linux , because my Computer compare card, so in Red Hat Linux installed configuration Java environment, if everyone computer configuration can, recommend that everyone in Ubuntu under the mobile development.

Select the red button above, select Always enable the shared folder, and then put the files you need to the local hard disk, click Add, and then click OK, so in the Linux system there is a folder called as, and this file directory on the Linux operating system where?

Note: The above two compressed packages can be found on the official website.




2. Next, how do I find the as file directory? In the Linux operating system, some of the folders and files imported into the share are placed in the MNT directory, and where is the MNT directory?

First, open the command line, and then enter the command: CD. This command is used to jump to the working directory under the root directory, after input such as:

Then enter the command: LS to see what directory is under the root directory:

See there is a mnt directory, we look at the MNT directory in the end there is no as this file directory, enter the command shown after the discovery:

How can not, how to have a Hgfs file directory? Well, what's the deal? Is it possible under the Hgfs directory? Next enter the command shown:

As file directory, what's the other stuff? Enter the command separately: CD as and ls-l as shown:

So there are two compressed packages, you can extract and start to configure the Java environment variables, because this step is to take everyone has been to find the as directory exactly where, so entered so many commands, if we know that the ad directory in the root directory under the MNT directory under the Hgfs directory, And the work path is in the root directory, you can enter this line command directly at the command line, as shown in:

Then enter the CD as command to jump to the as this working directory.




3. Next, you can extract the JDK tarball in the as directory, how to unzip it, because the JDK compression package suffix named tar.gz, so you can use the command: TAR-ZXVF compressed file name. tar.gz, after this command is executed, the extracted files are placed in the current working directory, as shown in:

After decompression, a directory of JDK appears in the as directory.




4. After the decompression is complete, you can start to configure the Java environment variables.

(1). Configure the Java environment variables, there are three ways, not described here, because my computer is only as a development use, so I directly modify the/etc/profile file, because all the user's shell can use these environment variables, will bring security issues to the system, Here I only introduce this method, if you want to know more, you can look at this article, I also learn from this article, article address: http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html

First, we use the command to open the/etc/profile file, you can use the command: Gedit/etc/profile or vi/etc/profile, are open a file, but there is a difference, using gedit This command to open the file and modify it, If the file is read-only and no permissions are written into it, it cannot be modified and saved, so it is recommended to use the VI Editor to modify the file:

Because we need to use the path of the JDK, we must know the JDK installation directory, when we unpack the JDK package, we unzip the JDK package into the directory under as, so you can use the command to view the JDK installation directory:

Then we use the command: vi/etc/profile This command to open the profile of this file, as shown in the following:


Using the arrow keys on the keyboard, move to the end of the/etc/profile file, press the INSERT key under the keyboard, insert some data, that is, add the configuration of the Java environment variable at the end of the profile, and add the following content:

Export java_home=/mnt/hgfs/as/jdk1.7.0_75

Export path= $JAVA _home/bin: $PATH

Export classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar


As shown in the following:



Then press the ESC key under the keyboard, then press shift+:, and then enter Wq hit Enter, as shown:

If the user wants to save and exit, you can enter: Wq, which is to save and exit after modifying the file.

After you modify the profile, after configuring the environment variables, you must restart the Linux system and enter the command reboot to restart the Linux operating system.



(2). After rebooting the system, let's test the Java environment variable configuration successfully. No, we can enter javac directly at the command line, as shown in:

This proves that you are successful in configuring the Java environment variable under the Linux operating system, and we can enter the command java-version to see the version information of the JDK, as shown in:




5. Configure the Java environment variables, you can start to write the first Java applet under the Linux operating system, that is, we are very familiar with the Hello World applet:

(1). First, we create a new Java file under the current directory, which is the root directory, and we can enter the command touch Hello.java, which creates a Hello.java file under root, and then through Gedit Hello.java command can write Java code, and then save, or use VI Hello.java to edit this Java file, here I directly use the VI editor to do, I directly at the command line Input command VI Hello.java, So the system will default to the root directory to help us create a new Hello.java file, then we can start to write our Java code, enter the VI Hello.java command, as shown in:

Then after we press the INSERT key, we can start writing Java code as shown in:

Then press ESC, then press shift+: Key combination, enter Wq press ENTER, save the file contents and exit the VI editor, as shown in:



(2). Below we can enter Javac Hello.java and Java Hello commands separately, as shown in:

The Hello World message will print out.




6. The above content is only for your study reference, write not good, please forgive me, if there are errors, please point out, thank you!

This article refers to the article: http://www.cnblogs.com/samcn/archive/2011/03/16/1986248.html



Build Java environment variables under Linux and implement the first Java applet

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.