背景
由于IntelliJ IDEA是需要激活码的,简单的java demo测试,除了可以直接使用命令行java和javac进行执行, 推荐使用VS code, 其功能比较强大,扩展插件也比丰富,对阅读和书写代码都是比较友好的.
JDK环境准备
Linux JDK可以使用Open JDK 11.
sudo apt-get install openjdk-11-jdk
查询是否源中有什么版本的JDK, 命令如下:
sudo apt-cache search openjdk
本机输出结果如下:
openjdk-11-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-11-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-11-doc - OpenJDK Development Kit (JDK) documentation
openjdk-11-jdk - OpenJDK Development Kit (JDK)
openjdk-11-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-11-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-11-jre-dcevm - Alternative VM for OpenJDK 11 with enhanced class redefinition
openjdk-11-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-11-jre-zero - Alternative JVM for OpenJDK, using Zero
openjdk-11-source - OpenJDK Development Kit (JDK) source files
openjdk-8-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-8-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-8-doc - OpenJDK Development Kit (JDK) documentation
openjdk-8-jdk - OpenJDK Development Kit (JDK)
openjdk-8-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-8-jre - OpenJDK Java runtime, using Hotspot JIT
openjdk-8-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-8-jre-zero - Alternative JVM for OpenJDK, using Zero/Shark
个人电脑是自带的源中含有openjdk11, 如果是其他系统,可以自行百度添加源来安装.
swd@swd-PC:~$ apt-cache policy openjdk-11-jdk
openjdk-11-jdk:
已安装:11.0.9.2+1-1~deb10u2
候选: 11.0.9.2+1-1~deb10u2
版本列表:
*** 11.0.9.2+1-1~deb10u2 500
500 https://community-packages.deepin.com/deepin apricot/main amd64 Packages
100 /usr/lib/dpkg-db/status
VS Code插件安装
1.Oracle coporation Java
安装了这个可以书写和书写java代码,但是好像不支持格式化代码.
2.Microsoft提供的Extension Pack for Java
这个pack包含了Language support for Java(TM), Debugger for Java,Test Runner for Java, Maven for Java, Project Manager for Java, IntelliCode这几个插件, 相当于一个微软认为的一个java开发套件. 除了第一个是RedHat提供,其他都是由微软提供.
实例运行
举个Math.acos()反三角函数的例子来测试下.
根据运算结果等于30度, 由此也直到Math反三角函数得到的值是弧度制,需要转换后才是才是熟知的角度度数制.
从效果来看, 和其他IDE工具差不多,可以辅助自动补全和提示函数doc.