Tuesday, May 3, 2016

JAVA 8 - what is Functional Interface and Lambda Expression, etc

Functional Interface is an interface with only one method.
- default methods do not count
- static methods do not count
- methods from the Object class do not count

A Lambda Expression is an instance of a functional interface.
public interface Predicate<T> {
    boolean test(T t);
}

Implementation would be:
Predicate<String> predicate = s -> s.length() < 20;
System.out.println(predicate.test("Hello world!"));//expicite way of using it

Friday, April 29, 2016

COLLECTIONS - mutable List vs unmodifiable view of List

When you use Collections.unmodifiableList(list) it will return unmodifiable view of that list, it means you will get an UnsupportedOperationException on add() over that view etc.

But in the same time the list itself remains to be mutable in case it is modified in proper way e.g. by the programm API.

JAVA - Map Big O notation chart, Algorithmic Performance


GRALDE - add custom external *.jar to module dependencies

1. An example is map-visualiser project from github
2. Clone that project and make gradlew build for it
3. It will build its *.jar inside of /build/libs
4. Create libs dir inside your module
5. Copy/past that *.jar into your module libs dir 
6. Add these LOCs below into module's build.gradle and build the project:

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'    
    }
}

dependencies {    
    compile name: 'map-visualiser-1.0'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

Wednesday, April 27, 2016

SCALA - Scala for Java developers notes

Resources:
This course on Pluralsight
http://scalaforfunandprofit.com/why-use-fsharp/

http://docs.scala-lang.org/style/

History
Started in 2003 as research project in Switzerland.
Research was headed by Martin Odersky - an author of Java Generics and Java compiler.


Scala was adapted by:

Scala is for the future Software Development and there is non too much experienced devs
http://insights.dice.com/2014/04/04/employers-cant-find-enough-scala-talent/

Pure functions 
Is associated with objects and work without a side-effects (or mutation).
Define fixed variable - vow.

Higher order functions 
Functions are "first citizens" in Scala. This why functions could:

  • receive other functions in its parameters
  • return functions
  • to be stored for later execution