> Ubuntu >

ubuntu中运行java程序

查找jdk

it@it:~/demo/java$ sudo apt-cache search jdk
default-jdk - Standard Java or Java compatible Development Kit


安装

it@it:~/demo/java$ sudo apt-get install default-jdk




示例代码

复制代码
it@it:~/demo/java$ cat Welcome.java
public class Welcome
{
    public static void main(String[] args)
    {
        String greeting = "Welcome to Core Java!";
        System.out.println(greeting);
    }
}
复制代码


编译,执行

it@it:~/demo/java$ javac Welcome.java
it@it:~/demo/java$ java Welcome
Welcome to Core Java!


(责任编辑:IT)