Detail ubuntu to build Java development environment

  • 2020-05-14 05:39:07
  • OfStack

As a new Java programmer, build the Java development environment in Ubuntu before writing the first Hello, world program.
Structure of this paper:

1. JDK installation 2. MyEclipse installation 3. Hello World test

1. JDK installation
Well, I'll take JDK 1.6, isn't it a bit out?
1, download JDK1.6, you can go to the official website to download, download please see their own version of the system, remember 1 must download the corresponding version.
2. Place the downloaded file in the /usr/lib/java directory (you need to manually create the java directory) and modify the executable permissions of the file, such as chmod 777 jdk-6u41-linux-x64.bin
[PS: if you can't create java because you already have java, you can name the directory java1.6 (meaning this is version 1.6 of jdk)]
3. Installation file, sudo./ jdk-6u41-linux-x64.bin
4. After the installation, the system environment sudo vi /etc/environment shall be configured, or the user environment variable vi /home/username/.bashrc shall be configured, JAVAHOME,CLASSPATH shall be established, and PATH variable shall be modified
As I set:


JAVA_HOME= " /usr/lib/java1.6/jdk1.6.0_41 " 
PATH= " /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/java1.6/jdk1.6.0_41/bin:/usr/lib/java1.6/jdk1.6.0_41/jre/bin " 
CLASSPATH= " /usr/lib/java1.6/jdk1.6.0_41/lib:/usr/lib/java1.6/jdk1.6.0_41/jre/lib " 

5. Execute the command to make the configuration effective. source /etc/environment(source /home/username/.bashrc)
6. Verify whether the installation is completed, and use java-version or javac directly to see whether it is effective or not.
7. If it has not taken effect, it is likely that there is a default jdk in ubuntu, such as openjdk. Therefore, in order to use the default jdk we installed, we need to do the following work.


sudo update-alternatives  � install /usr/bin/java java /usr/lib/java/jdk1.6.0_41/bin/java 300
sudo update-alternatives  � install /usr/bin/javac javac /usr/lib/java/jdk1.6.0_41/bin/javac 300

Add the jdk we installed to the java menu through this 1 step.
Then execute:
update - alternatives � config java
2. MyEclipse installation
Install package download, download is completed, modify the rights of the direct execution can be installed.
3. The first Hello world program

1) create a new java project and name it HelloWorld
2) create a new package and name it com.cricode
3) create a new SayHello class in package com.cricode, as follows:


package com.cricode;
 
public class SayHello {
 public static void main(String[] args){
 System.out.println("Hello,world");
 }
}

Results: Hello,world

At this point, the Java development environment on Linux has been installed. Hope you enjoy it.


Related articles: