Sponsored Links

Ad by Google
Still popular java interview question, yesterday I was appeared in one of the world's largest investment banking company's interview and interviewer asked me to list down the new features of java 7
I thought it was java 8 but when, I re-confirm then interviewer replied yes you have to list down the new features of java7.

So, I decided to post a topic on new features of java 7, In this post I am going to list down all the new features of java7 with code example.
The java 7 features are still on demand not only in real time use but in interview also like java program to balanced parentheses

Below are the list of new features of java 7
  1. String in switch
  2. Try-with-resources statement
  3. Underscores in numeric literals
  4. Binary literals
  5. Multiple exception catching
  6. Improved Type Inference for Generic Instance Creation
  7. SafeVarargs
String in switch: Now you can use Strings in switch statements.
public static void stringInSwitch(String months) {

		final String JAN = "january";
		final String FEB = "february";
		final String DEC = "December";

		switch (months) {
		case JAN:
			System.out.println("Repulic Day");
		case FEB:
			System.out.println("Valentine's Day");
		case DEC:

Try-with-resources statement:
public static void tryWithResources() throws IOException {
		try (BufferedReader br = new BufferedReader(new FileReader("test.txt"))) {


Underscores in numeric literals:
public static void _InNumeric() {
		int one_million = 1_000_000;


Binary literals:
public static void binaryLiterals() {
		int binary = 0b1001_1001;

Multiple exception catching:
public static void multipleException() {
		try {
			BufferedReader br = new BufferedReader(new FileReader("test.tx"));
			Object x = new Integer(0);
		} catch (FileNotFoundException | ClassCastException e) {

Improved Type Inference for Generic Instance Creation:
Map<String, List<String>> myMap = new HashMap<>();


	public static void safeVarargs(List<String>... lists) {
		for (List<String> list : lists) {

Sponsored Links


Post a Comment