Java 8 Tutorial: Arrays.parallelSort

Java 8 Tutorial: Arrays.parallelSort Trước Java 8, chúng ta thường dùng phương thức Arrays.sort để sắp xếp một array. Trong Java 8 chúng ta có thêm một lựa chọn nữa đó là phương thức Arrays.parallelSort. Về mặt giải thuật, cả 2 phương thức đều dùng phương pháp sắp xếp trộn (merge sort) để sắp xếp … Continue reading Java 8 Tutorial: Arrays.parallelSort

Java 8 Tutorial: Optional

Java 8 Tutorial: Optional Optional là 1 container được giới thiệu trong Java 8, theo quảng cáo của Oracle thì nó sẽ giúp cho các lập trình viên tránh được cơn ác mộng NullPointerException. Nhưng theo mình thấy thì thay vì kiểm tra null bằng cách thông thường, Optional cung cấp 1 số hàm, tiện … Continue reading Java 8 Tutorial: Optional

Java 8 Tutorial: Method Reference

Java 8 Tutorial: Method Reference Đi cùng với Lambda Expression, Java 8 có thêm một khái niệm mới là Method Reference. Chúng ta thường dùng Lambda Expression để tạo ra các method vô danh (anonymous method), nhưng đôi lúc Lambda Expression cũng có thể tham chiếu đến các phương thức có sẵn để thực thi. … Continue reading Java 8 Tutorial: Method Reference

Java 8 Tutorial: Default Method

Java 8 Tutorial: Default Method Java 8 giới thiệu một tính năng mới là Default Method. Nó cho phép thêm mới các method mới vào interface có sẵn mà các lớp con không cần phải implement lại method nó. Giúp cho cấu trúc của chương trình không bị phá vỡ. Ví dụ: Kết quả: Như … Continue reading Java 8 Tutorial: Default Method

Java 8 Tutorial: Functional Interface

Java 8 Tutorial: Functional Interface Trong Java, xuất hiện một khái niệm mới là SAM (Single Abstract Method) hay còn gọi là Functional Interface. Functional Interface thực chất là 1 Interface với duy nhất 1 abstract method (method không có phần body). Có thể các bạn sẽ tự hỏi Interface thì làm gì có các … Continue reading Java 8 Tutorial: Functional Interface

Java 8 tutorial: Cơ bản về Lambda Expression

Java 8 tutorial: Cơ bản về Lambda Expression Cuối cùng thì Lambda Expression đã xuất hiện trong phiên bản J2SE 8. Nếu đã làm qua các ngôn ngữ khác như: C#, Ruby, các bạn có thể đã biết được Lambda Expression là gì. Trong Java, xuất hiện một khái niệm mới là SAM (Single Abstract … Continue reading Java 8 tutorial: Cơ bản về Lambda Expression

Hướng dẫn lập trình Java 8 trên Eclipse

Hướng dẫn lập trình Java 8 trên Eclipse Để lập trình trên Java 8 trên Eclipse, các bạn cần làm 1 số việc như sau: Download JDK 8 Download Eclipse version suports Java 8 Tạo 1 project và test Trước tiên, các bạn vào trang chủ Oracle để download bộ JDK mới nhất về và … Continue reading Hướng dẫn lập trình Java 8 trên Eclipse

Exception Handling Templates in Java

Correct Error Handling is Tedious to Write Correct exception handling code can be tedious to write. Try-catch blocks also clutter the code and makes it harder to read. Look at the example below: In this example no exceptions are lost. If an exception is thrown from within the try block, and another exception is thrown … Continue reading Exception Handling Templates in Java

Java 8 explained: Default Methods

In a previous post, we looked into lambdas in Java 8 which proved to be a very popular topic. Now we continue our peek into new Java 8 features by continuing with default methods. Those are closely related to lambdas, which could be the main theme of Java 8. In this article, we’ll take a look at what default methods … Continue reading Java 8 explained: Default Methods