Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Java 7 features  RSS feed

 
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
We have the codebase mainly using Java 1.5. We are planning to migrate to Java 7/8. Some of the features of Java 7, i am planning to use
1)Auto close resources.
2)Catching multiple exceptions in one catch block.
3)Using String Switch where we are using dozens of if else for String comparisons.

These features definitely improve the readability but do they add any value beyond that ? Performance or any other advantage? Or any other feature you can think of adding ?(Java 8 has lambdas but as of now not adding this feature!)
 
Saloon Keeper
Posts: 9132
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using try-with-resources on AutoCloseables will not just improve readability of the code, but it will make your code more robust as well.

Catching disjoint exception types avoids code duplication, which makes your code easier to maintain.

I'm not a fan of switch statements in general. I prefer to map strings to objects that can perform different tasks through polymorphism. For instance, instead of:

You can do:

Another cool language enhancement you can use with Java 7 is the diamond operator. When initializing a variable of a generic type, you don't have to repeat the generic type arguments in the constructor call:
 
Java Cowboy
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a lot more new features in Java 7 besides the three new language features that you mentioned. Not just new language features, but a lot of enhancements to the standard library. Every new major Java version also comes with performance updates, including, for example, new and better garbage collection algorithms.

See this page from Oracle: Java SE 7 Features and Enhancements.

I would upgrade straight to Java 8, even if you are not yet planning to use the new Java 8 language features such as lambda expressions, because Java 7 is also already obsolete: Oracle does not provide any free and public updates (bugfixes and security updates) anymore since April 2015. See: Oracle Java SE Support Roadmap.
 
Arjun Shastry
Ranch Hand
Posts: 1907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Yes, we are planning to upgrade to Java 8 but some how may not use Lambda etc immediately.
 
Marshal
Posts: 59742
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper is right: go straight for Java8.

But I am going to throw in a dissenting voice.

If it ain't broke, don't fix it.

Why do you need to change code which is already working correctly, at least until it is time to upgrade it?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!