Posts

Showing posts with the label Core Java

Java Lambda Expressions

Image
Lambda expressions are introduced in Java 8 and are touted to be the most immensely colossal feature of Java. A lambda expression is an innominate function. A function that doesn’t have a designation and doesn’t belong to any class. It preserves an abundance of code and provides the implementation of a Functional interface. Lambda expressions are homogeneous to methods, but they do not require a denomination and they can be implemented right in the body of a method. //Syntax of lambda expression (parameter_list) -> {function_body} Java lambda expression has consisted of three components. 1) Parameter_list : It can be vacuous or non-empty as well. 2) Arrow-token : It is utilized to link arguments-list and body of expression. 3) Function_body : It contains expressions and verbalizations for a lambda expression. Lambda Expression Example: Single Parameter interface Fruit{ public String setFruit(String fruit); } class LambdaExpressionExample { public static void main(String[] a

Building Reactive Rest CRUD APIs Using Spring Boot, WebFlux, and MongoDB

Image
Hello everyone, today we will learn how to use Spring Boot, Spring WebFlux, and Spring Data to create a reactive web service that interacts with MongoDB. Reactive APIs are non-blocking and tend to be more efficient because they’re not tying up processing while waiting for stuff to happen. Reactive systems adopt asynchronous I/O. Reactive apps allow us to scale better if we are dealing with lots of streaming data.  If we are going to build a reactive app, we need it to be reactive all the way down to your database. Use a blocking JDBC driver with Spring WebFlux, and we will be displeased with its performance. Use a reactive NoSQL database like Cassandra, MongoDB, Couchbase, and Redis – and we will be satisfied with its performance. Spring WebFlux uses a library called Reactor for its reactive support. The Reactor is an implementation of the Reactive Streams specification. The Reactor Provides two main types called Flux and Mono . Both of these types implement the Publisher interface p

Java - Map with Multiple Keys - Example

Today we will show you how to implement a  Map with Multiple Keys.  Solution 1: Using Java Custom Key Class Solution 2: Using Google's Guava Solution 3: Using Apache Commons Collections  Example 1: Using Java Custom MultiMapKey Class Here we created a custom MultiMap Key class, we can use MultiMap as a Key to map a value.  import java.util.HashMap; import java.util.Map; public class MultiKeyDemo { public static void main( String [] args) { // Declaring the Map Map < MultiMapKey , String > table = new HashMap <>(); // Declaring the key objects MultiMapKey key1 = new MultiMapKey( "raw1" , "col1" ); MultiMapKey key2 = new MultiMapKey( "raw1" , "col2" ); MultiMapKey key3 = new MultiMapKey( "raw1" , "col3" ); // Putting the values table.put(key1, "Java" ); table.put(key2, "Kotlin" ); table.put(key3,

Hibernate 5 + RDBMS with example

Image
Hello everyone, Today we are giving an example of testing your hibernate code using HSQLDB in-memory database. Hibernate is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database. Object-relational mapping (ORM) is a programming technique for converting data between incompatible type systems in object-oriented programming languages. HSQLDB is an open-source lightweight Java database. It can be embedded in Java applications. HSQLDB database can be configured to run as an in-memory database, which designates that data will not persist on the disk. Hibernate HSQLDB In-Memory Database Example Directory Structure Maven Dependencies[pom.xml] <project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"