【JAVA系列】Java8、Java7、Java5新特性

从Java8到Java21各版本新特性详解 上面这张图是 Oracle 官方给出的 Oracle JDK 支持的时间线,可以看出,JDK 17的支持时间最长,可以延续到2029年9月。考虑到技术更新的速度,这次免费商用8年的时间可谓是经过精心考虑,旨在让用户放心地升级到JDK 17(不过JDK 8的支持时间更长,可以延续到2030年12月)。从JDK诞生到现在,仅有几个版本得到了长期支持,主要包括JDK 7、JDK 8、JDK 11以及即将发布的JDK 17,它将是继Java 8之后最重要的LTS版本,是Java社区八年努力的成果。 阅读详情

Java Programming Language Enhancements

Enhancements in Java SE 8

  • Lambda Expressions enable you to encapsulate a single unit of behavior and pass it to other code. You can use a lambda expressions if you want a certain action performed on each element of a collection, when a process is completed, or when a process encounters an error. Lambda expressions are supported by the following features:

    • Method References are compact, easy-to-read lambda expressions for methods that already have a name.

    • Default Methods enable you to add new functionality to the interfaces of your libraries and ensure binary compatibility with code written for older versions of those interfaces. They are interface methods that have an implementation and the default keyword at the beginning of the method signature. In addition, you can define static methods in interfaces.

    • New and Enhanced APIs That Take Advantage of Lambda Expressions and Streams in Java SE 8 describe new and enhanced classes that take advantage of lambda expressions and streams.

  • Improved Type Inference - The Java compiler takes advantage of target typing to infer the type parameters of a generic method invocation. The target type of an expression is the data type that the Java compiler expects depending on where the expression appears. For example, you can use an assignment statement’s target type for type inference in Java SE 7. However, in Java SE 8, you can use the target type for type inference in more contexts. The most prominent example is using a method invocation’s target types to infer the data types of its arguments.

    Consider the following example:

    List<String> stringList = new ArrayList<>();
    stringList.add("A");
    stringList.addAll(Arrays.asList());
    

    Disregarding generics for the moment, the method addAll expects a Collection instance as its argument, and the method Arrays.asList returns a List instance. This works because List is a subtype of Collection.

    Now considering generics, the target type of addAll is Collection<? extends String>, and Arrays.asList returns a List instance. In this example, the Java SE 8 compiler can infer that the value of the type variable T is String. The compiler infers this from the target type Collection<? extends String>.

    Compilers from Java SE 7 and earlier do not accept this code because they do not use target typing to infer types for method call arguments. For example, the Java SE 7 compiler generates an error message similar to the following:

    error: no suitable method found for addAll(List<Object>) ...
    method List.addAll(Collection<? extends String>) is not applicable (actual argument List<Object> cannot be converted to Collection<? extends String> by method invocation conversion)
    

    Consequently, in situations like this where the Java compiler cannot infer types, you must explicitly specify values for type variables with type witnesses. For example, the following works in Java SE 7:

    List<String> stringList = new ArrayList<>();
    stringList.add("A");
    stringList.addAll(Arrays.<String>asList());
    

    See the following sections in the Java Tutorials for more information:

    • Target Typing in Lambda Expressions

    • Type Inference

  • Annotations on Java Types - It is now possible to apply an annotation anywhere a type is used. Used in conjunction with a pluggable type system, this allows for stronger type checking of your code. For more information, see Type Annotations and Pluggable Type Systems in the new Annotations lesson in the Java Tutorial.

  • Repeating Annotations - It is now possible to apply the same annotation type more than once to the same declaration or type use. For more information, see Repeating Annotations in the new Annotations lesson in the Java Tutorial.

  • Method Parameter Reflection - You can obtain the names of the formal parameters of any method or constructor with the method java.lang.reflect.Executable.getParameters. (The classes Method and Constructor extend the class Executable and therefore inherit the method Executable.getParameters.) However, .class files do not store formal parameter names by default. To store formal parameter names in a particular .class file, and thus enable the Reflection API to retrieve formal parameter names, compile the source file with the -parameters option of the javac compiler. See Obtaining Names of Method Parameters in the Java Tutorials.

Enhancements in Java SE 7

  • Binary Literals - In Java SE 7, the integral types (byte, short, int, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number.
  • Underscores in Numeric Literals - Any number of underscore characters (_) can appear anywhere between digits in a numerical literal. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code.
  • Strings in switch Statements - You can use the String class in the expression of a switch statement.
  • Type Inference for Generic Instance Creation - You can replace the type arguments required to invoke the constructor of a generic class with an empty set of type parameters (<>) as long as the compiler can infer the type arguments from the context. This pair of angle brackets is informally called the diamond.
  • Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods - The Java SE 7 complier generates a warning at the declaration site of a varargs method or constructor with a non-reifiable varargs formal parameter. Java SE 7 introduces the compiler option -Xlint:varargs and the annotations @SafeVarargs and @SuppressWarnings({“unchecked”, “varargs”}) to suppress these warnings.
  • The try-with-resources Statement - The try-with-resources statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements the new java.lang.AutoCloseable interface or the java.io.Closeable interface can be used as a resource. The classes java.io.InputStream, OutputStream, Reader, Writer, java.sql.Connection, Statement, and ResultSet have been retrofitted to implement the AutoCloseable interface and can all be used as resources in a try-with-resources statement.
  • Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking - A single catch block can handle more than one type of exception. In addition, the compiler performs more precise analysis of rethrown exceptions than earlier releases of Java SE. This enables you to specify more specific exception types in the throws clause of a method declaration.

Enhancements in Java SE 6

No language changes were introduced in Java SE 6.

Enhancements in Java SE 5.0

  • Generics - This long-awaited enhancement to the type system allows a type or method to operate on objects of various types while providing compile-time type safety. It adds compile-time type safety to the Collections Framework and eliminates the drudgery of casting. See the Generics lesson in the Java Tutorials. (JSR 14)
  • Enhanced for Loop - This new language construct eliminates the drudgery and error-proneness of iterators and index variables when iterating over collections and arrays. (JSR 201)
  • Autoboxing/Unboxing - This facility eliminates the drudgery of manual conversion between primitive types (such as int) and wrapper types (such as Integer). (JSR 201)
  • Typesafe Enums - This flexible object-oriented enumerated type facility allows you to create enumerated types with arbitrary methods and fields. It provides all the benefits of the Typesafe Enum pattern (“Effective Java,” Item 21) without the verbosity and the error-proneness. (JSR 201)
  • Varargs - This facility eliminates the need for manually boxing up argument lists into an array when invoking methods that accept variable-length argument lists.
  • Static Import - This facility lets you avoid qualifying static members with class names without the shortcomings of the “Constant Interface antipattern.” (JSR 201)
  • Annotations (Metadata) - This language feature lets you avoid writing boilerplate code under many circumstances by enabling tools to generate it from annotations in the source code. This leads to a “declarative” programming style where the programmer says what should be done and tools emit the code to do it. Also it eliminates the need for maintaining “side files” that must be kept up to date with changes in source files. Instead the information can be maintained in the source file. (JSR 175)
    NOTE: The @Deprecated annotation provides a way to deprecate program elements. See How and When To Deprecate APIs.

Generics papers

  • JSR14: Adding Generic Types to the Java Programming Language
    • Generics lesson in the Java Tutorials
    • Earlier public review draft specification from Java Community Process
  • Making the Future Safe for the Past: Adding Genericity to the Java Programming Language (PDF)
    Bracha, Odersky, Stoutamire, and Wadler. OOPSLA 98, Vancouver, October 1998. ( other formats)
  • GJ: Extending the Java Programming Language with Type Parameters (PDF)
    Bracha, Odersky, Stoutamire, and Wadler. A tutorial on GJ. August 1998. ( other formats)
  • Adding Generics to the Java Programming Language (PDF)
    Bracha. Slides from JavaOne 2003 presentation.
  • Adding Wildcards to the Java Programming Language (PDF)
    Torgersen, Hansen, Ernst, Ahe, Bracha and Gafter. An ACM paper, 2004.

Enhancements in J2SE 1.4

  • Assertion Facility - Assertions are boolean expressions that the programmer believes to be true concerning the state of a computer program. For example, after sorting a list, the programmer might assert that the list is in ascending order. Evaluating assertions at runtime to confirm their validity is one of the most powerful tools for improving code quality, as it quickly uncovers the programmer’s misconceptions concerning a program’s behavior.

参考

https://docs.oracle.com/javase/8/docs/technotes/guides/language/enhancements.html

https://docs.oracle.com/en/java/javase/index.html

Java7/8/9语法新特性 Java7/8/9语法新特性 Java7 Java7的新特性是相对于Java6而言的,增加的特性如下: 二进制变量的表示,支持将整数类型用二进制来表示,用0b开头。 // 所有整数 int, short,long,byte都可以用二进制表示 // An 8-bit 'byte' value: byte aByte = (byte) 0b0... 阅读详情

相关推荐

Java 8的新特性—终极版

Java 8的新特性—终极版Java 8的新特性—终极版Java 8的新特性—终极版

JDK7、8新特性

JDK7、8新特性

杨宇昌的博客 859

Android逆向实战:通过smali/baksmali动态注入DEX逻辑

本文详细介绍了在无源码条件下对Android应用进行动态逻辑注入的实战方法。通过使用smali和baksmali工具对DEX文件进行反编译、修改与重打包,实现在目标方法中插入自定义代码(如日志打印),并分享了定位目标、处理寄存器、避免常见错误的实用技巧与避坑指南。

weixin_29008691的博客 362

看了就明白!java5、java6、java7、java8、java9新特性

你可以用过简单的annotaion将你的API发布成.NET交互的web services. Mustang 添加了新的解析和 XML 在 Java object-mapping APIs中, 之前只在Java EE平台实现或者Java Web Services Pack中提供.引用泛型之后,允许指定集合里元素的类型,免去了强制类型转换,并且能在编译时刻进行类型检查的好处。Java中某些资源是需要手动关闭的,如InputStream,Writes,Sockets,Sql classes等。

m0_64363449的博客 1046

从‘全步’到‘微步’:一张图看懂步进电机细分控制,选对模式让你的项目更丝滑

本文深入解析步进电机细分控制技术,从全步到微步的演进过程,帮助工程师根据项目需求选择最优控制模式。通过对比不同细分等级的性能特点和应用场景,提供3D打印、实验室自动化等领域的黄金配置方案,实现更精准、平稳的电机控制效果。

weixin_29290259的博客 470

GCC调试黑科技:-fomit-frame-pointer优化下如何保证栈回溯能力

本文深入探讨了GCC编译器在启用`-fomit-frame-pointer`优化选项时如何保证栈回溯能力。通过分析`.eh_frame`段的结构与DWARF调试信息,提供了从编译选项配置到实战调试的完整解决方案,帮助开发者在性能优化与调试能力之间找到最佳平衡点。

u6v7w8x的博客 904

Java 7和Java 8常用的新特性

本文主要总结JDK 8、JDK7的特性和增强功能

每天就学一点点的博客 1363

ES快速入门,一篇就懂!

Elastic Search 入门前言什么是搜索为什么常用数据库不适合做搜索什么是Lucene什么是Elastic SearchES核心概念ES使用正常启动索引​增删改查ES增加常见问题:ES删除ES查询欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的

qq1592的博客 9310

Java 7、Java 8常用新特性

Lambda 表达式经常与函数式接口一起使用。定义一个无实现类的接口,接口方法有且只有一个。//或myService.myMethod("这是一个自定义的函数式接口");/\* 等价写法 \*/@OverridemyService.myMethod("这是一个字符串");

2401_84009626的博客 1238

23、工业物流中的多智能体路径规划与碰撞处理策略

本文探讨了工业4.0背景下工业物流中的多智能体路径规划(MAPF)与碰撞处理策略。分析了自动导引车(AGV)等移动资源的应用现状,综述了主流路径规划算法如A*、D*Lite、M*等,以及集中式与分布式碰撞检测方法。重点比较了五种碰撞避免策略:路径交叉、优先级、起始时间调整、无交叉路径和速度调整,提出了基于环境条件的策略选择流程,并通过流程图展示了评估、组合、测试与优化的全过程。文章强调应根据订单不确定性、时间约束、优先级和生产组织等因素综合选择或组合策略,以提升物流效率与系统可靠性。

mac99的博客 125

华为OD机试真题 新系统 2026-04-19 Java&Go 实现【分辨率排序】

华为OD机试真题 新系统 2026-04-19 Python&JS 实现【分辨率排序】

MISAYAONE的博客 302

Java8新特性学习总结篇

​ 文章目录Lambda 表达式从匿名类到Lambda表达式的转换语法格式一:无参,无返回值,Lambda体只需要一条语句语法格式二:Lambda需要一个参数语法格式三:Lambda只需要一个参数时,参数的小括号可以省略语法格式四:Lambda需要两个参数,并且有返回值语法格式五:Lambda体只有一条语句,return和大括号后可以省略语法格式六:类型推断 类型可省略函数式接口自定义函数式接口函...

D_A_I_H_A_O的博客 722

Python爬虫实战:逆向工程与异步处理攻克Pinterest无限滚动瀑布流

我们将从零开始,逐步分析其数据接口,构建一个功能完整的爬虫,并深入探讨反爬虫策略的应对、性能优化以及数据存储等高级主题。: 在实际爬取中,你需要先访问一次Pinterest主页,获取初始的Cookie和CSRF Token,然后再发起API请求。: Python爬虫,Pinterest,无限滚动,瀑布流,异步IO,httpx,逆向工程,API接口,动态内容,反爬虫。你会很快发现一些关键的请求模式。:页面初始加载有限内容,随着用户滚动,新的图片块通过AJAX动态加载,实现“永无止境”的浏览。

2201_76125261的博客 551

java5、java6、java7、java8的新特性

Java5: 1、泛型 Generics:         引用泛型之后,允许指定集合里元素的类型,免去了强制类型转换,并且能在编译时刻进行类型检查的好处。         Parameterized Type作为参数和返回值,Generic是vararg、annotation、enumeration、collection的基石。         A、类型安全    

samjustin的博客 2万+

Android 13 wificond讲解

Android 13 wificond讲解

专业开发者的博客,一个从事Android WiFi和蓝牙的工程师 2932

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Java8新特性

HashMap jdk1.7:数组+链表 jdk1.8:数组+链表+红黑树 当哈希碰撞即链表上个数大于8并且总容量个数大于64,链表转成红黑树 红黑树除了添加以外,其他(查询、删除)效率都比链表高 扩容后重排序,不用重新运算hashCode值,直接找对应元素在原来哈希表的总长度加上它当前所在哈希表的位置 HashSet,同理 ConcurrentHashMap jdk1.7 并发级别:16 锁+段机制:默认16段,每段默认16表 段太多浪费空间,段太少导致每段元素过多效率遍地 jdk1.8 CAS 无锁算法

minge0001的博客 3万+

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

java5、java6、java7、java8、java9新特性

1. 介绍 JAVA作为使用的主力语言,掌握下其历史发展也是有必要的。看看从JAVA5开始到现在的JAVA9有哪些变化。借此机会,也可以看看哪些特性我们是已经用到的,哪些是还没有用到的。 我们在IDEA里面也可以看到language level里面的信息,这里也大致写了下各个版本JDK的新特性。 简单概括下就是: JAVA1.3:普通的原始的JAVA,基本语法相信大家都见过了 JAVA1.4:assert关键字 JAVA5:枚举类型、泛型、自动拆装箱 JAVA6: @Overrid

sunyanchun的专栏 2142

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

java7或java8新特性

1、jdk7,数值类型字面值可以用‘多个‘—’分隔增加可读性 int a = 123_456; double b = 123_456e3; 2、jdk7,可以使用字符串控制switch语句 String str = &amp;amp;quot;abc&amp;amp;quot;; switch (str){ case &amp;amp;quot;abc&amp;amp;quot;:

zhaojianting的博客 1万+

Java7、Java8新特性了解

转自 Java EE 7 三大新特性的介绍,Java 8 新特性概述

xuanjiewu的专栏 1万+

Java5-Java8新特性,这回全了

Java5:泛型 Generics 引用泛型之后,允许指定集合里元素的类型,免去了强制类型转换,并且能在编译时刻进行类型检查的好处。Parameterized Type作为参数和返回值,Generic是vararg、annotation、enumeration、collection的基石。

石竹的专栏 3360

java 8新特性

Java 8 概述 Java 8 是 Java 语言历史上一个非常重要的版本,它引入了多项新特性,大大提高了 Java 语言的现代化程度和生产力。以下是 Java 8 的一些主要新特性介绍。

qq_35932990的博客 4423

Java 8新特性-教程

Java 8新特性-教程Java8新特性1. 引入1.1 常规求值1.2 使用接口1.3 使用匿名类1.4 使用Lambda表达式2. Lambda表达式2.1 Lambda表达式组成2.2 函数式接口2.3 如何使用Lambda表达式2.4 类型推断2.5 引用外部变量2.6 默认函数式接口3. 默认方法和静态方法3.1 什么是默认方法3.2 为什么要使用默认方法3.3 默认方法的优先级3.4 ...

qq122516902的博客 4654

Java 8 新特性

Java 8 新特性

YIYIYI 1573

学习札记-Java8系列-1-Java8新特性简介&为什么要学习Java8

Oracle 公司于 2014 年 3 月 18 日发布 Java 8 ,距离现在已经有很长一段时间了,Java10也在2018年 3月 21日正式发布,并且Oracle宣布Java 语言将每隔 6 个月提供一次更新。Java语言不断更新迭代,然而很多Java程序员缺没有跟上技术更新的步伐!所以写下这篇系列文章,希望可以帮助大家入门Java8!话不多说,开始发车!

pingguocu3的博客 972

【java学习】java5 6 7 8 9 10新特性

1,java5新特性(Tiger,2004年) 1)自动装箱、拆箱 2)静态导入(static import) 可以直接导入到方法的级别。 注意: 方法必须是静态的 如果有多个同名的静态方法,容易不知道使用谁?这个时候要使用,必须加前缀。由此可见,意义不大,所以一般不用,但是要能看懂。 使用: import static java.lang.Math.max; //静态导入 // Sys...

午后阳光 645
上一篇: 【开发技巧】调教Win10自带的微软拼音输入法的快捷键
下一篇: 【JdbcTemplate】为什么使用JdbcTemplate的这些API必须要加try catch?
tanpenggood
博客等级 码龄9年 129粉丝 197原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值