Posts

Showing posts from February, 2017

Java 8 - Default Methods and Enhanced Stream API

Image
In this post we'll talk about Java 8 default methods and new stream API.First let's go back and talk about how previous Java versions handled interfaces and what are the rules applied.For that we'll implement simple intrface which gives us time details. public interface TimeClient {     void setDateAndTime(int day, int month, int year, int hour, int minute, int second);     LocalDateTime getLocalDateTime(); } As you can see all the methods are abstract and do not have a method body.Let's implement this interface in a class and add method bodies to the methods. public class SimpleTimeClient implements TimeClient {     private LocalDateTime dateAndTime;     public SimpleTimeClient() {         dateAndTime = LocalDateTime.now();    }    public void setDateAndTime(int day, int month, int year, int hour, int minute, int second) {         LocalDate dat...

In to the wild..!! (Cross-platform mobile application development)

Image
Let's discuss about something interesting (not related to Java) today." Cross-platform mobile application development" . I got an opportunity to look into cross platform application development and I thought of sharing the knowledge I gathered with you as there are no sufficient amount of tutorials online on how to start cross platform application development. Cross-platform mobile development is the creation of  apps  that are compatible with multiple  mobile operating systems . Originally, the complexity of developing mobile apps was compounded by the difficulty of building out a back end that worked across multiple platforms. Although it was time consuming and expensive, it was often easier to build  native applications  for each  mobile operating system  (OS), even though very little code that was written for each operating system could be re-purposed . There are several tools in the market that we can use to develop cross platform mobile ap...

Java 8 - Method references

Image
We'll add another field to our simple student management application. LocalDate birthday; Now the constructor of the class would look like this. Person(){} Person(String name, String emailAddress, int age, Sex gender,LocalDate birthday) {         this.name = name;         this.emailAddress = emailAddress;         this.age = age;         this.gender = gender;         this.birthday = birthday;  } We'll modify our student database with the new field. List<Person> peeps=new ArrayList<>(); LocalDate today=LocalDate.now(); peeps.add(new Person("Hasitha","hasitha@gmail.com",23,Sex.MALE,today)); peeps.add(new Person("Nadishan","nadishan@gmail.com",25,Sex.MALE,today.plus(1, ChronoUnit.DAYS))); peeps.add(new Person("Jayasundara","jayasundara@gmail.com",18,Sex.MALE,today.minusDays(2))); Somebody may tell you "Hey can you sort the students according to their b...

Java 8 - Lambda Expressions

Image
We'll do something interesting today.Let's make a simple student management application which you can insert students,get the information of the students and filter them according to the given conditions.First let's create the basic Person class which is going to help us in entering,getting and filtering student details. public class Person {    public enum Sex {         MALE, FEMALE     }     String name;     Sex gender;     String emailAddress;     int age;     Person(){}     Person(String name, String emailAddress, int age, Sex gender) {         this.name = name;         this.emailAddress = emailAddress;         this.age = age;         this.gender = gender;     }     public String getName() {         return name;     }     p...