`

Java 7 New Features(下篇)

 
阅读更多

本文节上篇 :     http://isilic.iteye.com/blog/1729439

 

CHAPTER 6:Stream IO in Java 7

看前言,Java 7 支持Socket Direct Protocol(SDP)协议,支持点到点双向并行数据传输,具体对这个技术感兴趣的可以看下本节。不过IO操作在每次Java版本更新时都是个重点,在实际应用中,这块的更新也是比较受人关注的。大家可以仔细阅读下此节。


  1. Managing simple filesFiles.readAllBytesFiles.writeFiles.readAllLines,能够通过Path直接读取文件内容。
  2. Using buffered IO for files:如果想使用带BufferIOStream,请使用Files.newBufferedReaderFiles.newBufferedWriter、当然也支持非Buffer的操作,直接得到IOStream,如Files.newInputStreamFiles.newOutputStream
  3. Random access IO using the SeekableByteChannelFiles.newByteChannel ,可以得到SeekableByteChannel,这个和Seekable接口差不多,支持回读和access directly
  4. Managing asynchronous communication using the AsynchronousServerSocketChannel classAsynchronousServerSocketChannelServer Socket的使用更加简单方便,使用监听模式,这种server设计更符合胃口。
  5. Writing to a file using the AsynchronousFileChannel class:异步写文件,这个使用场景得仔细考虑。
  6. Reading from a file using the AsynchronousFileChannel class:异步读。
  7. Using the SecureDirectoryStream classFiles.newDirectoryStream可以得到SecurityDirectoryStream,这个类的使用需要os的支持,如果转换失败,说明os并不支持这个SecurityDirectoryStream操作。
CHAPTER 7:Graphical User Interface Improvement
这个是Java的GUI操作的,这块了解不深,做的内容页不多,在此处就只是简单的列出来,对于熟悉Java GUI编程的同学来说,这个也不会是难点。我在这里就少说两句,以免贻笑于大方之家。
  1. Mixing heavyweight and lightweight components
  2. Managing window types
  3. Managing the opacity of a window
  4. Creating a varying gradient translucent window
  5. Managing the shape of a window
  6. Using the new border types in Java 7
  7. Handling multiple file selection in the FileDialog class
  8. Controlling the print dialog box type
  9. Using the new JLayer decorator for a password field

CHAPTER 8:Handling Events
GUI 操作,同上。
  1. Managing extra mouse buttons and high resolution mouse wheels
  2. Controlling focus when displaying a window
  3. Using secondary loops to mimic modal dialog boxes
  4. Handling spurious thread wakeups
  5. Handling applet initialization status with event handlers

CHAPTER 9:Databases, Security, and System Enhancement
这几个增强点有点不好说,应该说算是跟上规范了吧
  1. Using the RowSetFactory class:使用RowSetFactory代替了驱动加载的过程,不过得支持JDBC4.1,例子里使用Derby数据库,倒是清晰明了。
  2. Java 7 database enhancements:数据库的增强,拿到了数据库和表的一些信息,如SchemaAutoGeneratedKeys等;其它增强如伪列(Pseudo-Column),输出类型控制、Driver Log控制等。
  3. Using the ExtendedSSLSession interface:这块研究不深,不敢往上面写;不过书里的内容还算浅显,大家自己看吧。
  4. Using the platform MXBeans for JVM or system process load monitoring:这个是JMX的改进,ManagementFactory的功能被增强了,能够获得的JVM的信息增多;操作系统的信息也能作为MXBean的内容得到;还得提一下jconsole,这个是观察MXBeans的好地方,自己注册的MXBean可以在这边查下状态。
  5. Redirecting input and output from operating system's processes:这个是ProcessBuilderredirect功能,将输入Input、输出Output、错误Error重定向到文件或者其它地方。
  6. Embedding a JNLP file in an HTML pageJava Network Launch Protocol(JNLP),直接嵌入到HTML代码中,减少了装载的时间;以前版本的JNLP必须先下载装载完成或才能执行。这个功能还真没有用过,如果有误,请大家及时指正。
CHAPTER 10:Concurrent Processing
并发编程这块是个重点和难点,这个开发的leader还是Doug Lea,什么,你不知道这个人?好吧,我就当没有听见这句话。终于支持Fork-Join编程模型了啊;单是这个编程模型的支持,就能办好多事啦。这章对于Java开发者来说,都是个不小的诱惑,总想一睹为快。

  1. Using join/fork framework in Java:典型的Fork/Join模型,ForkJoinPoolRecursiveTaskRecursiveAction等,细节还要看源码。
  2. Using the reusable synchronization barrier Phaser
  3. Using the new LinkedTransferQueue class:这个是QueueunboundFIFOblocking or non-blockingThreadsafetransfer方法是block操作,tryTransfer是立即执行操作,根据情况返回True或者False
  4. Using the new LinkedTransferQueue class:这个是QueueunboundFIFOblocking or non-blockingThreadsafetransfer方法是block操作,tryTransfer是立即执行操作,根据情况返回True或者False
  5. Supporting multiple threads using the ThreadLocalRandom class:官方推荐在多线程下使用Random类,可以使用ThreadLocalRandomless contentionbetter performance,好吧,这些都是官方的话,不是我说的。

CHAPTER 11:Odds and Ends:零碎、琐碎的事情,这个短语向大家推荐下。
好吧,这章介绍的都是一些比较琐碎的支持,如week、currency、Range等,这些修改大家知道就可以,如果能在工作中用到,那也是能简化不小的工作量,如果真是没有印象,也没有关系,大家相信对于这些内容都有自己的原生支持吧。
  1. Handling weeks in Java 7:好吧,这个week的功能改进太琐碎了,支持weekofYearcurrentWeekweek formatCST等,这个改进还真是Odds and Edds
  2. Using the Currency class in Java 7:货币支持,这个是好事,不过大家在财务上真的会用这个货币功能吗?精确度是关键。
  3. Using the NumericShaper.Range enumeration to support the display of digits:这个类是java.awt.font.NumericShaper.Range,这个类真心不了解;看了下,是根据语言的不同,来调整数字输出的,不知道我理解是否正确。
  4. JavaBean enhancements in Java 7:这个JavaBean颇有Reflection的感觉,看使用方法就能想象出来JavaBean的实现方法。
  5. Handling locales and the Locale.Builder class in Java 7:本地化,这个功能很使用,问题是,在线上这个本地化操作会影响性能吗?严重怀疑。
  6. Handling null references:这个例子重写了equals方法来判断obj是否为null,但是我们自己重写equals时不时也是这么 写的吗?后面的两种出来null的方法倒是不错。
  7. Using the new BitSet methods in Java 7BitSet新添了几个方法,valueOftoLongArraypreviousSetBitpreviousClearBit等,这个类用的不多,不过在某些地方还是有奇效的。


Java 7的更改细究起来还是有不少研究的地方的,只是不知道各位同学有没有在生产环境中用到Java 的新特性。
这里提供个链接,http://openjdk.java.net/projects/jdk7/features/是提供Java版本更新所支持的内容的,大家可以上去看看,看看Java 8会支持哪些内容,哪些又是你比较期待的呢。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics