Posts

Showing posts with the label functional programming

Method References In JAVA 8

Method References :     Method reference is an important feature related to lambda expressions. It provides a way to a method without executing it. In order to that a method reference requires a target type context that consists of a compatible functional interface. Similar to lambda expressions, a method reference when evaluated creates an instance of the functional interface. The 3 types of method references are, 1. Static Method References. 2. Instance Method References Of Objects. 3. Instance Method References Of Classes. In the first two types, the method reference is equivalent to a lambda expression on which parameters of a method will be supplied. In the 3rd type, the 1st parameter of a method becomes the target of the method and second parameter becomes argument to the method just like s1.equals(s2); . Static Method References :  The syntax for static method references is ClassName :: methodName Lets see a simple example to understand st...

The "Hello, World" Program In Scala

Image
    While learning any programming language, we were used to execute a program that prints "Hello, World" as the first program . Here is the standard Hello World program using Scala. object HelloWorld {     def main(args : Array[String]) {       println("Hello, world!")     } } If you are coming from java, this program can be compared with the below java "Hello World" program. public class HelloWorld {      public static void main(String[] args) {           System.out.println("Hello, World!");      } } Both Java, & scala requires main method with String arguments, in order to execute the program. The method definition is slightly different in Scala, when compared to Java, as you can see in the above programs. In any application we will have only one public class with a main method. This is conceptually similar to singleton pattern. So in Scala , you can define singl...