centos6.4中安装java,编译和运行java的一个例子

centos6.4中安装java,编译和运行java的一个例子

其中java 代码如下:

public class hello
{
   public static void main(String[] agrs)
   {
       System.out.print("first java program hello world\r\n");
   }
} 

[root@hsgpc dev]# pwd
/dev

[root@hsgpc /]# useradd h
[root@hsgpc /]# cd home
[root@hsgpc home]# ls
h  hsg  lost+found
[root@hsgpc home]# passwd h

[root@hsgpc home]# su h
[h@hsgpc home]$ ls
h  hsg  lost+found
[h@hsgpc home]$ pwd
/home
[h@hsgpc home]$ su hsg
密码:
[hsg@hsgpc home]$ su h
密码:
[h@hsgpc home]$ ls
h  hsg  lost+found
[h@hsgpc home]$ pwd
/home
[h@hsgpc home]$ ls
h  hsg  lost+found
[h@hsgpc home]$ userdel h
bash: /usr/sbin/userdel: 权限不够
[h@hsgpc home]$ su root
密码:
[root@hsgpc home]# pwd
/home
[root@hsgpc home]# userdel h
userdel: user h is currently used by process 12658
[root@hsgpc home]# ls
h  hsg  lost+found
[root@hsgpc home]# su hsg
[hsg@hsgpc home]$ pwd
/home
[hsg@hsgpc home]$ userdel h
bash: /usr/sbin/userdel: 权限不够
[hsg@hsgpc home]$ su root
密码:
[root@hsgpc home]# userdel h
userdel: user h is currently used by process 12658
[root@hsgpc home]# userdel -r h
userdel: user h is currently used by process 12658
[root@hsgpc home]# exit
exit
[hsg@hsgpc home]$ exit
exit
[root@hsgpc home]# exit
exit
[h@hsgpc home]$ exit
exit
[hsg@hsgpc home]$ exit
exit
[h@hsgpc home]$ exit
exit
[root@hsgpc home]# userdel h
[root@hsgpc home]# ls
h  hsg  lost+found
[root@hsgpc home]# userdel -r h
userdel: user 'h' does not exist
[root@hsgpc home]# useradd h
useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件。
正在创建信箱文件: 文件已存在
[root@hsgpc home]# ls
h  hsg  lost+found
[root@hsgpc home]# pwd
/home
[root@hsgpc home]# ls
h  hsg  lost+found
[root@hsgpc home]# userdel -r h
[root@hsgpc home]# ls
hsg  lost+found
[root@hsgpc home]# cd hsg

[root@hsgpc hsg]# ls -l
总用量 18524
-rw-r--r--. 1 root root       10 11月 22 21:05 hello.java
-rwxrw-r--. 1 hsg  hsg     79010 11月 23 2015 install_chrome.sh
-rw-rw-r--. 1 hsg  hsg     79010 11月 23 2015 install_chrome.sh~
-rw-rw-r--. 1 hsg  hsg      6858 11月 22 18:53 Linux学习之CentOS(二)--初识linux的一些常用命令.txt
-rw-rw-r--. 1 hsg  hsg      1393 11月 23 2015 RedHat&CentOS 6.4安装谷歌浏览器chrome.txt
-rw-rw-r--. 1 hsg  hsg  18746570 11月 23 2015 sogoupinyin_2.0.0.0068_i386.deb
-rw-rw-r--. 1 hsg  hsg         0 11月 22 2015 test.txt
drwxr-xr-x. 2 hsg  hsg      4096 11月 22 2015 公共的
drwxr-xr-x. 2 hsg  hsg      4096 11月 22 2015 模板
drwxr-xr-x. 2 hsg  hsg      4096 11月 22 2015 视频
drwxr-xr-x. 2 hsg  hsg      4096 11月 22 2015 图片
drwxr-xr-x. 2 hsg  hsg      4096 11月 22 2015 文档
drwxr-xr-x. 2 hsg  hsg      4096 11月 23 2015 下载
-rw-rw-r--. 1 hsg  hsg      6858 11月 22 18:53 新文件~
drwxr-xr-x. 2 hsg  hsg      4096 11月 22 2015 音乐
drwxr-xr-x. 2 hsg  hsg      4096 11月 22 19:50 桌面
[root@hsgpc hsg]# clear

[root@hsgpc hsg]# vi hello.java
[root@hsgpc hsg]# gedit hello.java
[root@hsgpc hsg]# vi hello.java
[root@hsgpc hsg]# gedit hello.java
[root@hsgpc hsg]# javac hello.java
bash: javac: command not found
[root@hsgpc hsg]# bash
[root@hsgpc hsg]# sudo install java
install: 在"java" 后缺少了要操作的目标文件
请尝试执行"install --help"来获取更多信息。
[root@hsgpc hsg]# yum install java
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
包 1:java-1.7.0-openjdk-1.7.0.91-2.6.2.2.el6_7.x86_64 已安装并且是最新版本
无须任何处理
[root@hsgpc hsg]# yum list installed :grep java
已加载插件:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
错误:没有匹配的软件包可以列出
[root@hsgpc hsg]# yum list installed |grep java
java-1.6.0-openjdk.x86_64
java-1.7.0-openjdk.x86_64
tzdata-java.noarch      2015g-2.el6     @updates                                
[root@hsgpc hsg]# ping www.baidu.com
PING www.a.shifen.com (180.97.33.108) 56(84) bytes of data.
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=1 ttl=53 time=39.8 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=2 ttl=53 time=40.2 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=3 ttl=53 time=38.9 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=4 ttl=53 time=40.0 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=5 ttl=53 time=39.3 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=6 ttl=53 time=39.5 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=7 ttl=53 time=39.8 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=8 ttl=53 time=39.1 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=9 ttl=53 time=41.0 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=10 ttl=53 time=38.9 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=11 ttl=53 time=39.3 ms
64 bytes from sp3.baidu.com (180.97.33.108): icmp_seq=12 ttl=53 time=39.6 ms
^C
--- www.a.shifen.com ping statistics ---
12 packets transmitted, 12 received, 0% packet loss, time 11686ms
rtt min/avg/max/mdev = 38.921/39.675/41.056/0.601 ms
[root@hsgpc hsg]# yum -y list java*
已加载插件:fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
已安装的软件包
java-1.6.0-openjdk.x86_64                  1:1.6.0.37-1.13.9.4.el6_7    @updates
java-1.7.0-openjdk.x86_64                  1:1.7.0.91-2.6.2.2.el6_7     @updates
可安装的软件包
java-1.5.0-gcj.x86_64                      1.5.0.0-29.1.el6             base    
java-1.5.0-gcj-devel.x86_64                1.5.0.0-29.1.el6             base    
java-1.5.0-gcj-javadoc.x86_64              1.5.0.0-29.1.el6             base    
java-1.5.0-gcj-src.x86_64                  1.5.0.0-29.1.el6             base    
java-1.6.0-openjdk-demo.x86_64             1:1.6.0.37-1.13.9.4.el6_7    updates
java-1.6.0-openjdk-devel.x86_64            1:1.6.0.37-1.13.9.4.el6_7    updates
java-1.6.0-openjdk-javadoc.x86_64          1:1.6.0.37-1.13.9.4.el6_7    updates
java-1.6.0-openjdk-src.x86_64              1:1.6.0.37-1.13.9.4.el6_7    updates
java-1.7.0-openjdk-demo.x86_64             1:1.7.0.91-2.6.2.2.el6_7     updates
java-1.7.0-openjdk-devel.x86_64            1:1.7.0.91-2.6.2.2.el6_7     updates
java-1.7.0-openjdk-javadoc.noarch          1:1.7.0.91-2.6.2.2.el6_7     updates
java-1.7.0-openjdk-src.x86_64              1:1.7.0.91-2.6.2.2.el6_7     updates
java-1.8.0-openjdk.x86_64                  1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-debug.x86_64            1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-demo.x86_64             1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-demo-debug.x86_64       1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-devel.x86_64            1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-devel-debug.x86_64      1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-headless.x86_64         1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-headless-debug.x86_64   1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-javadoc.noarch          1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-javadoc-debug.noarch    1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-src.x86_64              1:1.8.0.65-0.b17.el6_7       updates
java-1.8.0-openjdk-src-debug.x86_64        1:1.8.0.65-0.b17.el6_7       updates
java_cup.x86_64                            1:0.10k-5.el6                base    
java_cup-javadoc.x86_64                    1:0.10k-5.el6                base    
java_cup-manual.x86_64                     1:0.10k-5.el6                base    
javacc.x86_64                              4.1-0.5.el6                  base    
javacc-demo.x86_64                         4.1-0.5.el6                  base    
javacc-manual.x86_64                       4.1-0.5.el6                  base    
javassist.noarch                           3.9.0-6.el6                  base    
javassist-javadoc.noarch                   3.9.0-6.el6                  base    
[root@hsgpc hsg]# yum -y install java-1.7.0-openjdk*
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirror.bit.edu.cn
包 1:java-1.7.0-openjdk-1.7.0.91-2.6.2.2.el6_7.x86_64 已安装并且是最新版本
解决依赖关系
--> 执行事务检查
---> Package java-1.7.0-openjdk-demo.x86_64 1:1.7.0.91-2.6.2.2.el6_7 will be 安装
---> Package java-1.7.0-openjdk-devel.x86_64 1:1.7.0.91-2.6.2.2.el6_7 will be 安装
---> Package java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.91-2.6.2.2.el6_7 will be 安装
---> Package java-1.7.0-openjdk-src.x86_64 1:1.7.0.91-2.6.2.2.el6_7 will be 安装
--> 完成依赖关系计算

依赖关系解决

=======================================================================================
 软件包                        架构      版本                         仓库        大小
=======================================================================================
正在安装:
 java-1.7.0-openjdk-demo       x86_64    1:1.7.0.91-2.6.2.2.el6_7     updates    1.9 M
 java-1.7.0-openjdk-devel      x86_64    1:1.7.0.91-2.6.2.2.el6_7     updates    9.5 M
 java-1.7.0-openjdk-javadoc    noarch    1:1.7.0.91-2.6.2.2.el6_7     updates     16 M
 java-1.7.0-openjdk-src        x86_64    1:1.7.0.91-2.6.2.2.el6_7     updates     39 M

事务概要
=======================================================================================
Install       4 Package(s)

总下载量:66 M
Installed size: 315 M
下载软件包:
(1/4): java-1.7.0-openjdk-demo-1.7.0.91-2.6.2.2.el6_7.x86_64.rp | 1.9 MB     00:02     
(2/4): java-1.7.0-openjdk-devel-1.7.0.91-2.6.2.2.el6_7.x86_64.r | 9.5 MB     00:10     
(3/4): java-1.7.0-openjdk-javadoc-1.7.0.91-2.6.2.2.el6_7.noarch |  16 MB     00:15     
(4/4): java-1.7.0-openjdk-src-1.7.0.91-2.6.2.2.el6_7.x86_64.rpm |  39 MB     00:34     
---------------------------------------------------------------------------------------
总计                                                   1.0 MB/s |  66 MB     01:03     
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
  正在安装   : 1:java-1.7.0-openjdk-src-1.7.0.91-2.6.2.2.el6_7.x86_64              1/4
  正在安装   : 1:java-1.7.0-openjdk-javadoc-1.7.0.91-2.6.2.2.el6_7.noarch          2/4
  正在安装   : 1:java-1.7.0-openjdk-demo-1.7.0.91-2.6.2.2.el6_7.x86_64             3/4
  正在安装   : 1:java-1.7.0-openjdk-devel-1.7.0.91-2.6.2.2.el6_7.x86_64            4/4
  Verifying  : 1:java-1.7.0-openjdk-devel-1.7.0.91-2.6.2.2.el6_7.x86_64            1/4
  Verifying  : 1:java-1.7.0-openjdk-demo-1.7.0.91-2.6.2.2.el6_7.x86_64             2/4
  Verifying  : 1:java-1.7.0-openjdk-javadoc-1.7.0.91-2.6.2.2.el6_7.noarch          3/4
  Verifying  : 1:java-1.7.0-openjdk-src-1.7.0.91-2.6.2.2.el6_7.x86_64              4/4

已安装:
  java-1.7.0-openjdk-demo.x86_64 1:1.7.0.91-2.6.2.2.el6_7                              
  java-1.7.0-openjdk-devel.x86_64 1:1.7.0.91-2.6.2.2.el6_7                             
  java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.91-2.6.2.2.el6_7                           
  java-1.7.0-openjdk-src.x86_64 1:1.7.0.91-2.6.2.2.el6_7                               

完毕!
[root@hsgpc hsg]# java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (rhel-2.6.2.2.el6_7-x86_64 u91-b00)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
[root@hsgpc hsg]# javac
用法: javac <options> <source files>
.....

[root@hsgpc hsg]# pwd
/home/hsg
[root@hsgpc hsg]# javac hello.java
hello.java:1: 错误: 类helloworld是公共的, 应在名为 helloworld.java 的文件中声明
public class helloworld
       ^
1 个错误
[root@hsgpc hsg]# vi hello.java
[root@hsgpc hsg]# gedit hello.java
[root@hsgpc hsg]# javac hello.java
[root@hsgpc hsg]# java hello
错误: 在类 hello 中找不到主方法, 请将主方法定义为:
   public static void main(String[] args)
[root@hsgpc hsg]# gedit hello.java
[root@hsgpc hsg]# javac hello.java
[root@hsgpc hsg]# java hello
[root@hsgpc hsg]# java hello
first java program hello world[root@hsgpc hsg]# gedit hello.java
[root@hsgpc hsg]# javac hello.java
[root@hsgpc hsg]# java hello
first java program hello world
[root@hsgpc hsg]# ^C
[root@hsgpc hsg]#
[root@hsgpc hsg]# ls
hello.class                                         公共的
hello.java
                                          模板
hello.java~                                         视频
install_chrome.sh                                   图片
install_chrome.sh~                                  文档
Linux学习之CentOS(二)--初识linux的一些常用命令.txt  下载
RedHat&CentOS 6.4安装谷歌浏览器chrome.txt           新文件~
sogoupinyin_2.0.0.0068_i386.deb                     音乐
test.txt                                            桌面
test.txt~
[root@hsgpc hsg]#


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值