ArrayList vs LinkedList vs Vector


ArrayList vs LinkedList vs Vector 


ArrayList
LinkedList
Vector
Data structureIndex-based  dynamic arrayDoubly linked listGrowable array
Increment size50%No initial size100%
Traverse Uses iteratorUses iteratorUses enumeration
Memory usageLess memory usageMore memory usage
AccessibilityRandom and fastSequential and slowRandom and fast
OrderInsertion orderInsertion orderInsertion order
DuplicatesAllowAllowAllow
Insert / DeleteSlowFastSlow
SynchronizedNoNoYes
ImplementsRandomAccess interfaceNA
RandomAccess interface &
Serializable interface
Null valuesYesYesYes

Array vs ArrayList


 

Array
ArrayList
Fixed-sizeSize is not fixed
Not type-safeType-safe
Allow both primitives and objectsDoesn't allow primitives. But after Java 5 auto-boxing will convert primitives to objects

Type safety means the compiler will validate the types while compiling and throw an error if you do anything wrong. 

What is REST


REST

Introduction

  • Stands for Representational State Transfer.
  • REST is a web standards-based architecture that uses the HTTP protocol (port 80) for data communication.
  • Uses HTTP methods for data communication 
  • REST server simply provides access to resources and client access and presents the resource.
  • REST is stateless, so there is no session.
  • REST uses various representations like TXT, JSON, XML...etc to represent resources.

Methods in REST

  • POST
    • Sends data to the server for creating a new resource, maybe an entity. Often used when uploading a file or submitting a web form.
  • GET 
    • Retrieves data from the server. Should have no other effect.
  • PUT 
    • Similar to POST, but used to replace an existing entity.
  • PATCH
    • Similar to PUT, but used to update only certain fields within an existing entity.
  • DELETE 
    • Removes data from the server.
  • TRACE 
    • Provides a way to test what the server receives. It simply returns what was sent.
  • OPTIONS 
    • This allows a client to get information about the request methods supported by a service. 
    • The relevant response header is Allow with supported methods.
  • HEAD 
    • This returns only the response headers.
  • CONNECT 
    • Used by browser when it knows it talks to a proxy and the final URI begins with https://. 
    • The intent of CONNECT is to allow end-to-end encrypted TLS sessions, so the data is unreadable to a proxy.

Directives in Angular 11


 Directives

  • Directives are instructions in the DOM
  • It adds additional behaviors to the elements
  • Using inbuilt directives we can manage forms, lists, styles, and what users see.
  • There are a few types
    • Component directives
    • Attribute directives
    • Structural directives

Component directives

  • These directives are used in the main class.
  • Declared by @Component
Ex:
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})

Attribute directives

  • Listen and modify the behavior of other HTML elements, attributes, properties, and components
    • NgClass
      • This allows to set the CSS classes dynamically.
    • NgStyles
      • This directive lets you to set a given DOM element's style properties.
<div [ngStyle]="{'background-color':'green'}"></<div>
      • Instead of this you can use following too.
[style.color]="getColor(person.country)"
    • NgModel
      • This bind inputs, select, text areas...etc and store the required user value in a variable.
      • Add two-way data binding
  • This allows to create new directives too.

Structural directives

  • These directives manipulate the DOM element or change the structure of the DOM element
  • These directives begin with *
  • Ex: *ngIf, *ngFor
<ul *ngFor="let age of ages">
    <li *ngIf="age > 20">
        {{age}}
    </li>
</ul>




Access token vs refresh token


Access token vs refresh token

Access token

  • This is short-lived
  • Send API request, with the access token
  • If the access token is invalid, fail and ask the user to re-authenticate
  • There are few types of access tokens
    • Bearer tokens
    • JWT tokens
    • Opaque token

Refresh token

  • These tokens are long-lived
  • Refresh tokens are used to retrieve access tokens
  • If the access token is invalid, try to update it using the refresh token
  • If the refresh request passes, update the access token and re-send the initial API request
  • If the refresh request fails, ask the user to re-authenticate

States of an object in Hibernate


Hibernate object states

There are three states
  • Transient 
    • If the object just created, no primary key and not associate with a session, then the object is in the transient state
  • Persistent 
    • If a session is open, the object is in the persistent state
  • Detached 
    • If a session is closed, the object is in the detached state