This document provides an overview of the 20 year history of Java and introduces key concepts of Java 8 including lambdas, streams, and parallel streams. It begins with Java's origins in the early 1990s at Sun Microsystems and covers major releases and new features up to Java 8 in 2014. The document then explains lambdas, streams, and how parallel streams enable automatic parallelization. It includes examples of using streams and parallel streams to filter, map, and sort collections of objects. Finally, it demonstrates solving a sample problem of finding transaction IDs using streams versus traditional for loops.
1. 20 years of Java
&
Simplified PARALLELISM - Java8
2. AGENDA
20 Years of JAVA
✣ Prehistory - the WEB
✣ Birth of OAK or JAVA
✣ Evolution till date
++++++++++++++++
Fun Quiz
Java 8 - Streams API and Parallelism
✣ Lambdas
✣ Streams
✣ Parallel Streams
++++++++++++++++
Demo Q&A
Slides will be uploaded at http://www.slideshare.net/dshevani
3. Hello everyone !
I am Deepak Shevani
I work at Flipkart, building next generation e-commerce platforms.
I like presenting & love to mingle with technology enthusiasts.
Contact me : aum2deepak@gmail.com
@deepak_shevani
5. Prehistory
✣ [1991]
■ World Wide Web initially released by CERN for physics community
■ Project Green started at Sun to explore opportunities in consumer electronics
■ New Wave was about convergence of interconnected computers and devices
■ James Gosling was exploring programming languages to suit requirements
✣ [1992]
■ OAK programming language, descendant of C++ but platform independent
■ Star7 interactive hand-held PDA introduced by Project Green
✣ [1993]
■ World Wide Web is born at CERN, put on public domain
■ 500 known web servers around the world
✣ [1994]
■ Browsers : Netscape Navigator released, WebRunner (HotJava)* demoed
■ 10,000 known web servers and 10 million web users
■ Java compiler re-written in Java rather in C++
6. Birth OF JAVA [1995]
✣ 16 million internet users worldwide
✣ Birth of e-Commerce companies
■ __a___ and __a_
✣ Birth of internet companies
■ _a___
✣ Demo of WebRunner at TED conference
✣ Debut of
■ Java 1.0a2
■ Hotjava
H A P P Y B I R T H D A Y J A V A
7. Birth OF JAVA [1995]
✣ 16 million internet users worldwide
✣ Birth of e-Commerce companies
■ Amazon and eBay
✣ Birth of internet companies
■ Yahoo
✣ Demo of WebRunner demo at TED
✣ Debut of
■ Java 1.0a2
■ Hotjava
H A P P Y B I R T H D A Y J A V A
8. Evolution OF JAVA [1996-2000]
✣ [1996]
■ First JavaOne developer conference held in SFO and attracts 6000 people
■ Java 1.0 available for download
■ Sun licenses Java to OS vendors including MS, Apple, IBM and others
✣ [1997]
■ JDK 1.1 released, included JavaBeans, RMI, JIT, Inner Classse, JDBC support
■ Sun sues Microsoft over use of Java and distorting it :)
■ 43% of US families own a computer
✣ [1998]
■ Google :) Apple iMac :)
■ Netscape Navigator acquired by AOL for whopping $4.2 billion
■ JDK 1.2 released, included Swing, Plugin, IDL, Collections, strictfp
✣ [1999]
■ Sun and AOL announce a joint alliance to market business software
■ Sun announces Java 2 Platform, J2ME, J2SE and J2EE
✣ [2000]
■ DotCom bubble bursts
■ JDK 1.3 released, included HotSpot, RMI/Corba, Java Sound
9. Evolution OF JAVA [2001-2005]
✣ [2001]
■ Google awarded patent for pagerank algorithm
■ Launch of Eclipse Project by IBM
■ Apple iPod :)
✣ [2002]
■ JDK 1.4 released, included JCP, WebStart, NIO, Logging, assertions
■ J2EE SDK downloads reach 2 million
✣ [2003]
■ Java’s new coffee logo debuts
■ Java.com launches
✣ [2004]
■ Java technology powered Mars Rover (Spirit) touches Mars
■ Java is already on 1.5 billion devices
■ Java 2 Platform Standard Edition J2SE 5.0 (Project Tiger) released
■ Included Generics, AutoBoxing/UnBoxing, Concurrency Utilities, enums
✣ [2005]
■ Google Maps launched
■ Sun launches Glassfish product
10. Evolution OF JAVA [2006-2010]
✣ [2006]
■ Java SE 6 released (no longer branded as J2SE) (Project Mustang)
■ Included Scripting, XML and Web Services
■ Sun releases Java Platforms on Oct 25 under the GNU General Public License
:)
✣ [2007]
■ Apple iPhone :)
■ Sun releases Duke, the Java mascot, under the free BSD license
✣ [2008]
■ Google introduces the Android operating system for mobile phones.
■ Facebook reaches 100 million users.
■ Twitter.com has more than 70 million unique visitors per month.
■ Sun slowing down ??
✣ [2009]
■ Oracle announces that it will acquire Sun Microsystems at JavaOne
■ Project Coin launched to enhance the Java programming language
✣ [2010]
■ Oracle acquires Sun Microsystems
■ JCP approves Java 7 and Java 8 roadmaps
11. Evolution OF JAVA [2011-2015]
✣ [2011]
■ Java SE 7 released (Project Dolphin) on July 28, 2011
■ Features
○ Strings in Switch statement
○ Type Inference for Generic Instance Creation
○ Multiple Exception Handling
○ Diamond Syntax
○ Automatic null Handling
○ ForkJoin, NIO2
○ etc
✣ [2014]
■ Java SE 8 released (No Project code !! ) on March 18, 2014
■ Features
○ Lambda Expressions, Streams
○ Pipelines and Streams API
○ Default Methods
○ Nashorn Javascript engine
○ Parallel operations
○ etc
13. QUIZ TIME
1) When did Java go open-source ? (date-year)
Oct 25, 2006
14. QUIZ TIME
1) When did Java go open-source ? (date-year)
Oct 25, 2006
2) When was internet first put on public domain ?
15. QUIZ TIME
1) When did Java go open-source ? (date-year)
Oct 25, 2006
2) When was internet first put on public domain ?
1993
16. QUIZ TIME
1) When did Java go open-source ? (date-year)
Oct 25, 2006
2) When was internet first put on public domain ?
1993
3) When was Java Coffee logo introduced ?
17. QUIZ TIME
1) When did Java go open-source ? (date-year)
Oct 25, 2006
2) When was internet first put on public domain ?
1993
3) When was Java Coffee logo introduced ?
2003
GREAT - Let’s move on :)
19. Basic Jargon FIRST
Lambdas
A lambda is anonymous function. A function is a
computation that may take some arguments and
may return some value. Lambdas enable functions to
passed around and stored like values (smells like
functional programming, yeah)
Syntax of lambda expression
( [optional arguments] ) -> body
( Person p1, Person p2 ) -> p1.name() == p2.name()
**** Types can be inferred (parameters, return type)
Streams
A Stream is an abstract concept that represents
multiple values. It may or may not be collection.
It may or may not be a sequence. It may or may
not be an iterator. It is something that would
allow sequential as well as parallel processing :)
Stream<T> is opened using
Collections.stream(), Collection.parallelStream()
IntStream.range(), Stream.of(), Arrays.stream()
BufferedReader.lines(), CharSequence.chars()
20. E X A M P L E S H O U L D M A K E I T C L E A R
SomeList<Employee> employees = ….
double highestPaid =
employees.stream()
.filter(e -> e.getDepartment().equals(‘Search’)
.map(e -> e.getSalary())
.max();
21. I T E R A T I O N S
// EXTERNAL
for (Item items : items) {
process(item);
}
// INTERNAL
items.forEach(item -> process(item));
22. S T R E A M O F B E N E F I T S
- LAZY EVALUATION
- SHORT CIRCUITING
- AUTOMATIC PARALLELISM
24. Question
Find all transactions of type mobiles and return a
list of transaction IDs sorted in decreasing order of
transaction value.
25. W I T H O U T S T R E A M S ( Java 7)
List mobileTransactions = new Arraylist<>();
for(Transaction t: transactions){
if(t.getType() == Transaction.MOBILE){
mobileTransactions.add(t);
}
}
Collections.sort(mobileTransactions, new MobilesComparator());
List transactionIds = new ArrayList<>();
for(Transaction t: mobileTransactions){
transactionsIds.add(t.getId());
}
26. U S I N G S T R E A M S ( Java 8)
List transactionsIds = transactions.stream()
.filter(t -> t.getType() == Transaction.MOBILE)
.sorted(comparing(Transaction::getValue)
.reversed())
.map(Transaction::getId)
.collect(toList());
27. U S I N G P A R A L L E L S T R E A M S
List transactionsIds = transactions.parallelStream()
.filter(t -> t.getType() == Transaction.MOBILE)
.sorted(comparing(Transaction::getValue)
.reversed())
.map(Transaction::getId)
.collect(toList());
28. Credits
Special thanks to all the people who made and
released these awesome resources for free:
✣ Presentation template by SlidesCarnival
✣ Photographs by Unsplash
✣ Paper texture by GraphicBurguer