Posts

Microservices

Microservices: -------------- What is Monolithic Application: ------------------------------- * All type of components included in the single project, That is called Monolithic application. Eg.  College Project (Including all below modules in the single project): ->Student ->Faculty ->Examination ->Result ->Address What is Microservice: -------------------- * Micro -> small * Creating multiple small services * So here we will create all the component as a seperate application (micro services).  * So here creating multiple spring boot projects.  Eg: (Below all creating as seperate application): ->Student ->Faculty ->Examination ->Result ->Address Advantages: * Testing -> If you change any one microservice you can test that alone and you can deploy that alone. So nothing else get down * Scalable -> Any specific applicaiton we can scalable. Eg. at the time of result , we can scale up the result micorserive up and others down. * Loosely ...

Monolithic & Heterogenous Application

 * Where one project containing all the modules (huge code base), that is called Monolithic application. Problem: * Due to this, if we want to change any small piece of code, you need to do full round of testing. And we need to down the whole system. * To avoid this they introduced Microservice Architecture (Heterogenous)

Spring - Dependency Injection

 * If you want to inject a one bean into another bean that is called dependency injection.  * Using the spring IOC container we can do easily just adding @Autowired annotation.

Blocking Queue

 * Blocking Queue is helping us to use the producer consumer concept in Java

Fail Safe vs Fail Fast Iterator

* When we are iterating the collections, and at the same time if we are modify the collection, then it will throw uninterepted exception.  This is Called Failed Fast Iterator. * But it will not throw the error for above use case, that is called Fail Safe Iterator. Eg for Fail Safe Iterator, CopyOnWriteArrayList, ConcurrentHashMap - These are synchronized. So it will not throw error

Create Generic Class

 * Generic Class to handle parameterized types.  * Example if class name called Employee. And the ID field may be some cases string and some usecase it should be number. Then at run time we can specify the DataType and we can make use of the same class.  Eg. public class Employee <T> {    private T id;    public void add(T id) {       this.id = id;    }    public T get() {       return id;    }    public static void main(String[] args) {       Employee<Integer> integerEmployee = new Employee<Integer>();       Employee<String> stringEmployee = new Employee<String>();            integerEmployee.add(new Integer(1001));       stringEmployee.add(new String("Hello World"));       System.out.printf("Integer Value :%d\n\n", integerEmployee.get());       Syst...

What are the Object Class Methods Available ?

  * public int hashcode() * protected void finalize() * protected Object clone() * public String toString()

How to set Java Object into JaxBElement ?

How to set Java Object into JaxBElement ? * In JaxBElement we are having setValue(T t) method. this will help us to solve this problem. * java.xml.bind.JAXBElement.setValue() Eg. Lets Use College Class as Bean. MainJaxBElement class as main class to process the College Class. package com.javavirus.jaxbelement; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class College{ private int id; private String name; public College(int id, String name) { super(); this.id = id; this.name = name; } public int getId() { return id; } @XmlAttribute public void setId(int id) { this.id = id; } public String getName() { return name; } @XmlElement public void setName(String name) { this.name = name; } @Override public String toString() { return "College [id=" + id + ", name=" + name + "]"...

TypeScript - Interface

TypeScript Interface: * Class can implement multiple interfaces. * Define a interface with method contract. Eg: export interface Coach {     getDailyWorkout(): string; } import { Coach } from "./Coach"; export class GolfCoach implements Coach {     getDailyWorkout(): string {         return "Hit 100 balls at the golf range.";     }  } import { Coach } from "./Coach"; export class CricketCoach implements Coach {     getDailyWorkout(): string {         return "Practice your spin bowling technique.";     } } import { CricketCoach } from "./CricketCoach"; import { GolfCoach } from "./GolfCoach"; import { Coach } from "./Coach"; let myCricketCoach = new CricketCoach(); let myGolfCoach = new GolfCoach(); // declare an array for coaches ... initially empty let theCoaches: Coach[] = []; // add the coaches to the array theCoaches.push(myCricketCoach); theCoaches.pu...

Typescript- Abstract Class

Type Script Abstract Class: * Cant create an instance for abstract class. * Abstract class can also have abstract methods. * Abstract method must be implemented in the concrete class. Eg: export abstract class Shape {     constructor(private _x: number, private _y: number) {     }     public get x(): number {         return this._x;     }     public set x(value: number) {         this._x = value;     }     public get y(): number {         return this._y;     }     public set y(value: number) {         this._y = value;     }     getInfo(): string {         return `x=${this._x}, y=${this._y}`;     }     abstract calculateArea(): number; } import { Shape } from './Shape'; export class Circle extends Shape {     calculateArea(...

TypeScript - Inheritance

Typescript - Inheritance: * Inheritance is the OOP Cocept. * Chile class can extends the parent class object and methods. * Support Abstract classess and overriding. * It supports only single inheritance. * But you can implement multiple interfaces. Eg: Shape.ts export class Shape {     constructor(private _x: number, private _y: number) {     }     public get x(): number {         return this._x;     }     public set x(value: number) {         this._x = value;     }     public get y(): number {         return this._y;     }     public set y(value: number) {         this._y = value;     }     getInfo(): string {         return `x=${this._x}, y=${this._y}`;     } } Circle.ts import { Shape } from './Shape'; export class Circle extends S...

TypeScript - Modules

Typescript Modules: * Module can export classes, functions, variables etc., * Another file can import classes, functions, variables etc., from module. Eg. File : Customer.ts export class Customer{ ... ... } File : Driver.ts import {Customer} from './Customer'; let myCustomer = new Customer("Vinoth", "Kumar"); console.log(myCustomer.firstName); console.log(myCustomer.lastName); {Customer} -> Class Name './Customer' -> Directory & File Name

TypeScript - Shortcut Constructor (Parameter Property)

Parameter Properties: * Typescript offers to create a shortcut to create a constructor. * To avoid boiler plate. Normal Approach: Class Customer{ //Start code private firstName : string; private lastName  : string; constructor(theFirst:string, theLast:string){ this._firstName = theFirst; this._lastName = theLast; } //End code public get firstName(): string(){ return this._firstName; } public set firstName(value: string){ this._firstName = value; } } Shortcut: Class Customer{ //Replace Start code constructor(private _firstName: string, private _lastName: string){ } //Replace End code public get firstName(): string(){ return this._firstName; } public set firstName(value: string){ this._firstName = value; } } Use above both codes: let myCustomer = new Customer("Vinoth", "Kumar"); myCustomer.firstName = "Raj"; console.log(myCustomer.firstName);

TypeScript - What is tsconfig.json ?

There are lot of compiler flags are there, So it is difficult to remember. So lets do it in config file. This config file is called "tsconfig.json" file * Place this file in the root directory. Eg. tsconfig.json: { "compilerOptions":{ "noEmitOnError":true, "target":"es5"; } } Command to auto generate this file with template: tsc --init

TypeScript - Access Modifier & get/set

Access Modifier: private - within the class public - access from anywhere protected - within the class and subclasses. Note: Most of the time if compile time error also, It will generate the file and we can run the file. How to avoid this ? 1. Delete the js file whatever created earlier. using below command. Eg. del Customer.js 2. Use below command to not generate the .js file if any compilation error . Command : tsc -noEmitOnError Customer.ts Accessors: Class Customer{ private firstName : string; private lastName : string; public getFirstName(): string(){ return this.firstName; } public setFirstName(theFirst: string): void { this.firstName : theFirst; } } Using Get/Set: * get/set accessors is only supported in ES5 and higher. * you have to set the compiler flag inorder to compile the code. Syntax to compile: tsc --target ES5 -noEmitOnError Customer.ts Example: Class Customer{ private _firstName: string; private _lastName: strin...

Type Script - Class

Create a Class: FileName: *.ts Class Customer{ firstName : string; lastName  : string; constructor(theFirst:string, theLast:string){ this.firstName = theFirst; this.lastName = theLast; } } Lets use class, let mycustomer = new Customer("Vinoth", "Kumar"); console.log(mycustomer.firstName);

TypeScript - Loops & Arrays

Creating Loops & Arrays: * Loop is used to iterate some values. Eg 1. for (let i=0; i < 5; i++) {     console.log(i); } Eg.2: Find the average from the integer array. let reviews: number[] = [5, 5, 4.5, 1, 3]; let total: number = 0; for (let i=0; i < reviews.length; i++) {     console.log(reviews[i]);     total += reviews[i]; } let average: number = total / reviews.length; console.log("Review average = " + average); * Array is Growable in Typescript. Eg.1 let sportsTwo: string[] = ["Golf", "Cricket", "Tennis"]; sportsTwo.push("Baseball"); sportsTwo.push("Futbol"); for (let tempSport of sportsTwo) {     console.log(tempSport); }

TypeScript - let & backticks

What is let: * Its like Javascript var keyword; * In var keyword in javascript have some gotchas and pitfalls like scoping, capturing etc., * let keyword is solving those issues as well. Typescript strongly Typed: let found: boolean = true; found = 0; // Compile time error will throw if you assign 0. mismatch the datatype. let data: any = 50.0; data = "Vinoth"; // true data = false; // true Try to avoid use any, because we will lose type safty. Use backticks: console.log("Hi " + firstname + " " + lastname); console.log('Hi ${firstname} ${lastname}');

TypeScript - Variable

Variable : Syntax : let <variablename>: <type> = <Initial value> ; Eg. let found: boolean = true; let grade: number = 88.6; let firstname: string = 'Vinoth'; let lastname: string = "Kumar";

TypeScript - DataTypes

DataTypes: * boolean - true/false. * number - support integer/floating. * String - text data. * any - its supports any data type. * etc.,