Home Java Overview Maven Tutorials

Monday 19 April 2021

Constructor Chaining In java

What is Constructor chaining in JAVA

Definition :-

The process of invoking a sequence of constructors upon initialization of a class object is called constructor chaining.
Constructor chaining is useful when you want to invoke multiple constructors, one after another, by initializing only one instance.

Constructor chaining can be done in two ways:
Within same class: It can be done using this() keyword for constructors in same class
From base class: by using super() keyword to call constructor from the base class.

package ChandanPack1;

class A
System.out.println("I am inside A class constructor");
A(int x)
this(2, 4);
System.out.println("Superclass second constructor" + " " +x);
A(int l, int m)
System.out.println("multiply is " + " " + (l*m));

public class BajiPractice extends A
System.out.println("i am inside first constructor");
BajiPractice(int x)
this(2, 80);
System.out.println("number is:->" + " "+ x);
BajiPractice(int a, int b)
System.out.println("the sum is" + " " +(a+b));
public static void main(String args[])
System.out.println("constructor chaining started");
BajiPractice obj = new BajiPractice();

Output:- constructor chaining started
multiply is 8
Superclass second constructor 0
I am inside A class constructor
the sum is 82
number is:-> 10
i am inside first constructor

Sunday 11 April 2021

Contract Testing Overview

Contract Testing in API

Microservices :-

Microservices is an architectural design for building a distributed application using containers. Microservices get their name because each function of the application operates as an independent service. This architecture allows for each service to scale or update without disrupting other services in the application.

Contract Testing :- Contract testing is a way to ensure that services (such as an API provider and a client) can communicate with each other. Without contract testing, the only way to know that services can communicate is by using expensive and brittle integration tests.

A service consumer and a service provider interact with each other based on some protocol or rules. This set of rules of communication between two services is called Contract and the process of testing the communication between the two services based on this Contract is called Contract Testing.