Submitted by heartin on Mon, 06/13/2016 - 21:35
Before Java 8, you could only use final variables from a surrounding class in an anonymous inner class. In Java 8, within anonymous class (or lambda expressions) you can use effectively final variables: not declared as final but only assigned once.
Important points about accessing variables from within an anonymous inner class (or lambda expression)
Submitted by heartin on Mon, 06/13/2016 - 21:25
Java 8 allows you to write lambda expressions in few varying syntaxes. Let us quickly see those here.
With no arguments
Runnable r = () -> System.out.println(“H”);
Only one argument: with or without parenthesis
ActionListener al1 = (event) -> System.out.println(“Button clicked”);
ActionListener al2 = event -> System.out.println(“Button clicked”);
Submitted by heartin on Mon, 06/13/2016 - 21:19
Lambda expressions implement an interface with only one single abstract methodl. Such interfaces are called as functional interfaces. Since the interface has only one single method (function), passing across that interface implementation gives the impression of passing across that function. Already existing interfaces in Java such as Runnable, Comparator, ActionListener are already functional interfaces, as they have only one abstract method. We will see how we can use lambda expressions with those existing interfaces.
Submitted by heartin on Mon, 06/13/2016 - 21:05
Before Java 8, interfaces could only have abstract methods and constants. Java 8 allows you to have default as well as static methods inside an interface. This was mainly done for interface unlocking: Now you can add methods to an interface without needing the implementing classes to change.
You can add an instance method to an interface through the keyword default.
They are also public similar to the abstract methods.
Default methods are inherited by subclasses and can be overriden.
Submitted by heartin on Mon, 06/13/2016 - 20:45
Method references or constructor references can be used to refer to an existing method or constructor by name. Classes containing these methods can be regular classes without the need to implement or extend anything. However, the target type needs to be a functional interface, as the signature of the method is infered from the functional interface's abstract method.
Submitted by heartin on Mon, 06/13/2016 - 12:11
Java 8 introduces few general purpose functional interfaces based on the input and output to the single abstract method.
Most common ones are:
Predicate<T> whose method
takes in an argument of type T and
rerturn a boolean.
Consumer<T> whose method
takes in an argument of type T and
rerturn nothing (void).
Function<T,R> whose method
Submitted by heartin on Mon, 06/13/2016 - 12:08
In functional programming, we think in terms of functions. While Object Oriented programming abstract over data, functional programming abstract over behavior. Instead of data, stateless functions are be passed across the code.
Lambda expressions are Java's way of doing functional programming. Lambda expressions in computer science are anonymous functions: a function (or a subroutine) defined, and possibly called, without being bound to an identifier.
Submitted by heartin on Thu, 06/02/2016 - 20:06
You need to install the version of Git for your system first before getting started. You can download Git for Windows from https://git-for-windows.github.io. A simple Google search will help you install Git.
This is the most important prerequisite for using git in your machine.
You can use various free GUI tools such as Tortoise Git or SourceTree for working with Git easily.
We will see more about these later, if you face any doubt, please ask.
Submitted by heartin on Sat, 05/14/2016 - 13:13
@Profile annotation allow you to register components that will be selected only if its associated profile is active. You can selectively activate a set of beans in a class or all beans .
We will see how to do this using a Java configuration file using the @Profile annotation, and then we will also discuss about how to do it using XML configuration.
Important points about Spring Profiles
Submitted by heartin on Sat, 05/14/2016 - 09:07
We will create a simple class, configure it and test it. You can configure a Spring application through xml, or Java configuration or annotations along with xml or java configuration. In this example we will use @Component and @ComponentScan annotations along with Java configuration. Note that these annotations can also be used along with xml configuration and we will see how to do that in the end.