1.Java 是由 Sun Microsystems 公司于 1995 年 5 月推出的 Java 面向对象程序设计语言和 Java 平台的总称。由 James Gosling和同事们共同研发,并在 1995 年正式推出,后来 Sun 公司被 Oracle (甲骨文)公司收购,Java 也随之成为 Oracle 公司的产品。
2.Java是一种通用的,基于类的,面向对象的编程语言。它是用于应用程序开发的计算平台。因此,Java是快速,安全和可靠的。
Java SE:Java 语言的(标准版),用于桌面应用的开发,是其他两个版本的基础。
Java ME:Java 语言的(小型版),用于嵌入式消费类电子设备(基本淘汰)。
Java EE:Java 语言的(企业版),用于 Web 方向的网站开发。
检查本地系统版本,本次实践使用的是centos7.6版本。
[root@jeven ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
检查系统内核版本
[root@jeven ~]# uname -r
6.1.8-1.el7.elrepo.x86_64
查询java所在位置
[root@jeven ~]# which java
/usr/bin/java
删除java
[root@jeven ~]# rm -rf /usr/bin/java
[root@jeven ~]# java -version
bash: java: command not found...
卸载所有java相关的软件
yum -y remove *java*
在/etc/profile等环境变量文件中,删除java相关环境变量。
检查java是否安装
[root@jeven ~]# rpm -qa | grep java
[root@jeven ~]#
搜索java的jdk版本
[root@jeven ~]# yum list | grep java-1.8.0-openjdk
java-1.8.0-openjdk.i686 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-accessibility.i686 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-demo.i686 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-src.i686 1:1.8.0.362.b08-1.el7_9 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.362.b08-1.el7_9 updates
安装的版本为java-1.8.0-openjdk-devel.x86_64
yum install java-1.8.0-openjdk-devel.x86_64 -y
在etc/profile中配置java环境
AVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b08-1.el7_9.x86_64/
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
使java相关变量生效
[root@jeven ~]# source /etc/profile
[root@jeven ~]#
查看java版本
[root@jeven lib]# java -version
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM (build 25.362-b08, mixed mode)
[root@jeven lib]# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-profile <profile> Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-Werror Terminate compilation if warnings occur
@<filename> Read options and filenames from file
java下载地址:https://www.oracle.com/java/technologies/downloads/#java8
[root@jeven jdk]# ls
jdk-8u202-linux-x64.tar.gz
接jkd软件的压缩包
[root@jeven jdk]# tar -xzf jdk-8u202-linux-x64.tar.gz
[root@jeven jdk]# ls jdk
jdk1.8.0_202/ jdk-8u202-linux-x64.tar.gz
[root@jeven jdk]# ls jdk1.8.0_202/
bin include jre LICENSE README.html src.zip THIRDPARTYLICENSEREADME.txt
COPYRIGHT javafx-src.zip lib man release THIRDPARTYLICENSEREADME-JAVAFX.txt
将jdk的二进制文件复制到/usr/local/目录下
[root@jeven ~]# cp -r /data/jdk/jdk1.8.0_202/ /usr/local/jdk/
[root@jeven ~]# ls /usr/local/jdk/
bin include jre LICENSE README.html src.zip THIRDPARTYLICENSEREADME.txt
COPYRIGHT javafx-src.zip lib man release THIRDPARTYLICENSEREADME-JAVAFX.txt
在/etc/profile文件中,新增以下两行:
export JAVA_HOME=/usr/local/jdk
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
使变量文件生效
source /etc/profile
查看java版本,检查是否安装成功。
[root@jeven ~]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
[root@jeven jdk]# cat test.java
public class test{
public static void main (String[] args) {
System.out.println("java test ok");
}
}
[root@jeven jdk]#
运行测试文件,检查是否正确输出,正常输出打印内容,则java环境安装成功。
[root@jeven jdk]# javac test.java
[root@jeven jdk]# java test
java test ok