I have never written programs in Java. As a Java novice, before writing the first Hello and world program, I will first build a Java development environment in Ubuntu.
1. JDK installation
OK, I chose JDK1.6, isn't it a bit out?
1. Download JDK1.6. You can go to the official website to download. Please see your own system version clearly when downloading. Remember to download the corresponding version.
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u41-oth-JPR
2. Place the downloaded file in /usr/lib/java directory (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 the prompt is that there is already a file java and cannot create java, you can name the directory java1.6 (indicates that this is jdk version 1.6)]
3. Installation file, sudo ./jdk-6u41-linux-x64.bin
4. After the installation is completed, you need to configure the system environment sudo vi /etc/environment, or configure the user environment variable vi /home/username/.bashrc, create JAVAHOME, CLASSPATH, and modify the PATH variable as my settings are:
The code copy is as follows:
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 take effect. source /etc/environment ( source /home/username/.bashrc )
6. Verify whether the installation is complete, use java -version or use javac directly to see if it takes effect.
7. If it has not yet taken effect, it is very likely that since there is a default jdk in ubuntu, such as openjdk, in order to make the default jdk we installed, the following work needs to be carried out.
The code copy is as follows:
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
In this step, we add the jdk we installed to the java menu.
Then execute:
The code copy is as follows:
update-alternatives config java
2. MyEclipse installation
Installation package download address: http://www.my-eclipse.cn/history.html
After the download is completed, the modification permissions can be directly executed and installed.
3. The first Hello world program
1) Create a new java project and name it HelloWorld
2) Create a new package, and the package name is com.cricode
3) Create a new class SayHello in package com.cricode, with the following content:
The code copy is as follows:
package com.cricode;
public class SayHello {
public static void main(String[] args){
System.out.println("Hello,world");
}
}
Running result: Hello, world
At this point, the Java development environment on Linux has been installed.