New features in java 7

前端 未结 8 939
再見小時候
再見小時候 2020-12-02 04:14

What new features in java 7 is going to be implemented? And what are they doing now?

相关标签:
8条回答
  • 2020-12-02 04:43

    In addition to what John Skeet said, here's an overview of the Java 7 project. It includes a list and description of the features.

    Note: JDK 7 was released on July 28, 2011, so you should now go to the official java SE site.

    0 讨论(0)
  • 2020-12-02 04:53

    Using Diamond(<>) operator for generic instance creation

    Map<String, List<Trade>> trades = new TreeMap <> ();
    

    Using strings in switch statements

    String status=  “something”;
       switch(statue){
         case1: 
         case2: 
         default:
        }
    

    Underscore in numeric literals

    int val 12_15; long phoneNo = 01917_999_720L;

    Using single catch statement for throwing multiple exception by using “|” operator

    catch(IOException | NullPointerException ex){
              ex.printStackTrace();   
        }
    

    No need to close() resources because Java 7 provides try-with-resources statement

    try(FileOutputStream fos = new FileOutputStream("movies.txt");
          DataOutputStream dos = new DataOutputStream(fos)) {
                  dos.writeUTF("Java 7 Block Buster");
      } catch(IOException e) {
            // log the exception
      }
    

    binary literals with prefix “0b” or “0B”

    0 讨论(0)
  • 2020-12-02 04:58

    Java Programming Language Enhancements @ Java7

    1. Binary Literals
    2. Strings in switch Statement
    3. Try with Resources or ARM (Automatic Resource Management)
    4. Multiple Exception Handling
    5. Suppressed Exceptions
    6. underscore in literals
    7. Type Inference for Generic Instance Creation using Diamond Syntax
    8. Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods

    Official reference
    Official reference with java8
    wiki reference

    0 讨论(0)
  • 2020-12-02 04:59

    New Feature of Java Standard Edition (JSE 7)

    1. Decorate Components with the JLayer Class:

      The JLayer class is a flexible and powerful decorator for Swing components. The JLayer class in Java SE 7 is similar in spirit to the JxLayer project project at java.net. The JLayer class was initially based on the JXLayer project, but its API evolved separately.

    2. Strings in switch Statement:

      In the JDK 7 , we can use a String object in the expression of a switch statement. The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.

    3. Type Inference for Generic Instance:

      We 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. Java SE 7 supports limited type inference for generic instance creation; you can only use type inference if the parameterized type of the constructor is obvious from the context. For example, the following example does not compile:

      List<String> l = new ArrayList<>();
      l.add("A");
      l.addAll(new ArrayList<>());
      

      In comparison, the following example compiles:

      List<? extends String> list2 = new ArrayList<>();
      l.addAll(list2);
      
    4. Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking:

      In Java SE 7 and later, a single catch block can handle more than one type of exception. This feature can reduce code duplication. Consider the following code, which contains duplicate code in each of the catch blocks:

      catch (IOException e) {
          logger.log(e);
          throw e;
      }
      catch (SQLException e) {
          logger.log(e);
          throw e;
      }
      

      In releases prior to Java SE 7, it is difficult to create a common method to eliminate the duplicated code because the variable e has different types. The following example, which is valid in Java SE 7 and later, eliminates the duplicated code:

      catch (IOException|SQLException e) {
          logger.log(e);
          throw e;
      }
      

      The catch clause specifies the types of exceptions that the block can handle, and each exception type is separated with a vertical bar (|).

    5. The java.nio.file package

      The java.nio.file package and its related package, java.nio.file.attribute, provide comprehensive support for file I/O and for accessing the file system. A zip file system provider is also available in JDK 7.

    Source: http://ohmjavaclasses.blogspot.com/

    0 讨论(0)
  • 2020-12-02 05:07

    The following list contains links to the the enhancements pages in the Java SE 7.

    Swing
    IO and New IO
    Networking
    Security
    Concurrency Utilities
    Rich Internet Applications (RIA)/Deployment
        Requesting and Customizing Applet Decoration in Dragg able Applets
        Embedding JNLP File in Applet Tag
        Deploying without Codebase
        Handling Applet Initialization Status with Event Handlers
    Java 2D
    Java XML – JAXP, JAXB, and JAX-WS
    Internationalization
    java.lang Package
        Multithreaded Custom Class Loaders in Java SE 7
    Java Programming Language
        Binary Literals
        Strings in switch Statements
        The try-with-resources Statement
        Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking
        Underscores in Numeric Literals
        Type Inference for Generic Instance Creation
        Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods
    Java Virtual Machine (JVM)
        Java Virtual Machine Support for Non-Java Languages
        Garbage-First Collector
        Java HotSpot Virtual Machine Performance Enhancements
    JDBC
    

    Reference 1 Reference 2

    0 讨论(0)
  • 2020-12-02 05:08

    I think ForkJoinPool and related enhancement to Executor Framework is an important addition in Java 7.

    0 讨论(0)
提交回复
热议问题