Features of each version of Java JDK

1. Important features of versions before Java 8

        There are some important features and improvements in versions prior to Java 8. Here are some of the main features and their release versions:

Java SE 7 (released in 2011):

  • Switch strings: Allows the use of strings in switch statements.
  • Generic type inference: allows the generic parameter type to be instantiated without repeatedly specifying the generic parameter type.
  • Improved exception handling: multiple exception capture methods are introduced, providing a more flexible exception handling method.
  • try-with-resources statement: simplifies the opening and closing operations of resources (such as files, database connections, etc.).

Java SE 6 (released in 2006):

  • Scripting language support: Integration with dynamic languages ​​such as JavaScript and Groovy via JSR 223.
  • JAXB (Java Architecture for XML Binding): Provides a way to bind and parse XML data through annotations.
  • Collection framework enhancements: including new collection types (such as Deque and NavigableSet), collection classes that support concurrent access, etc.

Java SE 5 (released in 2004):

  • Generic types: Generics were introduced, making it possible to use type parameters at the class, interface, and method levels.
  • Enhanced for loop: Simplified collection and array traversal operations.
  • Autoboxing and unboxing: Allows automatic conversion between base types and corresponding packaging types.
  • Variadics: Allows the definition of methods that can accept a variable number of arguments.
  • Enumeration types: Enumeration types were introduced to enable the definition of a limited set of named constants.

2. New features of Java 8

 The following is an overview of some of the features of Java JDK 8 major releases:

  • Lambda expressions and functional interfaces
  • Stream API performs data stream operations
  • Default method (interface methods can have default implementations)
  • New date and time API (java.time package)

 3. New features of Java 11

         Since Java 10, the key feature of Local Variable Type Inference has been introduced. Type inference allows the keyword var to be used as the type of a local variable instead of the actual type, and the compiler infers the type from the value assigned to the variable. This improvement simplifies code writing and saves developers time, because it is no longer necessary to explicitly declare the type of local variables. Instead, the keyword var can be used without overcomplicating the source code.

Local variables can be declared using the keyword var as follows:

var s = "Hello Java 11";
System.out.println(s);

But in Java 10, there are several limitations:

  • Can only be used on local variables
  • Must be initialized when declared
  • Cannot be used as method parameter
  • Cannot be used in Lambda expressions

        Java 11 differs from Java 10 by allowing developers to use var for parameter declarations in Lambda expressions. At first glance, this may seem a bit redundant, since you can omit the types of the Lambda parameters during coding and determine them through type inference. However, it is still useful to add type definitions and use type annotations such as @Nonnull and @Nullable, so as to maintain consistent writing with local variables without losing code simplicity.

  • New string methods: The String class has added some practical methods, such as isBlank()checking whether the string is empty or contains only spaces, strip()removing spaces at the beginning and end of the string, lines()splitting the string into lines, etc.
  1. isBlank(): used to check whether the string is empty or contains only space characters.

    Example: String str = " "; if (str.isBlank()) { // 执行逻辑 }
  2. strip(): Removes space characters from the beginning and end of the string.

    Example: String str = " Hello World "; String trimmed = str.strip(); // 返回 "Hello World"
  3. lines(): Split the string into Stream<String> objects by lines.

    Example: String str = "Hello\nWorld\nJava"; Stream<String> lines = str.lines(); lines.forEach(System.out::println); // 输出每行的内容
  • Standardized HTTP client based on HTTP/2: Java 11 introduces a new standard HTTP client API that supports the HTTP/2 protocol, asynchronous and reactive operations.

reference:

Online documentation-jdk-zh (oschina.net)

Online Tools - ioDraw (matools.com)

Java 11 Chinese version - Online API Manual - Coding Tools (matools.com)

Guess you like

Origin blog.csdn.net/weixin_49171365/article/details/129016343