Pages

Friday, 26 August 2022

How Hashmap works Internally?

 

HashMap<K,V> is a class in Java Collection Framework implementing Map<K,V> interface. HashMap fully supports all features specified in the Map interface, including optional features.
HashMap allows to store key and value pairs. Keys cannot be duplicated.

public class HashMap<K,V> extends AbstractMap<K,V>
                      implements Map<K,V>, Cloneable, Serializable
The characteristics of HashMap:
  • HashMap contains key and value pairs.
  • It can have one null key and multiple null values.
  • HashMap does not maintain keys order.
  • it works base on hashing technique. (See more explanation of this technique below)
Java designers have used hashing technique in HashMap class to store data and improve its performance. Now lets see how this technique is used in HashMap. We basically analyze what happens when we call these methods: HashMap.put(K,V), HashMap.get(K) and HashMap.remove(key).
HashMap<K,V> manages an array of Node<K,V> objects that will be replaced by another larger array if all of its elements has been assigned value.

static final int hash(Object key) {
    int h;
    return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
Node<K,V> class consists of 4 fields. next field is a reference to the next Node object. It may not be the next element in the array.

static class Node<K,V> implements Map.Entry<K,V> {
    int hashcode;
    K key;
    V value;
    Node<K,V> next;
}
HashMap ensures those Node(s) having the same hashcode will have consecutive references. This helps it quickly find all Node(s) with the same specified hashcode .
HashMap.put(key,value)
When calling HashMap.put(key,value) method, HashMap looks for Node with condition node.hashcode == hash(key). If no match is found, a new Node object is assigned to the array. (See picture below)
Otherwise, HashMap quickly identifies those consecutive Node(s) satisfying condition node.hashcode == hash(key) and significantly narrows the scope of Node(s) to be searched by key.
  • If the Node corresponding to the key is found, new value will be assigned to Node.value.
  • Otherwise, a new Node object is created and assigned to the array (See picture below).
HashMap.get(key)
When HashMap.get(key) method is called, HashMap quickly identifies consecutive Node(s) that satisfy the condition node.hashcode == hash(key), which significantly narrows the scope of the Node(s) need to be searched by key. Then, it searches Node by key and returns node.value if found, otherwise it returns null.

************************************************

✍️AUTHORLinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employee and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET.

For more details whatsapp : https://lnkd.in/dnBWDM33


*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python


 

Friday, 19 August 2022

How to do Docker Tooling in Intellij Idea

 



Most Used Docker Commands:Interview Question


Pre-Requisite: 




Docker and IntelliJ IDEA

This chapter will show you basic Docker tooling with IntelliJ IDEA:

  • Pull Docker images

  • Run, stop, or delete a Container

  • Build an Image

Install Docker Plugin in IDEA

Go to “Preferences”, “Plugins”, “Install JetBrains plugin…​”, search on “docker” and click on “Install”

docker intellij plugin install


Restart IntelliJ IDEA to active plugin.

Click on “Create New Project”, select “Java”, “Web Application”

docker intellij create java project


Click on “Next”, give the project a name “dockercon”, click on “Finish”. This will open up the project in IntelliJ window.

Go to “Preferences”, “Clouds”, add a new deployment by clicking on “+”. Click on “Import credentials from Docker Machine”, “Detect”, and see a successful connection. You may need to check the IP address of your Docker Machine. Find the IP address of your Docker Machine as docker-machine ip <machine-name> and specify the correct IP address here.

docker intellij cloud connection


Go to “View”, “Tool Windows”, “Docker Tooling Window”. Click on “Connect”" to connect with Docker Machine. Make sure Docker Machine is running.

Warning
IDEA does not work with “Docker for Mac” at this time. (ADD BUG #)

docker intellij tool window

************************


******************************


Pull an Image

Select top-level node with the name “Docker”, click on “Pull image”

docker intellij pull image

Type an image name, such as arungupta/couchbase, and “OK”

docker intellij repository name

Expand “Containers” and “Images” to see existing running containers and images.

The specified image is now downloaded and shown as well.

Run a Container

Select the downloaded image, click on “Create container”

Select “After launch” and enter the URL as http://192.168.99.100:8091. Make sure to match the IP address of your Docker Machine.

docker intellij deployment after launch

In “Container” tab, add “Port bindings” for 8091:8091

docker intellij container ports

Click on “Run” to run the container.

This will bring up the browser window and display the page http://192.168.99.100:8091 and looks like:

docker intellij run container browser

This image uses Couchbase REST API to configure the Couchbase server.

Right-click on the running container, select “Inspect” to see more details about the container.

docker intellij container inspect

Click on “Stop container” to stop the container and “Delete container” to delete the container.

Build an Image

  1. Refer to the instructions https://www.jetbrains.com/help/idea/2016.1/docker.html

  2. Right-click on the project, create a new directory docker-dir

  3. Artifact

    1. Click on top-right for “Project Structure”

    2. select “Artifacts”

    3. change “Type:” to “Web Application: Archive”

    4. change the name to dockercon

    5. change Output directory to docker-dir

  4. Create “Dockerfile” in this directory. Use the contents

    FROM jboss/wildfly
    
    ADD dockercon.war /opt/jboss/wildfly/standalone/deployments/
  5. “Run”, “Edit Configurations”, add new “Docker Deployment”

    1. “Deployment” tab

      1. Change the name to dockercon

      2. Select “After launch”, change the URL to “http://192.168.99.100:18080/dockercon/index.jsp”;

      3. In “Before launch”, add “Build Artifacts” and select the artifact

    2. “Container” tab

      1. Add “Port bindings” for “8080:18080”

  6. View, Tool Windows, Docker, connect to it

  7. Run the project


Special credit to arun gupta*

Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session

TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122
Entire course content can be found below:  COURSE CONTENT


  • Interview questions for SDET/Automation Testing:
  • Top 21 GIT interview questions
  • Top 30 Selenium Webdriver Interview Q&A 
  • Top 20 API Testing Interview Q&ASelenium Interview Question SET-4 
  • Selenium Interview Question SET-1
  • Selenium Interview Question SET-2
  • Selenium Interview Questions SET-3
  • Selenium Interview Question SET-4

      
  •        Check GIT commands for Interview preparation SET-1:

    GIT Interview Question 1 to 11

    Check GIT commands for Interview preparation SET-2:

    GIT Interview Question 12 to 21

    Check GIT commands for Interview preparation SET-3:

    GIT Interview Question 21 to 30

    Check below link for question and answers with code:

    Top API Interview Question 1-10

    *************************************************

    SeleniumWebdriver Automation Testing Interview Questions:

    API Testing Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Rest-API

     
    Kubernetes Interview Question Set
    https://automationreinvented.blogspot.com/search/label/Kubernetes

     
    Docker Interview Question Set
    https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

     
    Linux Interview question Set
    https://automationreinvented.blogspot.com/search/label/Linux

     
    Automation Testing/SDET Framework Design
    https://automationreinvented.blogspot.com/search/label/FrameworkDesign


    Java Related Interview Question Set

    https://automationreinvented.blogspot.com/search/label/Java


    GIT Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/GIT


    Coding Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Coding%20Questions
    Mobile Testing Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

    Python Interview Question Set for QAE - SDET - SDE:
    https://automationreinvented.blogspot.com/search/label/Python

    Thursday, 18 August 2022

    How to Dockerize PostgreSQL ? How to use docker postgresql ?

     


    Most Used Docker Commands:Interview Question

    Pre-Requisite: 


    What is PostgreSQL?

    PostgreSQL has object-oriented features for handling unstructured data, it is widely used as a Relational Database. 

    PostgreSQL supports both SQL and JSON to implement relational and non-relational queries on data present inside databases. In other words, with PostgreSQL, you can write SQL commands to process data present in tables that belong to the respective database servers. Because of its vast features and functionalities, PostgreSQL is reportedly ranked 4th among the most popular databases worldwide.

    Install PostgreSQL on Docker

    Assuming there is no Docker image that suits your needs in the Docker Hub, you can create one yourself.

    Start by creating a new Dockerfile:

    Note: This PostgreSQL setup is for development-only purposes. Refer to the PostgreSQL documentation to fine-tune these settings so that they are suitably secure.


     

    If you want to use the above code kindly download it from below github repository:
    https://github.com/sidharth8891/dockerhelp/blob/main/dockerFilePostgreSql
    

    Build an image from the Dockerfile and assign it a name.

    $ docker build -t eg_postgresql .
    

    Run the PostgreSQL server container (in the foreground):

    $ docker run --rm -P --name pg_test eg_postgresql
    

    There are two ways to connect to the PostgreSQL server. You can use Link Containers, or we can access it from our host (or the network).

    Note: The --rm removes the container and its image when the container exits successfully.

    Use container linking

    Containers can be linked to another container’s ports directly used --link remote_name:local_alias in the client’s docker run. This sets up a number of environmental variables that can then be used to connect:

    $ docker run --rm -t -i --link pg_test:pg eg_postgresql bash
    
    postgres@7ef98b1b7243:/$ psql -h $PG_PORT_5432_TCP_ADDR -p $PG_PORT_5432_TCP_PORT -d docker -U docker --password
    

    **********

    ***********

    Connect from your host system

    Assuming you have the postgresql-client installed, you can use the host-mapped port to test it as well. You need to use docker ps this to find out what local host port the container is mapped to first:

    $ docker ps
    
    CONTAINER ID        IMAGE                  COMMAND                CREATED             STATUS              PORTS                                      NAMES
    5e24362f27f6        eg_postgresql:latest   /usr/lib/postgresql/   About an hour ago   Up About an hour    0.0.0.0:49153->5432/tcp                    pg_test
    
    $ psql -h localhost -p 49153 -d docker -U docker --password
    

    Test the database

    Once you have authenticated and have a docker =# prompt, you can create a table and populate it.



    If you want to use the above code, kindly download it from the below github link:
    https://github.com/sidharth8891/dockerhelp/blob/main/TestTheDatabase

    Use container volumes

    You can use the defined volumes to inspect the PostgreSQL log files and to backup your configuration and data:

    $ docker run --rm --volumes-from pg_test -t -i busybox sh
    
    / # ls
    bin      etc      lib      linuxrc  mnt      proc     run      sys      usr
    dev      home     lib64    media    opt      root     sbin     tmp      var
    / # ls /etc/postgresql/9.3/main/
    environment      pg_hba.conf      postgresql.conf
    pg_ctl.conf      pg_ident.conf    start.conf
    /tmp # ls /var/log
    ldconfig    postgresql
  • Interview questions for SDET/Automation Testing:
  • Top 21 GIT interview questions
  • Top 30 Selenium Webdriver Interview Q&A 
  • Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session

    TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122
    Entire course content can be found below:  COURSE CONTENT


  • Interview questions for SDET/Automation Testing:
  • Top 21 GIT interview questions
  • Top 30 Selenium Webdriver Interview Q&A 
  • Top 20 API Testing Interview Q&ASelenium Interview Question SET-4 
  • Selenium Interview Question SET-1
  • Selenium Interview Question SET-2
  • Selenium Interview Questions SET-3
  • Selenium Interview Question SET-4

      
  •        Check GIT commands for Interview preparation SET-1:

    GIT Interview Question 1 to 11

    Check GIT commands for Interview preparation SET-2:

    GIT Interview Question 12 to 21

    Check GIT commands for Interview preparation SET-3:

    GIT Interview Question 21 to 30

    Check below link for question and answers with code:

    Top API Interview Question 1-10

    *************************************************

    SeleniumWebdriver Automation Testing Interview Questions:

    API Testing Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Rest-API

     
    Kubernetes Interview Question Set
    https://automationreinvented.blogspot.com/search/label/Kubernetes

     
    Docker Interview Question Set
    https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

     
    Linux Interview question Set
    https://automationreinvented.blogspot.com/search/label/Linux

     
    Automation Testing/SDET Framework Design
    https://automationreinvented.blogspot.com/search/label/FrameworkDesign


    Java Related Interview Question Set

    https://automationreinvented.blogspot.com/search/label/Java


    GIT Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/GIT


    Coding Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Coding%20Questions
    Mobile Testing Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

    Python Interview Question Set for QAE - SDET - SDE:
    https://automationreinvented.blogspot.com/search/label/Python