Java 7 Type Inference

Java 7 introduced a new feature Type Interface which provides ability to compiler to infer the type of generic instance. We can replace the type arguments with an empty set of type parameters () diamond. Before Java 7 following approach was used: List list = new List(); We can use following approach with Java 7: … Read more

Java 7 Features with Examples

Java 7 String In Switch Case Statement Java switch statement: Java switch statement is used to execute a block of statement based on the switch expression value. It is like if else if statement.… Read More Java 7 Try With Resources Example Resource: A resource is an object that must be closed after the program is … Read more

java 7 catch multiple exceptions

Java 7 provides the facility to catch multiple type exceptions in a single catch block to optimize code. We can use vertical bar or pipe (|) to separate multiple exceptions in catch block. Multiple exceptions handling before Java 7 package com.w3schools; public class MultipleExceptionHandling { public static void main(String args[]){ try{ int array[] = new … Read more

Java 7 Numeric Literals with Underscore

Numeric Literals Java 7 provides the facility to use underscore in numeric literals like int, byte, short, float, long, double. We can use any number of underscore characters (_) between digits in a numerical literal. It helps to improve the code readability. Note: Underscores cannot be put at the end of literal. So 12_ is … Read more

java 7 binary literals example

Binary Literals In Java 7, the integral types (byte, short, int, and long) can also be expressed using the binary number system. To specify a binary literal, add the prefix 0b or 0B to the number. Java binary literals example package com.w3schools; public class Java7BinaryLiterals { public static void main(String args[]){ int i=0b01111; byte b=(byte) … Read more

java 7 try with resources example

Resource: A resource is an object that must be closed after the program is finished with it. For example a File resource or JDBC resource for database connection. The try-with-resources statement: Main concept behind the try-with-resources statement is auto resource management. Before Java 7, there was no auto resource management and we explicitly have to … Read more

Java 7 String in Switch Case Statement

Java switch statement: Java switch statement is used to execute a block of statement based on the switch expression value. It is like if else if statement. Java 7 allows us to use string objects in the expression of switch statement. Note: Java switch case String is case sensitive. Java switch case uses String.equals() method … Read more

java varargs variable arguments example

Java varargs provides the facility to a method to accept variable number of arguments. Varargs refers to variable-length arguments. A variable-length argument is specified by three dots (…) also known as ellipsis. Before varargs, variable-length arguments handled either by using method overloading or take an array as the method parameter but it was not considered … Read more