Top Banner
JAVA 8 New Features Presenters: ●Nguyen Van Tan ●Nguyen Van Ngoc ●Nguyen Van Vu ●Tran Duc Toan
21

Java 8 new features

Jan 19, 2015

Download

Technology

Framgia Vietnam

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Java 8 new features

JAVA 8 New FeaturesPresenters:●Nguyen Van Tan●Nguyen Van Ngoc●Nguyen Van Vu●Tran Duc Toan

Page 2: Java 8 new features

Members1. Nguyễn Văn Tân2. Tran Duc Toan3. Nguyễn Văn Ngọc4. Nguyễn Ngọc trần anh5. Nguyễn Văn Vụ6. Đỗ Xuân Đức7. Phạm Trí Thái8. Bùi Quý Dương9. Trần Ngọc Thắng

Page 3: Java 8 new features

Main Presents

1.Nashorn Javascript Engine2.Remove The Permanent generation3.Array ParallelSort4.Lambda expressions5.Small VM6.Bulk Data Operations for Collections7.Define a standard API for Base64 encoding and decoding8.New Date & Time API9.Provide stronger Password-Based-Encryption (PBE) algorithm implementations in the SunJCE provider

Page 4: Java 8 new features

1.1 Nashorn Java Script Engine.1.What’s Nashorn?2.Why we need develop new Script Engine(Nashorn)?3.How to use new Nashorn Engine?4.Example.

Page 5: Java 8 new features

1.2 What’s Nashorn?- Nashorn is a JavaScript engine developed in the Java programming language by Oracle. It is based on the Da Vinci Machine (JSR 292) and will be released with Java 8, which has been rescheduled for a 2014 release date- Nashorn (the German word for rhinoceros) -> Rhino is an Javascript Engine was build by Netscape in 1997. - Nashorn execute base on InvokeDynamic byte code was introduce in java7.

Page 6: Java 8 new features

1.3 Why need new Javascript Engine?- The Peformance of Rhino Script Engine was slow.- Rhino java script engine was too old (build in 1997)- Need a brigde between java and javascripts to help using java and javascript more easy than.

Page 7: Java 8 new features

1.4 How to use Nashorn Engine?-Import javax.script.* package.- create New Nashorn Script Engine by use ScriptEngineManager Class.- execute a javascript code by script engine VD:import javax.script.*; public class EvalScript { public static void main(String[] args) throws Exception { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("nashorn"); // evaluate JavaScript code engine.eval("print('Hello, World')"); }}

Page 9: Java 8 new features

2. Remove permanent generation“java.lang.OutOfMemoryError: PermGen space”

Page 10: Java 8 new features

2.1 Java memory model

Page 11: Java 8 new features

2.2 Heap vs Stack

Page 12: Java 8 new features

2.3 What’s permanent used for ?•- Originally there was no permanent generation. Objects and classes were just stored together•- Classes were mostly static, custom class loaders were not widely used and so it was observed that not much class unloading occurred• - As a performance optimization the permanent generation was created and classes were put into it - The performance improvement was significant back then

Page 13: Java 8 new features

2.4 Permanent generation stores what ?•- Methods of a class (including the bytecodes)

•- Names of the classes

•- Object arrays and type arrays associated with a class (e.g., an object array containing references to methods)•- Internal objects created by the JVM (java/lang/Object or java/lang/exception

for instance)

•- Information used for optimization by the compilers (JITs)

Page 14: Java 8 new features

3.5 Why have to remove permanent generation ?

•Why?•Demo to be continued...

Page 16: Java 8 new features

3. Array.ParallelSort in JAVA 8

- Reintroduce Array.Sort- Introduce Array.ParallelSort- Demo- Reference doc

Page 17: Java 8 new features

3.1 About Array.Sort

Array.Sort is a API use MergeSort or TimSort object or primitive arrays. public static void sort(Object[] a) {

if (LegacyMergeSort.userRequested)legacyMergeSort(a);

else ComparableTimSort.sort(a);}

Page 18: Java 8 new features

3.2 Array.ParallelSort

Arrays#parallelSort uses Fork/Join framework (in Java 7) to assign the sorting tasks to multiple threads available in the thread pool.The implementation in JDK 8 uses this approach:- Divide the array into 4 parts.- Sort the first two parts and then merge them.- Sort the next two parts and then merge them.

Page 19: Java 8 new features

3.3 ParallelSort

And the above steps are repeated recursively with each part until the size of the part to sort is not lesser than the threshold value calculated above.

Page 20: Java 8 new features

3.4 Compare result Demo------------------------------------------------------------------| Seq | Array size | Sort time | VS | PSort time |------------------------------------------------------------------| 1 | 602 | 0.002 | < | 0.008 |------------------------------------------------------------------| 2 | 1400 | 0.006 | > | 0.004 |------------------------------------------------------------------| 3 | 2492 | 0.008 | > | 0.006 |------------------------------------------------------------------| 4 | 4984 | 0.012 | > | 0.008 |

Page 21: Java 8 new features

3.5 Reference.● http://blog.sanaulla.info/2013/04/08/arrays-sort-versus-arrays-parallelsort/