Technology Blog





Saturday, April 5, 2014

What is new in Java 7? New useful features

Java 7 is everywhere now and your boss maybe thinking to migrate too. So if you are still coding old way, it's useful to sneak peek the features.

Java has been constantly growing so much bigger that I cannot fathom all that is added to it.
Let me sum up the ones I found useful in my daily use. Consider this an introduction to Java 7 and we’ll be rolling out more detailed posts on each topic eventually.

String in switch case:

Let me start with a favourite,
With java 7, we can use string in switch case!
switch(str){ //str of type String
  case "abc": //do something
  case "efg": //do other thing

Multiple Exception Handling:
No need to copy paste many catch expressions. We can bundle related exceptions in a single catch.
get_A_Coffee (); //do someting;
catch(NotTastyException, NotHotEnoughException coffeExpObj){ //bundle similar exceptions
throwCoffeAndGetNew(coffeExpObj); //handle

Type Inference:
Lists can be put as such easily!
 Map<String, Integer> = new HashMap<String, Integer>();  //no need to write like this
 Map<String, Integer> = new HashMap<>();     //this will just do

Elvis Operator:
This is from groovy language. ( ?: looks like Elvis)
Instead of  x!=null? x: y, we can write as x ?: y
Ex:- Integer ival = (input from user); // may be null
int i = ival ?: -1; // no NullPointerException from unboxing

We hear something called Module in Java 7, module or a module definition by book is ‘a logical unit of set of files, resources and its dependencies that can be versioned, packaged and deployed in the module repository for re-use by some other application.’ Each module consists of a module meta-data that is self-describing. (Good for JAR versioning). Modules can be exported & imported between projects.

/* module meta-data */
module A @ 1.0 //this module class is of version 1.0
requires B @ 2.1; //this needs B of version 2.1
requires C @ 1.1; //this needs C of version 1.1
} /*meta-data end*/

module A;
package com.sample;
public class sample class{ 
public void sample()

Note: If class or one of its members or constructors is declared module, it will be accessible from a type that belongs to the same module.
If you don’t get it chill, I didn’t either, at first. We’ll see more on this in following posts.
Whole new I/O API:
The Java team has rolled out a whole new IO package, java.nio(new IO)
Tons of useful things for file and path handling under this.
Path is one such new class. (
It’s like a Unix path for manipulation, finding file, properties etc
Path searchPath = Paths.get(“c:/sample”);
final Path findFile = Paths.get(“samplefile”);
//similar to FileSystems.getDefault().getPath("/samplefile");
FileVisitor visitor = new SimpleFileVisitor()
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
//do something
Files.walkFileTree(searcPath, visitor);
Other features of nio are Buffers, Channels, Selectors, Character sets, asynchronous I/O, File Notifications, Directory Operations. know more

Garbage First!:
No more chaos with a fuzzy GC,
•    All new garbage collector, the “Garbage First Collector”.
•    Memory split into multiple regions as opposed to 2 regions in the last version.
•    Quite predictable and provides greater through-put for memory intensive applications.
•    Performs faster than the last parallel collectors.

There are more features like Fork and Join, Cache API (temporary, permanent), new Date and time API. Stay tuned to pro them too.


  1. Good Post and useful content. Thanks for sharing with us and appreciate your effort. Core Java Training in Bangalore | Core Java course in Bangalore

  2. TreasureBox is operated by a group of young, passionate, and ambitious people that are working diligently towards the same goal - make your every dollar count, as we believe you deserve something better.
    sofa bed nz
    gazebo nz

  3. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. This site instastalker is very helpful to find informaton about instagram.

  4. blood pressure watch professional in R&D wearable blood pressure monitor, in the innovative form of a wrist watch, proactively monitors your heart health by turning real-time heart data into heart.
    mason jar lids canning lids supplier. offer canning Lids in different style and size
    Cervical spine massager We aim to create a healthy lifestyle that assists every individual to de-stress, relax. unwind and streamline a pain-free life and at the same time feel and look amazing.
    sex machine for her Choose Sex Machine to Get Orgasm and Enjoy Life
    moving dildo Enjoy sexual life for both men and women
    neon light for roomNeon Signs Light Is One-of-a-Kind Activities Designed and Hosted by Expert Locals. All Experiences are Vetted for Quality.
    dog training collarsPets Supplier mall offers the ultimate pet shop experience. We have all the pet supplies, pet food, toys and accessories you and your pet needs at great prices. Find all the best pets suppliers coupons, promotion.
    novelty giftsDiscover the latest and most interesting gadgets at a bargain price
    Car decorationHere you will find the latest and most fashionable car accessories

  5. That’s by no means a pleasing experience, but with a 3D printer helpful, you won’t ever need to worry about it once more. This is for sure one of the most helpful 3d printing ideas on our list. Definitely among the many most fascinating and funky things to 3D print on this list , the dragonfly is a tiny little flying machine have the ability to|you probably can} whip up in a Bluetooth Gaming Headset short time|a short while}. It’s excellent for offering slightly leisure for your kids on a wet day. In just a few minutes, your 3D printer can spit one out and have you making exact cuts in your crafting initiatives in no time at all. With these easy 3D printer designs, you’ll have all {you need to|you should|you have to} generate truly distinctive desktop organizers that not solely keep your stuff where it must be but look cool as well.