This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Features new in Java 7 and the fly likes what is your favorite java 7 feature? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "what is your favorite java 7 feature?" Watch "what is your favorite java 7 feature?" New topic

what is your favorite java 7 feature?

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3152

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 ;)

Mohamed Sanaulla | My Blog
Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4642

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 ^^;

The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46424
What about being able to write numbers in binary? A feature which was available in languages like Eiffel back in the 1980s.
Alexis Lopez

Joined: Dec 11, 2010
Posts: 7
+1 Try with resources
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10033

I guess the try with resources feature gets a unanimous vote.

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

switch(String) is quite useful too

Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

So is catching multiple exceptions (catch (IOException | SQLException e). I still vote for try-with-resources.

How To Ask Questions How To Answer Questions
Jennifer Reese

Joined: Mar 08, 2012
Posts: 8
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
Ranch Hand

Joined: Jul 13, 2011
Posts: 84

I like the new concurrent processing features added to Java 7. There are not extensive, but they did allow me to write about zombies.

Richard Reese
Java 8 New Features: A Practical Heads-Up Guide
Roel De Nijs

Joined: Jul 19, 2004
Posts: 8412

My personal top-3:
1. try-with-resources
2. (generic) type inference
3. string in switch

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15100

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1341

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

Oracle certified Java 8 Programmer I (1Z0-808), Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

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!

OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: what is your favorite java 7 feature?
It's not a secret anymore!