• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is your favorite java 7 feature?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34870
369
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We've done favorites before, but it would be fun to do again since we have guest authors here.

Mine is autoclosing resources.

I learned while reading "Java 7 New Features Cookbook" that the JavaDocs are Section 508 compliant starting Java 7. (Section 508 is an accessibility standard.) I think this is really cool so wanted to mention it in this thread anyway.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mine is autoclosing resources.

+1 here as well.

But I also think the feature of not repeating the declaration for Generics on both the sides of the declaration reduces the verbosity to some extent. And even Autoclosing would help in reducing the amount of code written.

Then there's a new Concurrency related feature (Fork-Join) and I think even that might be useful, but I dont know how ;)
 
Stephan van Hulst
Bartender
Pie
Posts: 6128
74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definitely try-with-resources, and generic type inference.

try-with-resources makes I/O code *so* much nicer to read. And I just feel a little bit happy every time I don't have to type the generic type argument.

Catching disjoint exceptions is nice too, as well as grouping numbers with underscores, but I don't use these features that often.

Java 7 is just a really nice language ^^;
 
Campbell Ritchie
Sheriff
Pie
Posts: 49862
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about being able to write numbers in binary? A feature which was available in languages like Eiffel back in the 1980s.
 
Alexis Lopez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 Try with resources
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the try with resources feature gets a unanimous vote.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
switch(String) is quite useful too

Pat.
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is catching multiple exceptions (catch (IOException | SQLException e). I still vote for try-with-resources.
 
Jennifer Reese
author
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My personal favorite (and favorite recipe to write for our book) is the ability to manage the shape of a window in GUI applications, though I will admit this was more of a fun feature than something I have found particularly useful! From a more practical standpoint, I appreciate the simplicity of the Files class and Path interface for file I/O. Working with files and directories is greatly simplified in Java 7.
 
Richard Reese
author
Ranch Hand
Posts: 84
5
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like the new concurrent processing features added to Java 7. There are not extensive, but they did allow me to write about zombies.
 
Roel De Nijs
Sheriff
Posts: 10456
137
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My personal top-3:
1. try-with-resources
2. (generic) type inference
3. string in switch
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've written systems multiple times where there had to be some process that checks regularly if a file is placed in a directory, which should then be picked up to be processed. You could do that by having a scheduled task that every X seconds or so lists the files in the directory to see if anything has appeared.

Java 7 has a new feature where you can ask to be notified when something changes in a directory. See Watching a Directory for Changes. Instead of polling, it will use the native functionality of the operating system for file system change notifications, which is most likely much more efficient than polling.

So, that's one of the new features that seems really useful to me.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mine favorites are (from high to low priority)

1. try-with-resources (autoclose feature) - it takes boilerplate code of maintaining Streams/Connection out of scope for us
2. Diamond operator - makes code looks more better now
3. String in switch - aren't we missing this feature in Java since long ?

~ abhay

 
Jan Cumps
Bartender
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:...Java 7 has a new feature where you can ask to be notified when something changes in a directory.


That one!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic