SlideShare a Scribd company logo
1 of 67
Download to read offline
(x) -> x + x
Felipe Mamud
@ftmamud
Felipe Mamud
fmamud
fmamud
Agenda
• Environment lab
• Lambda expressions and Method references
• Functional Interfaces and Default Methods
• Java.util.function
• Stream API
• Repeating and Type Annotations
• New Java Date/Time API
• Java API additions
• Nashorn JS Engine
• Other stuffs
Environment lab
• Download JDK8 (currently 1.8.0-b132)
http://www.oracle.com/technetwork/java/javase/downloads/index.html
• IDE Support for JDK 8
– Eclipse 4.4 Luna (M6 partially compliant)
– NetBeans 8
– IntelliJ IDEA 13.1
• Java™ Platform, Standard Edition 8
API Specification
– http://docs.oracle.com/javase/8/docs/api/
Lambda expressions
• A lambda expression is an anonymous
function (not 100% true for Java but lets
assume it for time being)
• Syntax:
(arguments) -> (body)
• Following are some examples of Lambda
expressions:
(int a, int b) -> { return a + b; }
() -> System.out.println("Hello World");
(String s) -> { System.out.println(s); }
() -> 42
() -> { return 3.1415; };
Lambda expressions
• Four important syntax rules:
1. Declaring the types of the parameters is optional;
2. Using parentheses around the parameter is optional if
you have only one parameter;
3. Using curly braces is optional (unless you need multiple
statements);
4. The return keyword is optional if you have a single
expression that returns a value.
Lambda expressions
• Lambdas expressions are classified
into two types:
– Capturing
• Lambdas are said to be “capturing” if they access a
non-static variable or object that was defined outside
of the lambda body. For example, this lambda
captures the variable x:
int x = 5;
return y -> x + y;
Lambda expressions
• In order for this lambda
declaration to be valid, the variables
it captures must be “effectively final”.
So, either they must be marked with
the final modifier, or they must not be modified after
they're assigned.
– Non-capturing
• Is as opposed to capturing lambdas. A non-capturing lambda is
generally going to be more efficient than a capturing one,
because a non-capturing lambda only needs to be evaluated
once.
Lambda expressions
• What lambdas don't do?
– Non-final variable capture: If a variable is assigned a new
value, it can't be used within a lambda. The “final” keyword is not
required, but the variable must be “effectively final”. This code does
not compile:
int count = 0;
List<String> strings = Arrays.asList("a","b","c");
strings.forEach(s -> {
count++; // error: can't modify the value of count
});
Lambda expressions
– Exception transparency : If a checked exception may be
thrown from inside a lambda, the functional interface must also declare
that checked exception can be thrown. The exception is not propagated
to the containing method. This code does not compile:
void appendAll(Iterable<String> values, Appendable out)
throws IOException { // doesn't help with the error
values.forEach(s -> {
out.append(s); // error: can't throw IOException here
// Consumer.accept(T) doesn't allow it
});
}
There are ways to work around this:
– define your own functional interface that extends Consumer and wrap the
IOException through as a RuntimeException. (UncheckedIOException)
Lambda expressions
– Control flow (break, early return) :
In the forEach examples above, a traditional continue is possible
by placing a “return;” statement within the lambda. However, there
is no way to break out of the loop or return a value as the result of
the containing method from within the lambda. For example:
final String secret = "foo";
boolean containsSecret(Iterable<String> values) {
values.forEach(s -> {
if (secret.equals(s)) {
??? // want to end the loop and return true, but can't
}
});
}
Lambda expressions
– Examples:
//Old way:
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Hello from thread");
}
}).start();
//New way:
new Thread(
() -> System.out.println("Hello from thread")
).start();
Lambda expressions
– Examples:
//Old way:
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("From anonymous class");
}
});
//New way:
button.addActionListener( e ->
System.out.println("From lambda expressions!");
);
Lambda expressions
– Examples:
//Old way:
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
for (Integer n : list) {
System.out.println(n);
}
//New way:
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
list.forEach(n -> System.out.println(n));
//or we can use :: double colon operator
list.forEach(System.out::println);
Lambda expressions
• Is a literal method value that uses the colon
double operator (::), corresponding to a
lambda expression:
Method references
• Method references can point to:
– Static methods; String::valueOf
– Instance methods; Object::toString
– Methods on instances; x::toString
– Constructors; TreeSet::new
Method references
Method reference Equivalent lambda expression
String::valueOf x -> String.valueOf(x)
Object::toString x -> x.toString()
x::toString () -> x.toString()
ArrayList::new () -> new ArrayList<>()
• Example:
List<String> words = Arrays.asList("Biga", "Pisca", “Lopam");
words.forEach(System.out::println);
// java.lang.Iterable:
default void forEach(Consumer<? super T> action)
//java.io.PrintStream:
public void println(String x)
Method references
Functional Interfaces
• a functional interface is defined as an
interface with exactly one
(non default) method.
• Example:
@FunctionalInterface
public interface Runnable {
public abstract void run();
}
Functional Interfaces
• A new annotation, @FunctionalInterface, has
been introduced.
• It can be placed on an interface to declare
the intention of it being a functional
interface.
• It will cause the interface to refuse to compile
unless you've managed to make it a
functional interface.
Functional Interfaces
• Each lambda expression can be implicitly
assigned to one of the interface called
Functional interface.
• Examples:
new Thread(
() -> System.out.println("hello world")
).start();
Comparator<String> c = (a, b) ->
Integer.compare(a.length(), b.length());
Default methods
• Default methods are not abstract, so a
functional interface can define as many
default methods as it likes.
• Why we need Default Methods?
– R: Extensibility without breaking the implementor
class.
Default methods
• Example:
public interface Iterable<T> {
Iterator<T> iterator();
default void forEach(Consumer<? super T> action) {
Objects.requireNonNull(action);
for (T t : this) {
action.accept(t);
}
}
default Spliterator<T> spliterator() {
return Spliterators.spliteratorUnknownSize(iterator(), 0);
}
}
Static methods on Interface
• Although not strictly related to default methods,
the ability to add static methods to interfaces is
a major change to the Java language.
public interface Stream<T> extends BaseStream<T, Stream<T>> {
...
public static<T> Stream<T> of(T... values) {
return Arrays.stream(values);
}
...
}
java.util.function
• Java 8 comes with several functional interfaces in
package, java.util.function:
– Function<T,R> - takes an object of type T and returns R;
– Supplier<T> - just returns an object of type T;
– Predicate<T> - returns a boolean value based on input of type T;
– Consumer<T> - performs an action with given object of type T;
– BiFunction - like Function but with two parameters;
– BiConsumer - like Consumer but with two parameters;
– BinaryOperator<T> - take two T's as input, return one T as output,
useful for "reduce" operations.
• It also comes with several corresponding interfaces for primitive types,
such as:
– IntConsumer
– IntFunction<R>
– IntPredicate
– IntSupplier
Stream API
• New Java 8 Stream API provides utilities to
support functional-style operations on
streams of values.
• A stream is something like an iterator. The
values “flow past” (analogy to a stream of
water) and then they're gone. A stream can
only be traversed once, then it's used up.
Streams may also be infinite.
Stream API
• There are two types of Streams:
– Sequential: The actions of a sequential stream occur
in serial fashion on one thread.
– Parallel: The actions of a parallel stream may be
happening all at once on multiple threads.
• Usually, dealing with a stream will involve these
steps:
1. Obtain a stream from some source;
2. Perform one or more intermediate operations;
3. Perform one terminal operation.
Stream API
• Threre are two operation types of Streams:
– Intermediate: An intermediate operation keeps the
stream open and allows further operations to follow.
– Lazy operations (e.g. filter, map, flatMap, peek,
distinct, sorted, limit e substream)
– Terminal: A terminal operation must be the final
operation invoked on a stream. Once a terminal
operation is invoked, the stream is "consumed" and
is no longer usable. (e.g. forEach, toArray, reduce,
collect, min, max, count, anyMatch, allMatch,
noneMatch, findFirst e findAny)
Stream API
• There are a couple more general properties of stream
operations to consider:
– Stateful: imposes some new property on the stream,
such as uniqueness of elements, or a maximum number of
elements, or ensuring that the elements are consumed in
sorted fashion. These are typically more expensive than
stateless intermediate operations.
– Short-circuiting : allows processing of a stream to stop
early without examining all the elements. This is an
especially desirable property when dealing with infinite
streams; if none of the operations being invoked on a
stream are short-circuiting, then the code may never
terminate.
Stream API
• Examples:
int sumOfWeights = blocks.stream()
.filter(b -> b.getColor() == RED)
.mapToInt(b -> b.getWeight())
.sum();
Stream<Person> first4females = people.stream()
.peek(System.out::println)
.filter(p -> p.getGender().equals("F"))
.distinct()
.limit(4);
Repeating and Type Annotations
• Java 8 will allow annotations to be repeated.
// the first of the month and every monday at 7am
@Schedule(dayOfMont = "first")
@Schedule(dayOfWeek = "Monday", hour = 7)
public void doGoblinInvasion() { ... }
• To do this there is a new method called
obj.getAnnotationsByType(Class annotationClass)
on Class, Constructor, Method, etc. It returns an
array of all such annotations (or an empty array if
there are none).
Repeating and Type Annotations
• In Java 8, annotations can also be applied to the use of types.
This new ability is primarily aimed at supporting type-checking
frameworks, such as Checker. These frameworks help find errors
in your code at compile time.
// Class instance creation:
new @Interned RocketShip();
// Type cast:
notNullString = (@NonNull String) str;
// implements clause:
class ImmutableSet<T> implements
@Readonly Set<@Readonly T> { ... }
// Thrown exception declaration:
void launchRocket() throws @Critical FireException { ... }
New Java Date/Time API
• Java 8 introduces a new Date/Time API that
is safer, easier to read, and more
comprehensive than the previous API.
• Java’s Calendar implementation has not
changed much since it was first introduced
and Joda-Time is widely regarded as a better
replacement.
New Java Date/Time API
New Java Date/Time API
New Java Date/Time API
• Example:
// Old way
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR, cal.get(Calendar.HOUR) + 2);
// New Way
LocalTime now = LocalTime.now();
LocalTime later = now.plus(2, ChronoUnit.HOURS);
New Java Date/Time API
• For timezone specific times you use ZonedDateTime.
// Leaving from San Francisco on July 20, 2013, at 7:30 p.m.
LocalDateTime leaving = LocalDateTime.of(2013, Month.JULY, 20, 19, 30);
ZoneId leavingZone = ZoneId.of("America/Los_Angeles");
ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone);
// Flight is 10 hours and 50 minutes, or 650 minutes
ZoneId arrivingZone = ZoneId.of("Asia/Tokyo");
departure.withZoneSameInstant(arrivingZone).plusMinutes(650);
// Checks if the specified instant is in daylight savings.
if (arrivingZone.getRules().isDaylightSavings(arrival.toInstant()))
// LEAVING: Jul 20 2013 07:30 PM (America/Los_Angeles)
// ARRIVING: Jul 21 2013 10:20 PM (Asia/Tokyo)
(Asia/Tokyo standard time will be in effect.)
New Java Date/Time API
• Enums
– Java 8 adds several enums, such as LocalDateTimeField and
LocalPeriodUnit, for expressing things like “days” and “hours”
instead of the integer constants used in the Calendar API.
• Clock
– The Clock can be used in conjunction with dates and times to help
build your tests. During production a normal Clock can be used, and
a different one during tests.
//To get the default clock, use the following:
Clock clock = Clock.systemDefaultZone();
//The Clock can then be passed into factory methods;
LocalTime time = LocalTime.now(clock);
New Java Date/Time API
• Working with time zones
ZoneId zone = ZoneId.systemDefault();
Clock clock = Clock.system(zone); // America/Sao_Paulo
ZoneId zone = ZoneId.of("Europe/Berlin");
Clock clock = Clock.system(zone); // Europe/Berlin
Set<String> availableZoneIds =
ZoneId.getAvailableZoneIds();
// [Asia/Aden, America/Cuiaba, Etc/GMT+9, Etc/GMT+8,...
New Java Date/Time API
• Doing calculations with times and dates
Period days = Period.ofDays(5);
LocalTime time = LocalTime.now(); // 15:15:45.562
time.plus(5, ChronoUnit.DAYS);
// throws UnsupportedTemporalTypeException:
Unsupported unit: Days
time.plus(5, ChronoUnit.HOURS); // 20:15:45.562
New Java Date/Time API
• Period parse exploring:
Period parse = Period.parse("P5D"); // Period.ofDays(5)
– For example, the following are valid inputs:
"P2Y" // Period.ofYears(2)
"P3M" // Period.ofMonths(3)
"P4W" // Period.ofWeeks(4)
"P1Y2M3D" // Period.of(1, 2, 3)
"P1Y2M3W4D" // Period.of(1, 2, 25)
"P-1Y2M" // Period.of(-1, 2, 0)
"-P1Y2M" // Period.of(-1, -2, 0)
New Java Date/Time API
• Fluent Date and Time API:
// calculate the payday
LocalDate today = LocalDate.now();
today.with(TemporalAdjusters.lastDayOfMonth()).minusDays(2);
// immutable
LocalDate dateOfBirth = LocalDate.of(2012, Month.MAY, 14);
LocalDate firstBirthday = dateOfBirth.plusYears(1);
New Java Date/Time API
• Different display name types:
DayOfWeek dow = DayOfWeek.MONDAY;
Locale locale = Locale.getDefault();
dow.getDisplayName(TextStyle.FULL, locale); // Monday
dow.getDisplayName(TextStyle.NARROW, locale); // M
dow.getDisplayName(TextStyle.SHORT, locale); // Mon
//It is a valid year?
MonthDay date = MonthDay.of(Month.FEBRUARY, 29); boolean
boolean validLeapYear = date.isValidYear(2010);
// Is leap year?
boolean validLeapYear = Year.of(2012).isLeap();
New Java Date/Time API
• Method naming conventions
New Java Date/Time API
• Interoperability with Legacy Code
– Calendar.toInstant() converts the Calendar object to an
Instant.
– GregorianCalendar.toZonedDateTime() converts a
GregorianCalendar instance to a ZonedDateTime.
– GregorianCalendar.from(ZonedDateTime) creates a
GregorianCalendar object using the default locale from a
ZonedDateTime instance.
– Date.from(Instant) creates a Date object from an Instant.
– Date.toInstant() converts a Date object to an Instant.
– TimeZone.toZoneId() converts a TimeZone object to a
ZoneId.
Java API additions
• API additions
– Collections
– Concurrency
– IO/NIO
– Reflection and annotation changes
– Other miscellaneous additions to java.lang, java.util, and
elsewhere
http://www.techempower.com/blog/2013/03/26/everything-about-java-8/
• JDBC 4.2 (Rowset 1.2, REF_CURSOR support, etc.)
http://docs.oracle.com/javase/8/docs/technotes/guides/jdbc/jdbc_42.html
Optional
• Java 8 comes with the Optional class in
the java.util package for avoiding null return
values (and thusNullPointerException).
• Tony Hoare, the invention of the null reference
in 1965 for the ALGOL W programming
language. He calls The Billion Dollar Mistake.
• Used in the Stream API or custom
implementation
Optional
• Examples:
//Creating an instance of Optional using the factory method.
Optional<String> name = Optional.of("Puppy");
name.orElse("Bob")
//This fails with a NullPointerException.
Optional<String> someNull = Optional.of(null);
//This fails with a NoSuchElementException
Optional<String> someNull = Optional.ofNullable(null);
someNull.get();
Nashorn JS Engine
• Nashorn replaces Rhino as the default JavaScript
engine for the Oracle JVM.
• Nashorn is much faster since it uses
the invokedynamic feature of the JVM. It also
includes a command line tool (jjs).
• Java Platform, Standard Edition Nashorn User's Guide
http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/
• Command line Nashorn:
jjs script.js
Nashorn JS Engine
• Hello World:
var hello = function() {
print("Hello Nashorn!");
};
hello();
Nashorn JS Engine
• Examples:
var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var filtered = data.filter(function(i) {
return i % 2 == 0;
});
print(filtered);
var sumOfFiltered = filtered.reduce(function(acc, next) {
return acc + next;
}, 0);
print(sumOfFiltered);
Nashorn JS Engine
• Examples:
var imports = new JavaImporter(java.util, java.io, java.nio.file);
with (imports) {
var paths = new LinkedList();
print(paths instanceof LinkedList); //true
paths.add(Paths.get("/"));
paths.add(Paths.get("/home"));
paths.add(Paths.get("/tmp"));
print(paths); // [/, /home, /tmp]
}
Nashorn JS Engine
• Call from Java Class:
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("nashorn");
Reader reader = new FileReader("/home/fmamud/script.js");
engine.eval(reader); // prints: 2,4,6,8,10
30
Other stuffs
• jdeps
– In JDK 8, a new command-line tool, jdeps, is added
that developers can use to understand the static
dependencies of their applications and libraries.
– Java Platform, Standard Edition Tools Reference
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html
– Usage: jdeps <options> <classes...>
where <classes> can be a pathname to a .class
file, a directory, a JAR file, or a fully-qualified
class name.
// monitoracao-v1.4b.jar.dot
digraph "monitoracao-v1.4b.jar" {
// Path: monitoracao-v1.4b.jar
"br.com.bradesco.monitoracao" -> "java.io";
"br.com.bradesco.monitoracao" -> "java.lang";
"br.com.bradesco.monitoracao" -> "java.lang.reflect";
"br.com.bradesco.monitoracao" -> "java.net";
"br.com.bradesco.monitoracao" -> "java.sql";
"br.com.bradesco.monitoracao" -> "java.text";
"br.com.bradesco.monitoracao" -> "java.util";
"br.com.bradesco.monitoracao" -> "javax.naming";
"br.com.bradesco.monitoracao" -> "javax.sql";
"br.com.bradesco.monitoracao" -> "log.c.apis (BRS000A2.jar)";
"br.com.bradesco.monitoracao" -> "util.dataAccess.jdbc (not found)";
}
Other stuffs
– Example:
> jdeps -dotoutput . monitoracao-v1.4b.jar BRS000A2.jar
// BRS000A2.jar.dot
digraph "BRS000A2.jar" {
// Path: BRS000A2.jar
"log.c.apis" -> "java.io";
"log.c.apis" -> "java.lang";
"log.c.apis" -> "java.net";
"log.c.apis" -> "java.sql";
"log.c.apis" -> "java.util";
"log.c.apis" -> "javax.naming";
"log.c.apis" -> "javax.sql";
}
//summary.dot
digraph "summary" {
"monitoracao-v1.4b.jar“
-> "BRS000A2.jar";
"monitoracao-v1.4b.jar“
-> "not found";
"monitoracao-v1.4b.jar“
-> "rt.jar";
"BRS000A2.jar“
-> "rt.jar";
}
Other stuffs
• No More Permanent Generation
– Most allocations for the class metadata are now allocated
out of native memory. This means that you won’t have to
set the “XX:PermSize” options anymore (they don’t
exist).
– This also means that you will get a
“java.lang.OutOfMemoryError: Metadata space” error
message instead of “java.lang.OutOfMemoryError:
Permgen space” when you run out of memory.
– This is part of the convergence of the Oracle JRockit and
HotSpot JVMs.
Other stuffs
• Compact profiles
– Java 8 will define subset profiles of
the Java SE platform specification
that developers can use to deploy.
Compact1 have less than 14MB;
Compact2 is about 18MB;
Compact3 is about 21MB.
For reference, the latest Java 7u21 SE Embedded
ARMv5/Linux environment requires 45MB.
• An Introduction to Java 8 Compact Profiles
– https://blogs.oracle.com/jtc/entry/a_first_look_at_compact
Useful links
• What's New in JDK 8
http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html
• JDK 8 Adoption Guide
http://www.oracle.com/technetwork/java/javase/jdk8-adoption-guide-
2157601.html
• Compatibility Guide for JDK 8
http://www.oracle.com/technetwork/java/javase/8-compatibility-guide-
2156366.html
References
• Everything about Java 8
http://www.techempower.com/blog/2013/03/26/everything-about-java-8/
• Java 8 Lambda Expressions Tutorial With
Examples
http://viralpatel.net/blogs/lambda-expressions-java-tutorial/
• Java SE 8: Lambda Quick Start
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-
QuickStart/index.html
THANK YOU
FTD Blog
@friendstechday
friendstechday@gmail.com
JOIN IN US!
FTD Group

More Related Content

What's hot

Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features OverviewSergii Stets
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java langer4711
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8Knoldus Inc.
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsEmiel Paasschens
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New FeaturesNaveen Hegde
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8Takipi
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Harmeet Singh(Taara)
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhHarmeet Singh(Taara)
 

What's hot (20)

Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java Programming with Lambda Expressions in Java
Programming with Lambda Expressions in Java
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8The Dark Side Of Lambda Expressions in Java 8
The Dark Side Of Lambda Expressions in Java 8
 
Actors model in gpars
Actors model in gparsActors model in gpars
Actors model in gpars
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 

Viewers also liked

Node.JS - Campus Party Brasil 2011
Node.JS - Campus Party Brasil 2011Node.JS - Campus Party Brasil 2011
Node.JS - Campus Party Brasil 2011Emerson Macedo
 
Java 8 - project lambda
Java 8 - project lambdaJava 8 - project lambda
Java 8 - project lambdaIvar Østhus
 
50 new things you can do with java 8
50 new things you can do with java 850 new things you can do with java 8
50 new things you can do with java 8José Paumard
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJosé Paumard
 
50 nouvelles choses que l'on peut faire avec Java 8
50 nouvelles choses que l'on peut faire avec Java 850 nouvelles choses que l'on peut faire avec Java 8
50 nouvelles choses que l'on peut faire avec Java 8José Paumard
 
Java 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJava 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJosé Paumard
 
Les Streams sont parmi nous
Les Streams sont parmi nousLes Streams sont parmi nous
Les Streams sont parmi nousJosé Paumard
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8LivePerson
 
Java 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambdaJava 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambdaCh'ti JUG
 
Retours sur java 8 devoxx fr 2016
Retours sur java 8 devoxx fr 2016Retours sur java 8 devoxx fr 2016
Retours sur java 8 devoxx fr 2016Jean-Michel Doudoux
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8Simon Ritter
 

Viewers also liked (16)

Java8
Java8Java8
Java8
 
FTD JVM Internals
FTD JVM InternalsFTD JVM Internals
FTD JVM Internals
 
FTD Groovy
FTD GroovyFTD Groovy
FTD Groovy
 
Node.JS - Campus Party Brasil 2011
Node.JS - Campus Party Brasil 2011Node.JS - Campus Party Brasil 2011
Node.JS - Campus Party Brasil 2011
 
Java 8 - project lambda
Java 8 - project lambdaJava 8 - project lambda
Java 8 - project lambda
 
Golang
GolangGolang
Golang
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
50 new things you can do with java 8
50 new things you can do with java 850 new things you can do with java 8
50 new things you can do with java 8
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
50 nouvelles choses que l'on peut faire avec Java 8
50 nouvelles choses que l'on peut faire avec Java 850 nouvelles choses que l'on peut faire avec Java 8
50 nouvelles choses que l'on peut faire avec Java 8
 
Java 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelizationJava 8, Streams & Collectors, patterns, performances and parallelization
Java 8, Streams & Collectors, patterns, performances and parallelization
 
Les Streams sont parmi nous
Les Streams sont parmi nousLes Streams sont parmi nous
Les Streams sont parmi nous
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Java 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambdaJava 8 : Un ch'ti peu de lambda
Java 8 : Un ch'ti peu de lambda
 
Retours sur java 8 devoxx fr 2016
Retours sur java 8 devoxx fr 2016Retours sur java 8 devoxx fr 2016
Retours sur java 8 devoxx fr 2016
 
55 New Features in Java SE 8
55 New Features in Java SE 855 New Features in Java SE 8
55 New Features in Java SE 8
 

Similar to Java8

Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streamsjessitron
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 itiAhmed mar3y
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project LambdaRahman USTA
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesRaffi Khatchadourian
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hotSergii Maliarov
 
Java 8 lambdas expressions
Java 8 lambdas expressionsJava 8 lambdas expressions
Java 8 lambdas expressionsLars Lemos
 
Java 8
Java 8Java 8
Java 8vpulec
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxBruceLee275640
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Nayden Gochev
 
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...Akaks
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New featuresSon Nguyen
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8franciscoortin
 

Similar to Java8 (20)

Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
Charles Sharp: Java 8 Streams
Charles Sharp: Java 8 StreamsCharles Sharp: Java 8 Streams
Charles Sharp: Java 8 Streams
 
Lambdas in Java 8
Lambdas in Java 8Lambdas in Java 8
Lambdas in Java 8
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
java8
java8java8
java8
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Java 8
Java 8Java 8
Java 8
 
Lambdas and Laughs
Lambdas and LaughsLambdas and Laughs
Lambdas and Laughs
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
 
Java 8 lambdas expressions
Java 8 lambdas expressionsJava 8 lambdas expressions
Java 8 lambdas expressions
 
Java 8
Java 8Java 8
Java 8
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Wien15 java8
Wien15 java8Wien15 java8
Wien15 java8
 
Java 8
Java 8Java 8
Java 8
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
documents.pub_new-features-in-java-8-it-jpoialjavanaitedwien15java8pdf-java-8...
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New features
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
 

More from Felipe Mamud

Erlang sem enrolação
Erlang sem enrolaçãoErlang sem enrolação
Erlang sem enrolaçãoFelipe Mamud
 
Desenvolvendo software no mundo atual
Desenvolvendo software no mundo atualDesenvolvendo software no mundo atual
Desenvolvendo software no mundo atualFelipe Mamud
 
Reactive programming no mundo Java
Reactive programming no mundo JavaReactive programming no mundo Java
Reactive programming no mundo JavaFelipe Mamud
 
Reactive programming: Brincando com eficiência, composição e assíncronia
Reactive programming: Brincando com eficiência, composição e assíncroniaReactive programming: Brincando com eficiência, composição e assíncronia
Reactive programming: Brincando com eficiência, composição e assíncroniaFelipe Mamud
 
Minha aplicação Java vai pra nuvem. E agora?
Minha aplicação Java vai pra nuvem. E agora?Minha aplicação Java vai pra nuvem. E agora?
Minha aplicação Java vai pra nuvem. E agora?Felipe Mamud
 
EBD - Perguntas que não querem calar
EBD - Perguntas que não querem calarEBD - Perguntas que não querem calar
EBD - Perguntas que não querem calarFelipe Mamud
 
EBD - A importância da Escola Bíblica Dominical
EBD - A importância da Escola Bíblica DominicalEBD - A importância da Escola Bíblica Dominical
EBD - A importância da Escola Bíblica DominicalFelipe Mamud
 
EBD - Força de jovem
EBD - Força de jovemEBD - Força de jovem
EBD - Força de jovemFelipe Mamud
 
EBD - O que você quer ser
EBD - O que você quer serEBD - O que você quer ser
EBD - O que você quer serFelipe Mamud
 
EBD - Deixando de ser bebê
EBD - Deixando de ser bebêEBD - Deixando de ser bebê
EBD - Deixando de ser bebêFelipe Mamud
 
EBD - O que você faria se fosse invisível
EBD - O que você faria se fosse invisívelEBD - O que você faria se fosse invisível
EBD - O que você faria se fosse invisívelFelipe Mamud
 
EBD - Coisas que não fazem sentido
EBD - Coisas que não fazem sentidoEBD - Coisas que não fazem sentido
EBD - Coisas que não fazem sentidoFelipe Mamud
 
EBD - Faça mais do que saber o que e um bocejo
EBD - Faça mais do que saber o que e um bocejoEBD - Faça mais do que saber o que e um bocejo
EBD - Faça mais do que saber o que e um bocejoFelipe Mamud
 
EBD - Varias formas de dizer a mesma coisa
EBD - Varias formas de dizer a mesma coisaEBD - Varias formas de dizer a mesma coisa
EBD - Varias formas de dizer a mesma coisaFelipe Mamud
 
EBD - 10 coisas que temos de dar a Deus
EBD - 10 coisas que temos de dar a DeusEBD - 10 coisas que temos de dar a Deus
EBD - 10 coisas que temos de dar a DeusFelipe Mamud
 
EBD - Fe ter ou não ter, eis a questao
EBD - Fe ter ou não ter, eis a questaoEBD - Fe ter ou não ter, eis a questao
EBD - Fe ter ou não ter, eis a questaoFelipe Mamud
 
EBD - Amem ou misericordia
EBD - Amem ou misericordiaEBD - Amem ou misericordia
EBD - Amem ou misericordiaFelipe Mamud
 

More from Felipe Mamud (20)

Erlang sem enrolação
Erlang sem enrolaçãoErlang sem enrolação
Erlang sem enrolação
 
Desenvolvendo software no mundo atual
Desenvolvendo software no mundo atualDesenvolvendo software no mundo atual
Desenvolvendo software no mundo atual
 
Reactive programming no mundo Java
Reactive programming no mundo JavaReactive programming no mundo Java
Reactive programming no mundo Java
 
Reactive programming: Brincando com eficiência, composição e assíncronia
Reactive programming: Brincando com eficiência, composição e assíncroniaReactive programming: Brincando com eficiência, composição e assíncronia
Reactive programming: Brincando com eficiência, composição e assíncronia
 
Minha aplicação Java vai pra nuvem. E agora?
Minha aplicação Java vai pra nuvem. E agora?Minha aplicação Java vai pra nuvem. E agora?
Minha aplicação Java vai pra nuvem. E agora?
 
EBD - Perguntas que não querem calar
EBD - Perguntas que não querem calarEBD - Perguntas que não querem calar
EBD - Perguntas que não querem calar
 
EBD - UFC
EBD - UFCEBD - UFC
EBD - UFC
 
EBD - Escolhas
EBD - EscolhasEBD - Escolhas
EBD - Escolhas
 
EBD - A importância da Escola Bíblica Dominical
EBD - A importância da Escola Bíblica DominicalEBD - A importância da Escola Bíblica Dominical
EBD - A importância da Escola Bíblica Dominical
 
EBD - Força de jovem
EBD - Força de jovemEBD - Força de jovem
EBD - Força de jovem
 
EBD - O que você quer ser
EBD - O que você quer serEBD - O que você quer ser
EBD - O que você quer ser
 
EBD - Deixando de ser bebê
EBD - Deixando de ser bebêEBD - Deixando de ser bebê
EBD - Deixando de ser bebê
 
EBD - O que você faria se fosse invisível
EBD - O que você faria se fosse invisívelEBD - O que você faria se fosse invisível
EBD - O que você faria se fosse invisível
 
EBD - Coisas que não fazem sentido
EBD - Coisas que não fazem sentidoEBD - Coisas que não fazem sentido
EBD - Coisas que não fazem sentido
 
EBD - Faça mais do que saber o que e um bocejo
EBD - Faça mais do que saber o que e um bocejoEBD - Faça mais do que saber o que e um bocejo
EBD - Faça mais do que saber o que e um bocejo
 
EBD - Varias formas de dizer a mesma coisa
EBD - Varias formas de dizer a mesma coisaEBD - Varias formas de dizer a mesma coisa
EBD - Varias formas de dizer a mesma coisa
 
EBD - 10 coisas que temos de dar a Deus
EBD - 10 coisas que temos de dar a DeusEBD - 10 coisas que temos de dar a Deus
EBD - 10 coisas que temos de dar a Deus
 
EBD - Fe ter ou não ter, eis a questao
EBD - Fe ter ou não ter, eis a questaoEBD - Fe ter ou não ter, eis a questao
EBD - Fe ter ou não ter, eis a questao
 
Brincar com Deus
Brincar com DeusBrincar com Deus
Brincar com Deus
 
EBD - Amem ou misericordia
EBD - Amem ou misericordiaEBD - Amem ou misericordia
EBD - Amem ou misericordia
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Java8

  • 1. (x) -> x + x
  • 3. Agenda • Environment lab • Lambda expressions and Method references • Functional Interfaces and Default Methods • Java.util.function • Stream API • Repeating and Type Annotations • New Java Date/Time API • Java API additions • Nashorn JS Engine • Other stuffs
  • 4. Environment lab • Download JDK8 (currently 1.8.0-b132) http://www.oracle.com/technetwork/java/javase/downloads/index.html • IDE Support for JDK 8 – Eclipse 4.4 Luna (M6 partially compliant) – NetBeans 8 – IntelliJ IDEA 13.1 • Java™ Platform, Standard Edition 8 API Specification – http://docs.oracle.com/javase/8/docs/api/
  • 5. Lambda expressions • A lambda expression is an anonymous function (not 100% true for Java but lets assume it for time being) • Syntax: (arguments) -> (body)
  • 6. • Following are some examples of Lambda expressions: (int a, int b) -> { return a + b; } () -> System.out.println("Hello World"); (String s) -> { System.out.println(s); } () -> 42 () -> { return 3.1415; }; Lambda expressions
  • 7. • Four important syntax rules: 1. Declaring the types of the parameters is optional; 2. Using parentheses around the parameter is optional if you have only one parameter; 3. Using curly braces is optional (unless you need multiple statements); 4. The return keyword is optional if you have a single expression that returns a value. Lambda expressions
  • 8. • Lambdas expressions are classified into two types: – Capturing • Lambdas are said to be “capturing” if they access a non-static variable or object that was defined outside of the lambda body. For example, this lambda captures the variable x: int x = 5; return y -> x + y; Lambda expressions
  • 9. • In order for this lambda declaration to be valid, the variables it captures must be “effectively final”. So, either they must be marked with the final modifier, or they must not be modified after they're assigned. – Non-capturing • Is as opposed to capturing lambdas. A non-capturing lambda is generally going to be more efficient than a capturing one, because a non-capturing lambda only needs to be evaluated once. Lambda expressions
  • 10. • What lambdas don't do? – Non-final variable capture: If a variable is assigned a new value, it can't be used within a lambda. The “final” keyword is not required, but the variable must be “effectively final”. This code does not compile: int count = 0; List<String> strings = Arrays.asList("a","b","c"); strings.forEach(s -> { count++; // error: can't modify the value of count }); Lambda expressions
  • 11. – Exception transparency : If a checked exception may be thrown from inside a lambda, the functional interface must also declare that checked exception can be thrown. The exception is not propagated to the containing method. This code does not compile: void appendAll(Iterable<String> values, Appendable out) throws IOException { // doesn't help with the error values.forEach(s -> { out.append(s); // error: can't throw IOException here // Consumer.accept(T) doesn't allow it }); } There are ways to work around this: – define your own functional interface that extends Consumer and wrap the IOException through as a RuntimeException. (UncheckedIOException) Lambda expressions
  • 12. – Control flow (break, early return) : In the forEach examples above, a traditional continue is possible by placing a “return;” statement within the lambda. However, there is no way to break out of the loop or return a value as the result of the containing method from within the lambda. For example: final String secret = "foo"; boolean containsSecret(Iterable<String> values) { values.forEach(s -> { if (secret.equals(s)) { ??? // want to end the loop and return true, but can't } }); } Lambda expressions
  • 13. – Examples: //Old way: new Thread(new Runnable() { @Override public void run() { System.out.println("Hello from thread"); } }).start(); //New way: new Thread( () -> System.out.println("Hello from thread") ).start(); Lambda expressions
  • 14. – Examples: //Old way: button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("From anonymous class"); } }); //New way: button.addActionListener( e -> System.out.println("From lambda expressions!"); ); Lambda expressions
  • 15. – Examples: //Old way: List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7); for (Integer n : list) { System.out.println(n); } //New way: List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7); list.forEach(n -> System.out.println(n)); //or we can use :: double colon operator list.forEach(System.out::println); Lambda expressions
  • 16.
  • 17. • Is a literal method value that uses the colon double operator (::), corresponding to a lambda expression: Method references
  • 18. • Method references can point to: – Static methods; String::valueOf – Instance methods; Object::toString – Methods on instances; x::toString – Constructors; TreeSet::new Method references Method reference Equivalent lambda expression String::valueOf x -> String.valueOf(x) Object::toString x -> x.toString() x::toString () -> x.toString() ArrayList::new () -> new ArrayList<>()
  • 19. • Example: List<String> words = Arrays.asList("Biga", "Pisca", “Lopam"); words.forEach(System.out::println); // java.lang.Iterable: default void forEach(Consumer<? super T> action) //java.io.PrintStream: public void println(String x) Method references
  • 20.
  • 21. Functional Interfaces • a functional interface is defined as an interface with exactly one (non default) method. • Example: @FunctionalInterface public interface Runnable { public abstract void run(); }
  • 22. Functional Interfaces • A new annotation, @FunctionalInterface, has been introduced. • It can be placed on an interface to declare the intention of it being a functional interface. • It will cause the interface to refuse to compile unless you've managed to make it a functional interface.
  • 23. Functional Interfaces • Each lambda expression can be implicitly assigned to one of the interface called Functional interface. • Examples: new Thread( () -> System.out.println("hello world") ).start(); Comparator<String> c = (a, b) -> Integer.compare(a.length(), b.length());
  • 24. Default methods • Default methods are not abstract, so a functional interface can define as many default methods as it likes. • Why we need Default Methods? – R: Extensibility without breaking the implementor class.
  • 25. Default methods • Example: public interface Iterable<T> { Iterator<T> iterator(); default void forEach(Consumer<? super T> action) { Objects.requireNonNull(action); for (T t : this) { action.accept(t); } } default Spliterator<T> spliterator() { return Spliterators.spliteratorUnknownSize(iterator(), 0); } }
  • 26. Static methods on Interface • Although not strictly related to default methods, the ability to add static methods to interfaces is a major change to the Java language. public interface Stream<T> extends BaseStream<T, Stream<T>> { ... public static<T> Stream<T> of(T... values) { return Arrays.stream(values); } ... }
  • 27.
  • 28. java.util.function • Java 8 comes with several functional interfaces in package, java.util.function: – Function<T,R> - takes an object of type T and returns R; – Supplier<T> - just returns an object of type T; – Predicate<T> - returns a boolean value based on input of type T; – Consumer<T> - performs an action with given object of type T; – BiFunction - like Function but with two parameters; – BiConsumer - like Consumer but with two parameters; – BinaryOperator<T> - take two T's as input, return one T as output, useful for "reduce" operations. • It also comes with several corresponding interfaces for primitive types, such as: – IntConsumer – IntFunction<R> – IntPredicate – IntSupplier
  • 29. Stream API • New Java 8 Stream API provides utilities to support functional-style operations on streams of values. • A stream is something like an iterator. The values “flow past” (analogy to a stream of water) and then they're gone. A stream can only be traversed once, then it's used up. Streams may also be infinite.
  • 30. Stream API • There are two types of Streams: – Sequential: The actions of a sequential stream occur in serial fashion on one thread. – Parallel: The actions of a parallel stream may be happening all at once on multiple threads. • Usually, dealing with a stream will involve these steps: 1. Obtain a stream from some source; 2. Perform one or more intermediate operations; 3. Perform one terminal operation.
  • 31. Stream API • Threre are two operation types of Streams: – Intermediate: An intermediate operation keeps the stream open and allows further operations to follow. – Lazy operations (e.g. filter, map, flatMap, peek, distinct, sorted, limit e substream) – Terminal: A terminal operation must be the final operation invoked on a stream. Once a terminal operation is invoked, the stream is "consumed" and is no longer usable. (e.g. forEach, toArray, reduce, collect, min, max, count, anyMatch, allMatch, noneMatch, findFirst e findAny)
  • 32. Stream API • There are a couple more general properties of stream operations to consider: – Stateful: imposes some new property on the stream, such as uniqueness of elements, or a maximum number of elements, or ensuring that the elements are consumed in sorted fashion. These are typically more expensive than stateless intermediate operations. – Short-circuiting : allows processing of a stream to stop early without examining all the elements. This is an especially desirable property when dealing with infinite streams; if none of the operations being invoked on a stream are short-circuiting, then the code may never terminate.
  • 33. Stream API • Examples: int sumOfWeights = blocks.stream() .filter(b -> b.getColor() == RED) .mapToInt(b -> b.getWeight()) .sum(); Stream<Person> first4females = people.stream() .peek(System.out::println) .filter(p -> p.getGender().equals("F")) .distinct() .limit(4);
  • 34.
  • 35. Repeating and Type Annotations • Java 8 will allow annotations to be repeated. // the first of the month and every monday at 7am @Schedule(dayOfMont = "first") @Schedule(dayOfWeek = "Monday", hour = 7) public void doGoblinInvasion() { ... } • To do this there is a new method called obj.getAnnotationsByType(Class annotationClass) on Class, Constructor, Method, etc. It returns an array of all such annotations (or an empty array if there are none).
  • 36. Repeating and Type Annotations • In Java 8, annotations can also be applied to the use of types. This new ability is primarily aimed at supporting type-checking frameworks, such as Checker. These frameworks help find errors in your code at compile time. // Class instance creation: new @Interned RocketShip(); // Type cast: notNullString = (@NonNull String) str; // implements clause: class ImmutableSet<T> implements @Readonly Set<@Readonly T> { ... } // Thrown exception declaration: void launchRocket() throws @Critical FireException { ... }
  • 37. New Java Date/Time API • Java 8 introduces a new Date/Time API that is safer, easier to read, and more comprehensive than the previous API. • Java’s Calendar implementation has not changed much since it was first introduced and Joda-Time is widely regarded as a better replacement.
  • 40. New Java Date/Time API • Example: // Old way Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR, cal.get(Calendar.HOUR) + 2); // New Way LocalTime now = LocalTime.now(); LocalTime later = now.plus(2, ChronoUnit.HOURS);
  • 41. New Java Date/Time API • For timezone specific times you use ZonedDateTime. // Leaving from San Francisco on July 20, 2013, at 7:30 p.m. LocalDateTime leaving = LocalDateTime.of(2013, Month.JULY, 20, 19, 30); ZoneId leavingZone = ZoneId.of("America/Los_Angeles"); ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone); // Flight is 10 hours and 50 minutes, or 650 minutes ZoneId arrivingZone = ZoneId.of("Asia/Tokyo"); departure.withZoneSameInstant(arrivingZone).plusMinutes(650); // Checks if the specified instant is in daylight savings. if (arrivingZone.getRules().isDaylightSavings(arrival.toInstant())) // LEAVING: Jul 20 2013 07:30 PM (America/Los_Angeles) // ARRIVING: Jul 21 2013 10:20 PM (Asia/Tokyo) (Asia/Tokyo standard time will be in effect.)
  • 42. New Java Date/Time API • Enums – Java 8 adds several enums, such as LocalDateTimeField and LocalPeriodUnit, for expressing things like “days” and “hours” instead of the integer constants used in the Calendar API. • Clock – The Clock can be used in conjunction with dates and times to help build your tests. During production a normal Clock can be used, and a different one during tests. //To get the default clock, use the following: Clock clock = Clock.systemDefaultZone(); //The Clock can then be passed into factory methods; LocalTime time = LocalTime.now(clock);
  • 43. New Java Date/Time API • Working with time zones ZoneId zone = ZoneId.systemDefault(); Clock clock = Clock.system(zone); // America/Sao_Paulo ZoneId zone = ZoneId.of("Europe/Berlin"); Clock clock = Clock.system(zone); // Europe/Berlin Set<String> availableZoneIds = ZoneId.getAvailableZoneIds(); // [Asia/Aden, America/Cuiaba, Etc/GMT+9, Etc/GMT+8,...
  • 44. New Java Date/Time API • Doing calculations with times and dates Period days = Period.ofDays(5); LocalTime time = LocalTime.now(); // 15:15:45.562 time.plus(5, ChronoUnit.DAYS); // throws UnsupportedTemporalTypeException: Unsupported unit: Days time.plus(5, ChronoUnit.HOURS); // 20:15:45.562
  • 45. New Java Date/Time API • Period parse exploring: Period parse = Period.parse("P5D"); // Period.ofDays(5) – For example, the following are valid inputs: "P2Y" // Period.ofYears(2) "P3M" // Period.ofMonths(3) "P4W" // Period.ofWeeks(4) "P1Y2M3D" // Period.of(1, 2, 3) "P1Y2M3W4D" // Period.of(1, 2, 25) "P-1Y2M" // Period.of(-1, 2, 0) "-P1Y2M" // Period.of(-1, -2, 0)
  • 46. New Java Date/Time API • Fluent Date and Time API: // calculate the payday LocalDate today = LocalDate.now(); today.with(TemporalAdjusters.lastDayOfMonth()).minusDays(2); // immutable LocalDate dateOfBirth = LocalDate.of(2012, Month.MAY, 14); LocalDate firstBirthday = dateOfBirth.plusYears(1);
  • 47. New Java Date/Time API • Different display name types: DayOfWeek dow = DayOfWeek.MONDAY; Locale locale = Locale.getDefault(); dow.getDisplayName(TextStyle.FULL, locale); // Monday dow.getDisplayName(TextStyle.NARROW, locale); // M dow.getDisplayName(TextStyle.SHORT, locale); // Mon //It is a valid year? MonthDay date = MonthDay.of(Month.FEBRUARY, 29); boolean boolean validLeapYear = date.isValidYear(2010); // Is leap year? boolean validLeapYear = Year.of(2012).isLeap();
  • 48. New Java Date/Time API • Method naming conventions
  • 49. New Java Date/Time API • Interoperability with Legacy Code – Calendar.toInstant() converts the Calendar object to an Instant. – GregorianCalendar.toZonedDateTime() converts a GregorianCalendar instance to a ZonedDateTime. – GregorianCalendar.from(ZonedDateTime) creates a GregorianCalendar object using the default locale from a ZonedDateTime instance. – Date.from(Instant) creates a Date object from an Instant. – Date.toInstant() converts a Date object to an Instant. – TimeZone.toZoneId() converts a TimeZone object to a ZoneId.
  • 50.
  • 51. Java API additions • API additions – Collections – Concurrency – IO/NIO – Reflection and annotation changes – Other miscellaneous additions to java.lang, java.util, and elsewhere http://www.techempower.com/blog/2013/03/26/everything-about-java-8/ • JDBC 4.2 (Rowset 1.2, REF_CURSOR support, etc.) http://docs.oracle.com/javase/8/docs/technotes/guides/jdbc/jdbc_42.html
  • 52. Optional • Java 8 comes with the Optional class in the java.util package for avoiding null return values (and thusNullPointerException). • Tony Hoare, the invention of the null reference in 1965 for the ALGOL W programming language. He calls The Billion Dollar Mistake. • Used in the Stream API or custom implementation
  • 53. Optional • Examples: //Creating an instance of Optional using the factory method. Optional<String> name = Optional.of("Puppy"); name.orElse("Bob") //This fails with a NullPointerException. Optional<String> someNull = Optional.of(null); //This fails with a NoSuchElementException Optional<String> someNull = Optional.ofNullable(null); someNull.get();
  • 54.
  • 55. Nashorn JS Engine • Nashorn replaces Rhino as the default JavaScript engine for the Oracle JVM. • Nashorn is much faster since it uses the invokedynamic feature of the JVM. It also includes a command line tool (jjs). • Java Platform, Standard Edition Nashorn User's Guide http://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/ • Command line Nashorn: jjs script.js
  • 56. Nashorn JS Engine • Hello World: var hello = function() { print("Hello Nashorn!"); }; hello();
  • 57. Nashorn JS Engine • Examples: var data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; var filtered = data.filter(function(i) { return i % 2 == 0; }); print(filtered); var sumOfFiltered = filtered.reduce(function(acc, next) { return acc + next; }, 0); print(sumOfFiltered);
  • 58. Nashorn JS Engine • Examples: var imports = new JavaImporter(java.util, java.io, java.nio.file); with (imports) { var paths = new LinkedList(); print(paths instanceof LinkedList); //true paths.add(Paths.get("/")); paths.add(Paths.get("/home")); paths.add(Paths.get("/tmp")); print(paths); // [/, /home, /tmp] }
  • 59. Nashorn JS Engine • Call from Java Class: ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("nashorn"); Reader reader = new FileReader("/home/fmamud/script.js"); engine.eval(reader); // prints: 2,4,6,8,10 30
  • 60.
  • 61. Other stuffs • jdeps – In JDK 8, a new command-line tool, jdeps, is added that developers can use to understand the static dependencies of their applications and libraries. – Java Platform, Standard Edition Tools Reference http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html – Usage: jdeps <options> <classes...> where <classes> can be a pathname to a .class file, a directory, a JAR file, or a fully-qualified class name.
  • 62. // monitoracao-v1.4b.jar.dot digraph "monitoracao-v1.4b.jar" { // Path: monitoracao-v1.4b.jar "br.com.bradesco.monitoracao" -> "java.io"; "br.com.bradesco.monitoracao" -> "java.lang"; "br.com.bradesco.monitoracao" -> "java.lang.reflect"; "br.com.bradesco.monitoracao" -> "java.net"; "br.com.bradesco.monitoracao" -> "java.sql"; "br.com.bradesco.monitoracao" -> "java.text"; "br.com.bradesco.monitoracao" -> "java.util"; "br.com.bradesco.monitoracao" -> "javax.naming"; "br.com.bradesco.monitoracao" -> "javax.sql"; "br.com.bradesco.monitoracao" -> "log.c.apis (BRS000A2.jar)"; "br.com.bradesco.monitoracao" -> "util.dataAccess.jdbc (not found)"; } Other stuffs – Example: > jdeps -dotoutput . monitoracao-v1.4b.jar BRS000A2.jar // BRS000A2.jar.dot digraph "BRS000A2.jar" { // Path: BRS000A2.jar "log.c.apis" -> "java.io"; "log.c.apis" -> "java.lang"; "log.c.apis" -> "java.net"; "log.c.apis" -> "java.sql"; "log.c.apis" -> "java.util"; "log.c.apis" -> "javax.naming"; "log.c.apis" -> "javax.sql"; } //summary.dot digraph "summary" { "monitoracao-v1.4b.jar“ -> "BRS000A2.jar"; "monitoracao-v1.4b.jar“ -> "not found"; "monitoracao-v1.4b.jar“ -> "rt.jar"; "BRS000A2.jar“ -> "rt.jar"; }
  • 63. Other stuffs • No More Permanent Generation – Most allocations for the class metadata are now allocated out of native memory. This means that you won’t have to set the “XX:PermSize” options anymore (they don’t exist). – This also means that you will get a “java.lang.OutOfMemoryError: Metadata space” error message instead of “java.lang.OutOfMemoryError: Permgen space” when you run out of memory. – This is part of the convergence of the Oracle JRockit and HotSpot JVMs.
  • 64. Other stuffs • Compact profiles – Java 8 will define subset profiles of the Java SE platform specification that developers can use to deploy. Compact1 have less than 14MB; Compact2 is about 18MB; Compact3 is about 21MB. For reference, the latest Java 7u21 SE Embedded ARMv5/Linux environment requires 45MB. • An Introduction to Java 8 Compact Profiles – https://blogs.oracle.com/jtc/entry/a_first_look_at_compact
  • 65. Useful links • What's New in JDK 8 http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html • JDK 8 Adoption Guide http://www.oracle.com/technetwork/java/javase/jdk8-adoption-guide- 2157601.html • Compatibility Guide for JDK 8 http://www.oracle.com/technetwork/java/javase/8-compatibility-guide- 2156366.html
  • 66. References • Everything about Java 8 http://www.techempower.com/blog/2013/03/26/everything-about-java-8/ • Java 8 Lambda Expressions Tutorial With Examples http://viralpatel.net/blogs/lambda-expressions-java-tutorial/ • Java SE 8: Lambda Quick Start http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda- QuickStart/index.html