Skip to main content

Posts

Introduction

Groovy Declarative Style Code [1,2,3,4,5].findAll { it % 2 == 0 }.each() {value->println "${value*2}"}; There are lot of way to address this stuff in Java 8. So let’s have a look to do the same stuff in Java 8 Example:- import java.util.Arrays ; import java.util.List ;   class DeclarativeStyle {     public static void main(String []args){         List numbers = Arrays.asList(1,2,3,4, 5, 6);           numbers.stream()                          //A Fancy Collection            .filter(DeclarativeStyle::isEven)      //Filter the data            .map(DeclarativeStyle::doubleInteger) //Map new values            .forEach( System.out::println );         //Iterate & perform the operation     }       public static String doubleInteger(Integer number){         return String.valueOf(number * 2);     }       public static Boolean isEven(Integer number){         return number%2==0;     } } The first three method calls are just lazy ca
Recent posts

What is declarative programming?

•         Here code is written in such a way that it describes what you want to do, and not how you want to do it. It is left up to the compiler to figure out the how. •         Often defined as any style of programming that is not imperative. •         The program is built from one or more procedures •         It provides a programmer a means to define precisely each step in the performance of a task. Declarative programming contrasts with imperative and procedural programming. Declarative programming is a non-imperative style of programming in which programs describe their desired results without explicitly listing commands or steps that must be performed. Functional and logical programming languages are characterized by a declarative programming style. In logical programming languages, programs consist of logical statements, and the program executes by searching for proofs of the statements. Examples •         Example :-    SQL , Prolog , Alpha , Brooks ,