Wednesday, November 28, 2018

Materialized View in Oracle:
A materialized view in Oracle is a database object that contains the results of a query. They are local copies of data located remotely, or are used to create summary tables based on aggregations of a table's data. Materialized views, which store data based on remote tables are also, know as snapshots.
It is used for keeping a local copy of the data in a remote database and also to improve the performance in some cases.
Syntax is:
CREATE MATERIALIZED VIEW AS SELECT STATEMENT
A LOG table has to be created corresponding to a Master table to enable FAST REFRESH.

Tuesday, November 20, 2018

Second Level Caching:
If you are enabling both second-level caching and query caching, then your hibernate config file should contain the following:
         true
true
net.sf.ehcache.hibernate.EhCacheRegionFactory

Then Configure hibernate Entities to use second level caching.

Monday, November 19, 2018

Saturday, November 10, 2018

Java 8 Streams:
Whereas a java Stream is a data structure that is computed on-demand and do internal iteration.Java Stream doesn’t store data, it operates on the source data structure (collection and array) and produce pipelined data that we can use and perform specific operations. Such as we can create a stream from the list and filter it based on a condition.Java 8 Stream internal iteration principle helps in achieving lazy-seeking in some of the stream operations.Commonly used intermediate operations are filter and map.Commonly used terminal methods are forEachtoArrayminmaxfindFirstanyMatchallMatch etc. You can identify terminal methods from the return type, they will never return a Stream.
Java Streams are consumable, so there is no way to create a reference to stream for future usage. Since the data is on-demand, it’s not possible to reuse the same stream multiple times.
Functional Interfaces in Stream are :
Function and BiFunction:takes one input returns another.
 ToIntFunctionToLongFunctionToDoubleFunctionToIntBiFunctionToLongBiFunctionToDoubleBiFunctionLongToIntFunctionLongToDoubleFunctionIntToLongFunctionIntToDoubleFunction

Predicate and BiPredicate
Consumer and BiConsumer :consumes a type and do not return any object
Java Optional is a container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value. Stream terminal operations return Optional object. Some of these methods are:

  • Optional reduce(BinaryOperator accumulator)
  • Optional min(Comparator comparator)
  • Optional max(Comparator comparator)
  • Optional findFirst()
  • Optional findAny()

Converting Java Stream to Collection or Array

There are several ways through which we can get a Collection or Array from a java Stream.
  1. We can use java Stream collect() method to get List, Map or Set from stream.
    Copy
    Stream intStream = Stream.of(1,2,3,4); List intList = intStream.collect(Collectors.toList()); System.out.println(intList); //prints [1, 2, 3, 4] intStream = Stream.of(1,2,3,4); //stream is closed, so we need to create it again Map intMap = intStream.collect(Collectors.toMap(i -> i, i -> i+10)); System.out.println(intMap); //prints {1=11, 2=12, 3=13, 4=14}
Example:
Object obj=list.stream().filter( i->((Employee)i).getEmpName().startsWith("A")).collect(Collectors.toList());
List list2=(ArrayList) obj;
Lambda Expression:

Map<String, Integer> items = new HashMap<>();
 items.put("A", 10);
 items.put("B", 20);
 items.put("C", 30);
 items.put("D", 40);
 items.put("E", 50);
 items.put("F", 60);
 
 items.forEach((k,v)->System.out.println("Item : " + k + " Count : " + v));

Method references provide the useful syntax to refer directly to exiting methods or constructors of Java classes or objects (instances). It can be to a Class::new (Constructor),Static method,instance method or to a pair of object referance and instance method.
Eg:cars.forEach( Car::collide );cars.forEach( Car::collide );

Friday, November 9, 2018

TreeMap:
TreeMap is a Red-Black tree based NavigableMap implementation. The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.
This implementation provides guaranteed log(n) time cost for the containsKeygetputand remove operations.
SortedMap<String, String> fileExtensions = new TreeMap<>(new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                return s2.compareTo(s1);
            }
        });

Friday, November 2, 2018