Tuesday, February 11, 2020

Java in Practice

      CompletableFuture


package com.studyskymate.dinesh.corejava.java8;


import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public class CompletableFutureEx {

      public static void main(String[] args) {
           List<Integer> list = Arrays.asList(5);

list.stream().map(
num -> CompletableFuture
.supplyAsync(() ->getNumber(num)))
.map(CompletableFuture -> CompletableFuture
.thenApply(n -> n * n)).map(t -> t.join())
.forEach(s -> System.out.println(s));
      }

      private static int getNumber(int a) {
           return a * a;
      }
}

  Transactions and Isolation Level

Isolation level in a transactional method
@Autowired
private TestDAO testDAO;

@Transactional(isolation=Isolation.READ_COMMITTED)
public void someTransactionalMethod(User user) {

  // Interact with testDAO

}

dirty readsnon-repeatable readsphantom reads
READ_UNCOMMITTEDyesyesyes
READ_COMMITTEDnoyesyes
REPEATABLE_READnonoyes
SERIALIZABLEnonono
Example: Transaction A reads a range of records. Meanwhile, Transaction B inserts a new record in the same range that Transaction A initially fetched and commits. 
Later Transaction A reads the same range again and will also get the record that Transaction B just inserted.This is a phantom read: a transaction fetched a range of records multiple times from the database and obtained different result sets (containing phantom records).



Microservices Design Pattern


1. Decomposition Patterns
   a. Decompose by Business Capability
   b. Decompose by Subdomain
   c. Strangler Pattern
2. Integration Patterns
   a. API Gateway Pattern
   b. Aggregator Pattern
   c. Client-Side UI Composition Pattern
3. Database Patterns
    a. Database per Service
    b. Shared Database per Service
    c. Command Query Responsibility Segregation (CQRS)
    d. Saga Pattern  credit limit
4. Observability Patterns
      a. Log Aggregation
      b. Performance Metrics
      c. Distributed Tracing
      d. Health Check
5.Cross-Cutting Concern Patterns
  a. External Configuration
  b. Service Discovery Pattern
  c. Circuit Breaker Pattern

  d. Blue-Green Deployment Pattern


How to avoid Diamond Problem With Default Methods in Java 8


package com.studyskymate.dinesh.corejava.java8;

public interface Poet {

      default void write() {
           System.out.println("Poet's default method");
      }

      static void write3() {
           System.out.println("poet Writer static default method");
      }

}


package com.studyskymate.dinesh.corejava.java8;

public interface Writer {
       default void write() {
              System.out.println("Writer default method");
          }
       
       default void write2() {
              System.out.println("Writer default method22");
          }
       
       static void write3() {
              System.out.println(" write Writer static default method");
          }
}

package com.studyskymate.dinesh.corejava.java8;

public class Multitalented implements Poet, Writer {

      public static void main(String[] args) {
           Multitalented m = new Multitalented();
           m.write();
      }

      //Need to override the ambiguous method otherwise there will be compile time error
      @Override
      public void write() {
           Writer.super.write();
           System.out.println("In Multitalented class");
      }

}


Wednesday, November 6, 2019

Most Important Java Interview Questions

 Java Interview Questions

Most Important Java Interview Questions

Core Java, JDBC, Spring, Hibernate, Servlet, JSP Interview Questions



Wednesday, October 16, 2019

Fetch the Data from Database using Hibernate Query


Fetch the Data from Database using Hibernate Query


Here we are going to fetch the data of table emp1000 from the database using hibernate Query


Prerequisite: Hibernate libraries and ojdbc.jar already linked to the project.(Hibernate save data example)





 Employees.java


package com.studyskymate.hib;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

//POJO
@Entity
@Table(name = "emp1000")
public class Employees {

     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     private int id;

     private String firstName, lastName;

     public int getId() {
           return id;
     }

     public void setId(int id) {
           this.id = id;
     }

     public String getFirstName() {
           return firstName;
     }

     public void setFirstName(String firstName) {
           this.firstName = firstName;
     }

     public String getLastName() {
           return lastName;
     }

     public void setLastName(String lastName) {
           this.lastName = lastName;
     }
}



2.        TestHibernate2.java

package com.studyskymate.hib;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.query.Query;

public class TestHibernate2 {

      public static void main(String[] args) {


StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml").build();

Metadata meta = newMetadataSources(ssr).getMetadataBuilder().build();

SessionFactory factory = meta.getSessionFactoryBuilder().build();

            Session session = factory.openSession();

            Transaction t = session.beginTransaction();
        
           
            //Here this query will fetch data from Employees Table
            Query q = session.createQuery("from Employees");

            //fetching list of Employees class objects
            List<Employees> list = q.list();

            //if list has data then iterate
            if (list != null && !list.isEmpty()) {

                  //iterate over list and fetch Employee Data
      
            for (Employees e : list) {

                System.out.println("Id: " + e.getId());
                System.out.println("Name: " +
                e.getFirstName() + " " +e.getLastName());

                  }
            }

           factory.close();
           session.close();
     }
}

Friday, October 11, 2019

MG-CEIT Course Feedback Form

       MG-CEIT Course Feedback Form

Step1: 

 Like below three pages for the updated course information


                  

Step2: Logout from facebook 

Step3: Fill the below form and click on the submit button:



Thanks for Visit


Create a Digital Clock using HTML and JavaScript

Create a Digital Clock using HTML and JavaScript  <! DOCTYPE html> < html > < head > ...

Followers

Search This Blog

Popular Posts