Dear friends,welcome 2 Java 8. It released by taking some new amazing features. We got lots of updates from java1.1 to 1.7 like collections(1.2) , memory management stuffs etc.but in java8.0 we will get something new. Basically we will get three important feature that are :
Now we will start with a small update like method definition in interface. We know in 1.7 method is declared in interface but not defined. So here in 1.8 we will see how a method is defining in interface. Second update that we will know that is functional programming. Here we will not focus how to do thing, just focus on what to do thing.Third update is Lambda expression. It is very useful for android programmer and also those people who are working in big data. Basically lambda expressions remove the boiler plate code present when we write anonymous inner classes and here we have to focus main thing. Fourth update is stream API.
Now I am presenting a simple demo program that I have a List containing some integer objects and we want to retrieve, then there are different 4 approaches that I have implemented: among them first three approaches belongs to java 7 and fourth approach belongs to Java 8 feature.
Package java8s; import java.util.*; public class Java8Demo { public static void main(String[] args) { List<Integer> l=Arrays.asList(10,20,30,40,50); for(int i=0;i<5;i++) { System.out.println(l.get(i)); } } }
10
20
30
40
50
Package java8s; import java.util.*; public class Java8Demo { public static void main(String[] args) { List<Integer> l=Arrays.asList(10,20,30,40,50); //for(int i=0;i<5;i++) //{ //System.out.println(l.get(i)); //} Iterator<Integer> i=l.iterator(); while(i.hasNext()) { System.out.println(i.next()); } } }
10
20
30
40
50
Package java8s; import java.util.*; public class Java8Demo { public static void main(String[] args) { List<Integer> l=Arrays.asList(10,20,30,40,50); //for(int i=0;i<5;i++) //{ //System.out.println(l.get(i)); //} //Iterator<Integer> i=l.iterator(); //while(i.hasNext()) //{ //System.out.println(i.next()); //} for(int i:l) { System.out.println(i); } } }
10
20
30
40
50
Package java8s; import java.util.*; public class Java8Demo { public static void main(String[] args) { List<Integer> l=Arrays.asList(10,20,30,40,50); //for(int i=0;i<5;i++) //{ //System.out.println(l.get(i)); //} //Iterator<Integer> i=l.iterator(); //while(i.hasNext()) //{ //System.out.println(i.next()); //} //for(int i:l) //{ //System.out.println(i); //} l.forEach(i->System.out.println(i)); // java 8 feature } }
10
20
30
40
50
Package java8s; import java.util.*; public class Java8Demo { public static void main(String[] args) { List<Integer> l=Arrays.asList(10,20,30,40,50); l.forEach(i->System.out.println(i)); //java 8 feature } }
10
20
30
40
50
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc