jdk7和8的一些新特性介绍ITeye - 凯时娱乐

jdk7和8的一些新特性介绍ITeye

2019年02月18日08时50分30秒 | 作者: 鸿才 | 标签: 类型,特性,二进制 | 浏览: 2296

更多ppt内容请检查:http://www.javaarch.net/jiagoushi/927.htm

 

本文是我学习了解了jdk7和jdk8的一些新特性的一些材料,有爱好的我们能够阅读下下面的内容。
官方文档:http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html
在jdk7的新特性方面主要有下面几方面的增强:
1.jdk7语法上
 1.1二进制变量的表明,支撑将整数类型用二进制来表明,用0b最初。
 // 一切整数 int, short,long,byte都能够用二进制表明
 // An 8-bit byte value:
 byte aByte = (byte) 0b00100001;
 // A 16-bit short value:
 short aShort = (short) 0b1010000101000101;
 // Some 32-bit int values:
 intanInt1 = 0b10100001010001011010000101000101;
 intanInt2 = 0b101;
 intanInt3 = 0B101; // The B can be upper or lower case.
 // A 64-bit long value. Note the "L" suffix:
 long aLong = 0b1010000101000101101000010100010110100001010001011010000101000101L;
 // 二进制在数组等的运用
 final int[] phases = { 0b00110001, 0b01100010, 0b11000100, 0b10001001,
 0b00010011, 0b00100110, 0b01001100, 0b10011000 };
1.2 Switch句子支撑string类型 
 public static String getTypeOfDayWithSwitchStatement(String dayOfWeekArg) {
 String typeOfDay;
 switch (dayOfWeekArg) {
 case "Monday":
 typeOfDay = "Start of work week";
 break;
 case "Tuesday":
 case "Wednesday":
 case "Thursday":
 typeOfDay = "Midweek";
 break;
 case "Friday":
 typeOfDay = "End of work week";
 break;
 case "Saturday":
 case "Sunday":
 typeOfDay = "Weekend";
 break;
 default:
 throw new IllegalArgumentException("Invalid day of the week: " + dayOfWeekArg);
 return typeOfDay;
1.3 Try-with-resource句子 
 留意:完成java.lang.AutoCloseable接口的资源都能够放到try中,跟final里边的封闭资源相似; 依照声明逆序封闭资源 ;Try块抛出的反常经过Throwable.getSuppressed获取 
 try (java.util.zip.ZipFile zf = new java.util.zip.ZipFile(zipFileName);
 java.io.BufferedWriter writer = java.nio.file.Files 
 .newBufferedWriter(outputFilePath, charset)) {
 // Enumerate each entry
 for (java.util.Enumeration entries = zf.entries(); entries
 .hasMoreElements();) {
 // Get the entry name and write it to the output file
 String newLine = System.getProperty("line.separator");
 String zipEntryName = ((java.util.zip.ZipEntry) entries
 .nextElement()).getName() + newLine;
 writer.write(zipEntryName, 0, zipEntryName.length());
1.4 Catch多个反常 阐明:Catch反常类型为final; 生成Bytecode 会比多个catch小; Rethrow时坚持反常类型 
 public static void main(String[] args) throws Exception {
 try {
 testthrows();
 } catch (IOException | SQLException ex) {
 throw ex;
 public static void testthrows() throws IOException, SQLException {
1.5 数字类型的下划线表明 更友爱的表明方法,不过要留意下划线增加的一些规范,能够参阅下面的示例
 long creditCardNumber = 1234_5678_9012_3456L;
 long socialSecurityNumber = 999_99_9999L;
 float pi = 3.14_15F;
 long hexBytes = 0xFF_EC_DE_5E;
 long hexWords = 0xCAFE_BABE;
 long maxLong = 0x7fff_ffff_ffff_ffffL;
 byte nybbles = 0b0010_0101;
 long bytes = 0b11010010_01101001_10010100_10010010; 
 //float pi1 = 3_.1415F; // Invalid; cannot put underscores adjacent to a decimal point
 //float pi2 = 3._1415F; // Invalid; cannot put underscores adjacent to a decimal point
 //long socialSecurityNumber1= 999_99_9999_L; // Invalid; cannot put underscores prior to an L suffix 
 //int x1 = _52; // This is an identifier, not a numeric literal
 int x2 = 5_2; // OK (decimal literal)
 //int x3 = 52_; // Invalid; cannot put underscores at the end of a literal
 int x4 = 5_______2; // OK (decimal literal) 
 //int x5 = 0_x52; // Invalid; cannot put underscores in the 0x radix prefix
 //int x6 = 0x_52; // Invalid; cannot put underscores at the beginning of a number
 int x7 = 0x5_2; // OK (hexadecimal literal)
 //int x8 = 0x52_; // Invalid; cannot put underscores at the end of a number 
 int x9 = 0_52; // OK (octal literal)
 int x10 = 05_2; // OK (octal literal)
 //int x11 = 052_; // Invalid; cannot put underscores at the end of a number 
 1.6 泛型实例的创立能够经过类型揣度来简化 能够去掉后边new部分的泛型类型,只用 就能够了。
 //运用泛型前 
 List strList = new ArrayList(); 
 List String strList4 = new ArrayList String 
 List Map String, List String strList5 = new ArrayList Map String, List String                          
			
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表凯时娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章

阅读排行

  • 1

    jdk7和8的一些新特性介绍ITeye

    类型,特性,二进制
  • 2
  • 3

    JS根底加强凯时娱乐

    目标,函数,声明
  • 4
  • 5

    第八章 装修形式环球

    形式,组件,结构
  • 6

    CreateThread()、mingxing

    线程,函数,运转
  • 7

    js 目标过错itjob

    目标,网站,上线
  • 8
  • 9
  • 10

    dom4j比如alibaba

    节点,特点,示例