Saturday, 4 January 2025

SQL Query for find manager with in the same name

 Table 


Query 

select e.Emp_Name,m.Emp_Name as Manager from EmpDetails e 

left join EmpDetails m on m.Manager_Id=e.id




Saturday, 23 November 2024

Remove Duplication in the string

 //Word duplication checking

string s = "eearr";

string duplicatewords=string.Empty;

for (int i = 0; i < s.Length; i++)

{

    if (!(duplicatewords.Contains(s[i].ToString())))

    {

        duplicatewords += s[i];

    }

}

Console.WriteLine(duplicatewords);


Output:


Using LINQ for Duplication

//To Get unique Word alone
var a1 = s.GroupBy(x => x.ToString());

OUTPUT: a1[0]=e ,a1[1]=a,a1[2]=r

//To Get duplicate Values alone
var a = s.GroupBy(x => x.ToString())
              .Where(g => g.Count() > 1)
              .Select(y => y.Key)
              .ToList();

OUTPUT: a[0]=e ,a[1]=r

JWT(JSON Web Token)

What is JWT?

JSON Web Token (JWT) serves as a compact and self-contained mechanism for securely transmitting information between parties as a JSON object.

JWT Structure/Components:

Header: Specifies the token type (JWT) and the signing algorithm (e.g., HMAC SHA256).

Payload: Contains the claims, which are statements about an entity (user) and additional metadata.

Signature: Created by encoding the header and payload with a secret, ensuring the token’s integrity.

JWT in Action:

  • Upon user authentication, the server generates a JWT.
  • This JWT is sent back to the client and stored, often in local storage or an HTTP-only cookie.
  • The client includes this token in the HTTP Authorization header for subsequent requests.
  • The server validates the token and grants access if valid.

Advantages:

Scalability: Due to their stateless nature, JWTs are ideal for distributed systems.

Flexibility: They can be used across different domains and applications.

Security: When properly implemented, they provide a secure way to handle user authentication.

Security Concerns:

Transmission Security: It's vital to transmit JWTs over HTTPS.

Storage: Store JWTs securely to prevent XSS attacks and other vulnerabilities.

Handling Token Expiry:

Implement short-lived JWTs and use refresh tokens for renewing access without re-authentication.


Wednesday, 30 October 2024

Create object Using Abstract and Interface and its difference

Interface Class

interface InterfaceA

{

    string MethodA(string s);

}

Abstract Class

public class AbstractB:InterfaceA

{

    public string MethodA(string s)

    {

        return s;

    }

}


Object Creation Using Abstract 

AbstractB abstractB = new AbstractB();

abstractB.MethodA("Abstract object");

Output : Abstract object

Object Creation Using Interface 

InterfaceA interfaceA = new AbstractB();

interfaceA.MethodA("Interface object");

Output : Interface object

Note (Object Creation Using Interface) :



 Inheriting the interface directly in the Class and creating the object


 public class DerivedClass :InterfaceA
 {
     public string MethodA(string s)
     {
         return s;
     }
 }

InterfaceA interfaceA1 = new DerivedClass();
interfaceA1.MethodA("Derived object");

Output : Derived object

Sunday, 13 October 2024

Sync and Async

 


If we use Async and await then its going to work in the normal way.

Sunday, 6 October 2024

React props Vs State

 

PROPS

STATE

The Data is passed from one component to another.

The Data is passed within the component only.

It is Immutable (cannot be modified).

It is Mutable ( can be modified).

Props can be used with state and functional components.

The state can be used only with the state components/class component (Before 16.0).

Props are read-only.

The state is both read and write.

React Pure components

We use the shouldComponentUpdate() Lifecycle method to customize the default behavior and implement it when the React component should re-render or update itself.

import React from "react";

export default class Test extends React.PureComponent {

    render() {

        return <h1>Welcome to GeeksforGeeks</h1>;

    }

}

Pure components automatically implement the shouldComponentUpdate() method with a shallow prop and state comparison. This method returns false if the props and state haven’t changed.