java 8 new features

Post on 19-Jan-2015

211 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

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

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

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

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.

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.

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.

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')"); }}

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

2.1 Java memory model

2.2 Heap vs Stack

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

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)

3.5 Why have to remove permanent generation ?

•Why?•Demo to be continued...

3. Array.ParallelSort in JAVA 8

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

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);}

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.

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.

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 |

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

top related