Posts

Showing posts from December, 2019

Modern Android architecture by using View Model

Image
A bridge of elegant design in T.O. In 2018, Google released Android Jetpack, a suite of code library, tools and guidelines that included the APIs of architecture components. The APIs are designed to help building common tasks faster and more reliable, and at the same time conforming to the architectural guidelines recommended. An Android app consists of one or more user-interface controllers.  There are already a lot of codes in this area.  It is not a good approach to have the codes, for example, written for managing Web Service and database I/O included in the U.I. Controller component.  Good design puts codes in the right places to reduce complexity, and enables collaboration among teams. A U.I. Controller consists of one or more Activities.  Each Activity uses zero, one or more Fragments.  Each Fragment uses other classes. While a U.I. defines how the data is displayed and collected on the screen, a Repository manages the incoming and outgoing data....

List manipulation by using Stream in Java

For modern Java, there are a number of features that greatly enhance the expressiveness of the language.  These features include Generics and Lambda Expressions.  And there is another one: the Stream API.  Stream is designed with the integration of Lambda Expressions that can reduce the verbosity of the language.  This API has been an important feature of the language since version 8. A Stream is a sequence of objects.  Like any generic interfaces, Stream<T> is declared as a variable where T can be Integer, Double, String, YourClass and so on.  A stream moves data by filtering, sorting, and other type of manipulation.  It doesn't provide a storage or modify the data source. Manipulating a stream will result in the creation of a new stream.  Below are some examples to show how to use the Stream API to manipulate a list. import java.util.* ; import java.util.stream.* ; class CalmStreamDemo { public static void main ( Str...