Java SE 9(JDK9)环境安装及交互式编程环境Jshell使用示例

目的

安装JDK 9, 练习Jshell工具的使用, 体验Java的交互式编程环境。

什么是Jshell

其实就是一个命令行工具,安装完JDK9后,可以在bin目录下找到该工具,与Python的解释器极其相似,用过Python解释器的人应该会非常熟悉。

它可以让你体验交互式编程,有一些比较有趣的特性:

1、语句末尾可以省略分号

2、一般情况下不需要强制捕获受检异常

3、可以直接写表达式

4、在定义方法时可以引用其他方法或变量,且这些方法或变量可以在一段时间后被定义;

 5、其它等等

安装JDK 9

下载

可以去以下连接下载:

https://jdk9.java.net/download/

http://down.downun.com/%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/java/

我下载的是jdk-9-ea+140_windows-x64_bin.exe;

安装

很简单,直接点击安装即可,记得勾选自定义,选择一个合适的安装路径,我安装在D:\ProgramFiles\Java\jdk-9

设置环境变量

自行参考网上的配置,设置JAVA_HOME、PATH、CLASSPATH什么的,如果仅仅想尝试使用下Jshell的话,也可以不设置;

Jshell工具使用

直接在JDK安装目录的bin文件夹下双击jshell.exe即可。

创建一个类,调用静态方法

注意这里,我们不需要编写main方法就可以直接运行。

其它使用示例

输入/help获取帮助

有没发现跟Python解释器极其相似, 剩下的有兴趣自己探索吧。

参考资料

http://www.importnew.com/16353.html

http://www.journaldev.com/9879/java9-install-and-repl-jshell-tutorial

Java 9 with JShell by Gaston C. Hillar English | 29 Mar. 2017 | ASIN: B01N388HH3 | 408 Pages | AZW3 | 8.99 MB Key Features A full account of Java 9's new features This tutorial emphasises fluency using JShell exercises Get a thorough introduction to contract programming code reuse via Java generics Learn how to use the new module system How to use proper functional programming style inside Java 9 Book Description The release of Java 9 has brought many subtle and not-so-subtle changes to the way in which Java programmers approach their code. The most important ones are definitely the availability of a REPL, known as JShell, which will make experiments and prototyping much more straightforward than the old IDE-based project-led approach. Another, more subtle change can be seen in the module system, which will lead to more modularized, maintainable code. The techniques to take full advantage of object-oriented code, functional programming and the new modularity features in Java 9 form the main subjects of this book. Each chapter will add to the full picture of Java 9 programming starting out with classes and instances and ending with generics and modularity in Java. What you will learn Engage with object-oriented programming in Java 9, starting with code snippets in JShell Optimize your code, applying functional programming features Discover the advantages of modularity Become very proficient at using JShell itself Learn the new approach to Java programming, which uses the REPL as a prototyping tool About the Author Gaston C. Hillar is Italian and has been working with computers since he was 8 years old. In the early 80s, he began programming with the legendary Texas TI-99/4A and Commodore 64 home computers. Gaston has a bachelor's degree in computer science (he graduated with honors). He also holds an MBA (he graduated with an outstanding thesis). At present, Gaston is an independent IT consultant and a freelance author who is always looking for new adventures around the world. He was a senior contributing editor at Dr. Dobb's and has written more than a hundred articles on software development topics. He has received the prestigious Intel® Black Belt Software Developer award eight times. He has written many articles about Java for Oracle Java Magazine. Gaston was also a former Microsoft MVP in technical computing. He is a guest blogger at Intel® Software Network (http://software.intel.com). You can reach him at gastonhillar@hotmail.com and follow him on Twitter at http://twitter.com/gastonhillar. Gaston's blog is http://csharpmulticore.blogspot.com. He lives with his wife, Vanesa, and his two sons, Kevin and Brandon. Table of Contents JShell – A Read-Evaluate-Print-Loop for Java 9 Real-World Objects to UML Diagrams and Java 9 via JShell Classes and Instances Encapsulation of Data Mutable and Immutable Classes Inheritance, Abstraction, Extension, and Specialization Members Inheritance and Polymorphism Contract Programming with Interfaces Advanced Contract Programming with Interfaces Maximization of Code Reuse with Generics Advanced Generics Object-Oriented, Functional Programming, and Lambda Expressions Modularity in Java 9 Exercise Answers
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值