7 Reasons Why JavaScript Async/Await Is Better Than Plain Promises (Tutorial)

Async/await was introduced in NodeJS 7.6 and is currently supported in all modern browsers. I believe it has been the single greatest addition to JS since 2017. If you are not convinced, here are a bunch of reasons with examples why you should adopt it immediately and never look back.

from Pocket https://ift.tt/2LNB5jo
via IFTTT

openCV – Android app

This a post from a guy that have just used openCV libraries directly on Android. Brilliant! Thank you for your post, Elvis Chidera

For those who doesn’t know what openCV is or what is it for, openCV is the most popular opensource library that allows you to manipulate images, like identifying objects and so on.

If you need that on your android app, take a look on this post.

Java 8 – Some of the new features

In this post, some of the new features of JAVA 8…

 

…and here are the results from running the file above

Note that the build fails because we pass null to the Optional and we have a condition to throw an exception if null is passed to it (this is the reason why this line is the last statement of this example).

Thank you! 🙂

 

Design Pattern: Command and State together

In this article we will explain two JAVA design patterns:
Command and State.

In the main method we:

  1. first create the light object (aka receiver);
  2. then we check if the light is on or off;
  3. after that we create a light command passing to it the light we’ve just created;
  4. then we create a Remote Control and set the command into it;
  5. in the next step we press the button and we check the light state;
  6. finally, we repeat the process and check the light state again.

So lets start with the  code:

Here we have the client class (the one that have the main method)

 

The Command Design Pattern implementation
Here we define our Command interface

 

This is the remote control class.
Note that in the pressButton method we actually execute the Command passed previously in the set method. Notice that this class has no knowledge at all about the receiver. Instead it just knows that it has a Command and how to interact with it.

 

Here we have the concrete  light command (the implementation of the Command interface). In the execute method we specify what the command really does: in this case with the help of the State Design Pattern we are simply saying to the light to go to the next state.

 

The next section is the State Design Pattern part
This is the Light class. From the Command point of view this is the receiver and from the point of view of the state design pattern this is the object that keeps the current state of the light (also known as a wrapper that will be passed to the concrete states).

 

This is the state interface. Notice that here we have two methods that have to be implemented by the classes that implement the state interface.

 

The next class represents one of the possible state of the light (the concrete state that represents the ON state of the light)

 

This is the other possible state (the concrete state that represents the OFF state of the light)

 

And the results:

 

And that’s it. Feel free to comment.

Thank you!

Working with nested Maps in JAVA

In this post I will show you a simple and easy way of working with JAVA Maps, more precisely, how to add an element (a.k.a value) to a multi nested maps:

That’s it. Simple, isn’t it? 😉

Source code: github

Builder Design Pattern

Here is the “usual” implementation of this design pattern.

 

The result is:
builder2

UML
builder2_uml