Skip to main content

Posts

RAML?

RAML is an open source specification for DESCRIBING APIs  • RAML is surrounded by an open source community with over 100 projects in 12 programming languages • RAML is backed by a working group consisting members from MuleSoft, Akana, Cisco, Intuit, Airware, VMware, ProgrammableWeb, and Angular.js • RAML is used commercially by thousands of companies including Spotify, Cisco, VMware, PBS, Sonic, and more what can you do with RAML? You can define your API in just a few lines of code •  You can see what it would look like as you go •  You can quickly prototype it for devs to try  • You can quickly make tweaks/ changes  • You can easily document your API  • You can let developers try your API online  • You can let developers interact with your and other APIs  • Generate SDKs/ client libraries for your API     
Recent posts

RAML 1.0 Mulesoft

                                                                                                                                                        

Lambda Expressions: Method References:

Method references are short hand of lambda expression. It is an easy way to delegate a call to an existing method. The method is referenced by using the class name or the object reference with :: separating the method name e.g. We can call System.out.println with a below statement: List < Integer > numbers = Arrays . asList ( 1 , 2 , 3 , 4 , 5 , 6 ); numbers . forEach ( System . out :: println ); package com.corejava.LambdaExpressions.examples; //method references are short hand of lambda expression public class MethodReferences { interface IMovie { Boolean check(Integer id); } private void testMovieStaticMethodRef() { IMovie movie1 = (i) -> i < 100 ; // movie id less than 100 are classic movies IMovie movie2 = MethodReferences:: isClassic ; System. out .println(movie1.check( 100 )); System. out .println(movie2.check( 99 )); } private void testMovieInstanceMethodRef() { IMovie movie1 =

Java 8:Lambda Expression Hello World Example.

We have written a simple HelloWorldLambdas class to illustrate the usage of lambda Expression. We have declared an interface Greeting with a single abstract method sayHello. A testGreetingmethod with parameters as String and Greeting . From the main class we instantiate the HelloWorldLambdas class to invoke the test Greeting with lambda expression. package com.consciousprogramming.LambdaExpressions.examples; public class HelloWorldLambdas { interface Greeting{ String sayHello(String greeting); } public void testGreeting(String input, Greeting greeting){ String result= greeting.sayHello(input); System. out .println(result); } public static void main(String [] args){ new HelloWorldLambdas().testGreeting( "World" ,(s)-> "Hello " +s); new HelloWorldLambdas().testGreeting( "" ,(s)->s.isEmpty()? "Input not provided" : "Hello" +s); } }

Java 8:Lambda Expression Syntax

Lambda Expression Syntax A lambda expression is composed of three parts. Argument List Arrow Token Body (int x, int y) -> x + y The body can be either a single expression or a statement block. In the expression form, the body is simply evaluated and returned. In the block form, the body is evaluated like a method body and a return statement returns control to the caller of the anonymous method.  The  break  and  continue  keywords are illegal at the top level, but are permitted within loops. If the body produces a result, every control path must return something or throw an exception. Input arguments, body and return :(input arguments)->body    Left hand side is input arguments    Right hand side is logic.    The Arrow token is the separator between the arguments and logic, Return Values:  Implicit return; Simple expression does not requires a return  Explicit return: If it is complex code , we need to explicit mention a return. Examples of Lambda

Java 8:What are Lambda Expressions ?

Java is an object oriented programming language.  Everything in Java language is an Object. A variable or method or a block of code can not exist of it own. A class is building block , a fundamental structure from which we create and use an object. All methods and variables are tied to a class. A class must be instantiate so that you can invoke methods appropriately. Even if a single line of business logic, it must be written in a method, declared in a class, instantiate a class and invoke the method on that object.In pre Java 8 we can't have free floating code of expression.Also mutability is inherent in java language, java does not put restriction on mutability,  it is upto developer responsibility to create immutable methods. What are Lambda Expressions? Lambda expressions are a new and important feature included in Java SE 8.Lambda Expressions are blocks of code that represents behaviour which can be passed around to other methods. This pieces allows us to functional progra