New features in java 7
What new features in java 7 is going to be implemented? And what are they doing now?
Asked by: Aston132 | Posted: 28-01-2022
Answer 1
Java SE 7 Features and Enhancements from JDK 7 Release Notes
This is the Java 7 new features summary from the OpenJDK 7 features page:
vm JSR 292: Support for dynamically-typed languages (InvokeDynamic) Strict class-file checking lang JSR 334: Small language enhancements (Project Coin) core Upgrade class-loader architecture Method to close a URLClassLoader Concurrency and collections updates (jsr166y) i18n Unicode 6.0 Locale enhancement Separate user locale and user-interface locale ionet JSR 203: More new I/O APIs for the Java platform (NIO.2) NIO.2 filesystem provider for zip/jar archives SCTP (Stream Control Transmission Protocol) SDP (Sockets Direct Protocol) Use the Windows Vista IPv6 stack TLS 1.2 sec Elliptic-curve cryptography (ECC) jdbc JDBC 4.1 client XRender pipeline for Java 2D Create new platform APIs for 6u10 graphics features Nimbus look-and-feel for Swing Swing JLayer component Gervill sound synthesizer [NEW] web Update the XML stack mgmt Enhanced MBeans [UPDATED]
Code examples for new features in Java 1.7
Try-with-resources statement
this:
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
becomes:
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
You can declare more than one resource to close:
try (
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest))
{
// code
}
Underscores in numeric literals
int one_million = 1_000_000;
Strings in switch
String s = ...
switch(s) {
case "quux":
processQuux(s);
// fall-through
case "foo":
case "bar":
processFooOrBar(s);
break;
case "baz":
processBaz(s);
// fall-through
default:
processDefault(s);
break;
}
Binary literals
int binary = 0b1001_1001;
Improved Type Inference for Generic Instance Creation
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
becomes:
Map<String, List<String>> anagrams = new HashMap<>();
Multiple exception catching
this:
} catch (FirstException ex) {
logger.error(ex);
throw ex;
} catch (SecondException ex) {
logger.error(ex);
throw ex;
}
becomes:
} catch (FirstException | SecondException ex) {
logger.error(ex);
throw ex;
}
SafeVarargs
this:
@SuppressWarnings({"unchecked", "varargs"})
public static void printAll(List<String>... lists){
for(List<String> list : lists){
System.out.println(list);
}
}
becomes:
@SafeVarargs
public static void printAll(List<String>... lists){
for(List<String> list : lists){
System.out.println(list);
}
}
Answered by: Chloe372 | Posted: 01-03-2022
Answer 2
New Feature of Java Standard Edition (JSE 7)
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.
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.
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);
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 (|).
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/
Answered by: Walter319 | Posted: 01-03-2022Answer 3
Java Programming Language Enhancements @ Java7
- Binary Literals
- Strings in switch Statement
- Try with Resources (How it works) or ARM (Automatic Resource Management)
- Multiple Exception Handling
- Suppressed Exceptions
- underscore in literals
- Type Inference for Generic Instance Creation using Diamond Syntax
- Improved Compiler Warnings and Errors When Using Non-Reifiable Formal Parameters with Varargs Methods
Official reference
Official reference with java8
wiki reference
Answer 4
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.
Answered by: Adrian802 | Posted: 01-03-2022Answer 5
Language changes:
-Project Coin (small changes)
-switch on Strings
-try-with-resources
-diamond operator
Library changes:
-new abstracted file-system API (NIO.2) (with support for virtual filesystems)
-improved concurrency libraries
-elliptic curve encryption
-more incremental upgrades
Platform changes:
-support for dynamic languages
Below is the link explaining the newly added features of JAVA 7 , the explanation is crystal clear with the possible small examples for each features :
http://radar.oreilly.com/2011/09/java7-features.html
Answered by: Sawyer611 | Posted: 01-03-2022Answer 6
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
}
Answered by: Alissa117 | Posted: 01-03-2022binary literals with prefix “0b†or “0Bâ€
Answer 7
I think ForkJoinPool and related enhancement to Executor Framework is an important addition in Java 7.
Answered by: Sarah248 | Posted: 01-03-2022Answer 8
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
Answered by: Melanie114 | Posted: 01-03-2022
Similar questions
java - How do I design a sub class with features not available in the base class?
For example suppose I have a class Vehicle and I wish for a subclass ConvertibleVehicle which has extra methods such as foldRoof(), turboMode(), foldFrontSeats() etc. I wish to instantiate as follows
Vehicle convertible = new ConvertibleVehicle()
so I still have access to common method such as openDoor(), startEngine() etc. How do I designed such a solution?
To clarify my two in...
java - What are the new features in Eclipse Galileo?
I couldn't find any description of this on the site.
What are some of the new features/improvements/changes in Eclipse Galileo from its previous version? Particularly for Java programming.
java - How to import a Maven project to Eclipse Mylyn with WTP features enabled?
I cannot import a maven project with WTP features enabled.
I have already tried:
mvn -Dwtpversion=R7 eclipse:eclipse
When I did the import, the WTP features are not enabled.
How do I import with the features enabled?
what are the OOP features which are not in java but c++ has those features?
Respected Sir!
As i have not learnt java yet but most people say that C++ has more OOP features than Java, I would like to know that what are the features that c++ has and java doesn't. Please explain.
Where can I find the Java features list
This may be super easy to solve but I can't find the correct "google search term" and I've got tons of pages and none with the answer I'm looking for.
Does anyone knows or has a list of the available features of java as a language?
For instance.
Define classes:
class Employee {
}
Define attributes
private String name;
If Swing has more features to design a form. Then what is the use of AWT in java?
In java, Swing has more features than the AWT components.
For example,
In AWT,
TextArea ta;
Button btn;
But its same in Swing as,
JTextArea ta;
JButton btn;
But swing component has good in look.
Then what's the need of AWT. Is there any useful feature?
Do Java or C++ lack any OO features?
I am interested in understanding object-oriented programming in a more academic and abstract way than I currently do, and want to know if there are any object-oriented concepts Java and C++ fail to implement.
I realise neither of the languages are "pure" OO, but I am interested in what (if anything) they lack, not what they have extra.
java - Hidden Features IntelliJ IDEA
java - Playing around with Eclipse features - Project files are now hidden?
I don't even remember how, but somehow I managed to make all of my project's source files hidden in Eclipse's Package and Project Explorer panels. Go figure.
'Show Filtered Children (alt+click)' temporarily reveals the files, and only in Package Explorer can I double-click to reopen them from this view. They go back into hiding after I select another item, though. Plus, now I'm getting other annoyances, such as ...
java - Similar features of LINQ
Closed. This question needs to be more focused. It ...
Still can't find your answer? Check out these amazing Java communities for help...
Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)