1 java简介
- Java 是由 Sun Microsystems 公司于 1995 年 5 月推出的 Java 面向对象程序设计语言和 Java 平台的总称。由 James Gosling和同事们共同研发,并在 1995 年正式推出,后来 Sun 公司被 Oracle (甲骨文)公司收购,Java 也随之成为 Oracle 公司的产品。
- Java是一种通用的,基于类的,面向对象的编程语言。它是用于应用程序开发的计算平台。因此,Java是快速,安全和可靠的。
2 java的三大平台
- Java SE:Java 语言的(标准版),用于桌面应用的开发,是其他两个版本的基础。
- Java ME:Java 语言的(小型版),用于嵌入式消费类电子设备(基本淘汰)。
- Java EE:Java 语言的(企业版),用于 Web 方向的网站开发。
3 java的主要特性
- Java 语言是简单的
- Java 语言是面向对象的
- Java语言是分布式的
- Java 语言是健壮的
- Java 语言是体系结构中立的
- Java语言是安全的
- Java 语言是可移植的
- Java 语言是解释型的
- Java 是高性能的
- Java 语言是多线程的
- Java 语言是动态的
4 检查本地系统环境
1)检查系统版本
 检查本地系统版本,本次实践使用的是centos7.6版本。
[root@jeven ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)2)检查系统内核版本
 检查系统内核版本
[root@jeven ~]# uname -r 
6.1.8-1.el7.elrepo.x86_645 清空java环境
1)删除java目录
 查询java所在位置
[root@jeven ~]# which java
/usr/bin/java2)删除java
[root@jeven ~]# rm -rf /usr/bin/java
[root@jeven ~]# java -version
bash: java: command not found...3)移除所有java相关包
卸载所有java相关的软件
 yum -y remove *java*4)清空java环境变量
在/etc/profile等环境变量文件中,删除java相关环境变量。
6 使用yum安装java
1)搜索本地java软件版本
 检查java是否安装
[root@jeven ~]# rpm -qa | grep java
[root@jeven ~]# 2)搜索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  3)安装java
安装的版本为java-1.8.0-openjdk-devel.x86_64
yum install java-1.8.0-openjdk-devel.x86_64 -y4)配置环境变量
 在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 PATH5)使java相关变量生效
[root@jeven ~]# source /etc/profile
[root@jeven ~]# 6)查看java版本
 查看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 file7 二进制包安装java
1)下载java软件包
 java下载地址:https://www.oracle.com/java/technologies/downloads/#java8
[root@jeven jdk]# ls
jdk-8u202-linux-x64.tar.gz2)解压jdk安装包
 解压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.txt3)复制jdk的二进制文件
 将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.txt4)配置环境变量
 在/etc/profile文件中,新增以下两行:
export JAVA_HOME=/usr/local/jdk
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin使变量文件生效
source /etc/profile5)查看java版本
 查看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)8 测试java安装环境
1)编辑test.java文件
[root@jeven jdk]# cat test.java 
public class test{public static void  main (String[] args) {System.out.println("java test ok");}
}
[root@jeven jdk]# 2)运行测试文件
 运行测试文件,检查是否正确输出,正常输出打印内容,则java环境安装成功。
[root@jeven jdk]# javac test.java 
[root@jeven jdk]# java test
java test ok