Java 8 Tuto

Share Embed Donate


Short Description

JAVA 8 Features...

Description

 Table  Table Of Contents

1. Introduction 2. New Features in Java language

2.1. Lambdas and Functional Functional Interfaces 2.2. Interface Default and tatic !et"ods 2.#. !et"od $eferences $eferences 2.%. $e&eating $e&eating annotations 2.'. (etter T)&e Inference Inferenc e 2.*. +,tended -nnotations u&&ort

#. New Features in Java com&iler

#.1. arameter names

%. New Features in Java libraries

%.1. O&tional %.2. treams %.#. Date/Time -I 0J$ #1 %.%. Nas"orn Javacri&t engine %.'. (ase*% %.*. arallel -rra)s %.3. Concurrenc)

'. New Java tools

'.1. Nas"orn engine4 55s '.2. Class de&endenc) anal)6er4 5de&s

*. New Features in Java runtime 0J7! 3. Conclusions 8. $esources

1. Introduction

9it" no doubts: Java 8 release is t"e greatest t"ing in t"e Java world since Java ' 0released ;uite a w"ile ago: bac< in 2%. It brings tons of new features to t"e Java as a language: its com&iler: libraries: tools and t"e J7! 0Java virtual mac"ine itself. itself. In t"is tutorial we are going to taguration 1 /&lugin

Latest +cli&se Ye&ler $2 release wit" Java 8 0&lease c"ec< out t"is download instructions su&&ort &rovides useful con>guration o&tion to control t"is com&iler setting as t"e &icture below s"ows. icture 1. Con>guring +cli&se &ro5ects to su&&ort new Java 8 com&iler B&arameters argument.

icture 1. Con>guring +cli&se &ro5ects to su&&ort new Java 8 com&iler B&arameters argument.

-dditionall): to verif) t"e availabilit) of &arameter names: t"ere is a "and) met"od isNameresent0 &rovided b) arameter class.

%. New Features in Java libraries

 Java 8 adds a lot of new classes and e,tends e,isting ones in order to &rovide better su&&ort of modern concurrenc): functional &rogramming: date/time: and man) more. %.1. O&tional

 T"e famous Nullointer+,ce&tion is b) far t"e most &o&ular cause of Java a&&lication failures. Long time ago t"e great ?oogle ?uava &ro5ect introduced t"e O&tionals as a solution to Nullointer+,ce&tions: discouraging codebase &ollution wit" null c"ecrstName.isresent0 E # )stem.out.&rintln0 First Name4   >rstName.or+lse?et0 0 A PnoneQ  E % )stem.out.&rintln0 >rstName.ma&0 s A e)   s  W .or+lse0 e) trangerW  E ' )stem.out.&rintln0E

-nd "ere is t"e out&ut4 1 First Name is setX true 2

First Name4 Tom # e) TomW

For more details &lease refer to ocial documentation. %.2. treams

 T"e newl) added tream -I 05ava.util.stream introduces realAworld functionalAst)le &rogramming into t"e Java. T"is is b) far t"e most com&re"ensive addition to Java librar) intended to macantl) more &roductive b) allowing t"em to write e=ective: clean: and concise code.

tream -I maed 0but it is not limited to  Java collections onl) as we will see later. Let us tarst ;uestion we are going to address is "ow man) &oints in total all O+N tasnal tring te,t  (ase*% >nall) in Java 8WE M

1 >nal tring encoded  (ase*% 11  

.get+ncoder0

12 .encodeTotring0 te,t.get()tes0 tandardC"arsets.UTFR8  E 1# )stem.out.&rintln0 encoded E 1%

1' >nal tring decoded  new tring0 1* (ase*%.getDecoder0.decode0 encoded : 13 tandardC"arsets.UTFR8 E

18 )stem.out.&rintln0 decoded E 1M H 2 H

 T"e console out&ut from &rogram run s"ows bot" encoded and decoded te,t4 1 ]mF6\TI?\&bmFsbnall) in Java 8W

 T"ere are also U$LAfriendl) encoder/decoder and !I!+Afriendl) encoder/decoder &rovided b) t"e (ase*% class 0(ase*%.getUrl+ncoder0 / (ase*%.getUrlDecoder0: (ase*%.get!ime+ncoder0 / (ase*%.get!imeDecoder0. %.*. arallel -rra)s

 Java 8 release adds a lot of new met"ods to allow &arallel arra)s &rocessing. -rguabl): t"e most im&ortant one is &arallelort0 w"ic" ma) signi>cantl) s&eedu& t"e sorting on multicore mac"ines. T"e following small e,am&le demonstrates t"is new met"od famil) 0&arallel^,, in action. 1 &acrst 1 elements before and after sorting so to ensure t"e arra) is reall) ordered.  T"e sam&le &rogram out&ut ma) loo< lile func.5s wit" following content4 1 function f0 G 2 return 1E # HE %

' &rint0 f0  1 E

 To e,ecute t"is >e from command: let us &ass it as an argument to 55s4 1  55s func.5s

 T"e out&ut on t"e console will be4 1 2

For more details &lease refer to ocial documentation. '.2. Class de&endenc) anal)6er4 5de&s

 5de&s is a reall) great command line tool. It s"ows t"e &acles. It acce&ts .class >le: a director): or J-$ >le as an in&ut. () default: 5de&s out&uts t"e de&endencies to t"e s) stem out&ut 0console.

-s an e,am&le: let us tale4 org.s&ringframewor
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF