Java development environment setup and the first HelloWorld under Linux
- 2020-04-01 04:07:58
- OfStack
Want to do JAVA development on Linux? How to build the environment, how to achieve the first HelloWorld, the following is dedicated:
1 environment construction
1.1 installation of the Java JDK
The Java JDK is a necessary environment for Java to compile and run, so you must first install the package by:
1) download JDK archive,
Note whether the version is x86 or x64, or Windows
Linux, to be clear, I installed the JDK -7u13-linux-i586.tar.gz;
2) unzip the compressed package, and the directory after unzip to /usr/lib/ JVM/under the command as follows (? Represents the directory in which your zip is located) :
~ $: the tar - zxvf The & # 63; / JDK 7 u13 - Linux - i586. Tar. Gz
~ $: sudo mkdir/usr/lib/JVM
~ $: sudo cp & # 63; / jdk1.7.0 _13 / usr/lib/JVM
3) add JAVA_HOME, set up a corresponding environment variable JAVA_HOME with /usr/lib/ jv5/jdk1.7.0_13:
Append the following line to ~ /.profile:
Export JAVA_HOME = / usr/lib/JVM/jdk1.7.0 _13
Append in ~ /.profile and the environment variable is only valid for the current user. If append in /etc/profile, it is valid for all users
Choose accordingly.
Update configuration:
~ $: source ~ /. Profile
4) add CLASSPATH, set up a corresponding environment variable for /usr/lib/ JVM /jdk1.7.0_13/lib, as follows:
Append the following line to ~ /.profile:
Export the CLASSPATH = $JAVA_HOME/lib
Can also be added in /etc/profile, as in (3)
Update configuration:
~ $: source ~ /. Profile
5) check the JDK version to confirm the successful installation:
~ $: Java version
If successful, it displays as follows:
Java version "1.7.0 _13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) Server VM (build 23.7-b01, mixed mode)
2. The first HelloWorld
At this point, we have the full JDK installed, but we don't have any ide installed, just like we don't have VC6 installed in Windows
Same, but by manually creating and compiling the source file, we can run HelloWorld once to see if the JDK is installed correctly and start...
1) edit the source file helloworld.java
, as follows
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello,World!");
return;
}
}
2) compile source files,
As follows:
~ $: javac HelloWorld. Java
When compiled, the helloworld.class file is generated, which is called Java bytecode.
3) execute Java bytecode
That is as follows:
~ $: Java HelloWorld
Note that although the Java bytecode file has the.class suffix, it is not required for execution. Note that after execution, the output is as follows:
Hello, World!
3 use IDE to go graphical - install IntelliJ IDE
Nowadays, eclipse is ubiquitous, but IntelliJ is a good lightweight IDE. Take him for example.
1) download IntelliJ IDE
(link: http://www.jetbrains.com/idea/download/)
The community edition is downloaded in this example
2) unzip ('? 'stands for ideaIC-12.1.6.tar.gz) and is placed under /opt (or any other suitable directory)
~ $: the tar - zxvf The & # 63; / ideaIC - 12.1.6. Tar. Gz
~ $: sudo cp & # 63; / idea - IC - 129.1359 / opt /
3) add /opt/ idea-ic-129.1359 /bin to the environment variable
Can be added in ~/.profile or /etc/profile, but the scope of application is different. In this example, modify /etc/profile and append the following:
The export PATH = $PATH: / opt/idea - IC - 129.1359 / bin
Update configuration:
~ $: source/etc/profile
4) run IDE
The IntelliJ development environment can be started by directly inputting idea.sh into the terminal
~ $: idea. Sh
OK, what's left to do, I think you all know, simply learn how to use IntelliJ, how to build a project, how to add files, how to build a project
Properties are set, compiled, debugged, and generally used in ides.
The above is to share with you about the Linux Java development environment construction and the first HelloWorld, I hope to really help you.