Posts

Showing posts from August, 2021

Java Collections

ArrayList Vs HashSet: Load Factor: The default load factor of an ArrayList is 0.75f.  For example, the current capacity is 10. So, loadfactor = 10*0.75=7 while adding the 7th element array size will increase.   Growth Rate: current_size + current_size/2 Example: package com.vasanth.java.collections; import java.util.ArrayList; import java.util.HashSet; /**  *   * @author Vasanth  *  */ public class ArrayListVsHashSet { public static void main (String args[]) { /* ArrayList * - Implements List Interface * - Baked by Array * - Insertion order will be maintained * - Duplicates are allowed * - Null allowed , no restriction. * - Index based. we can retrieve/remove object using index. get(index)/remove(index) */ ArrayList<Object> arrayList = new ArrayList<>(); System.out.println("===== ArrayList====="); arrayList.add("hello"); arrayList.add(20d); arrayList.add(1); arrayList.add(10L); arrayLi

Spring Data JPA Using Hibernate

  ORM  (Object Relational Mapping): - Process of mapping a Java class to Database tables .  - Developers can deal with Objects instead of writing SQLs.    JPA (Java Persistence API) :  - Its a standard from Oracle to perform ORM in Java EE applications. - JPA comes with Specification & API             Specification -> For JPA Vendors/Providers like Hibernate, Open JPA , Eclipse Link and etc..               API -> For developers Why JPA: Before JPA, we have to learn each ORM tool like Hibernate / Open JPA and etc depends on the ORM  we used in our application.  Now, we can learn one single API (JPA). All the vendors/Providers implements JPA. So, we can switch from one vendor to another without making any code change in our application,  JPA API : Two important classes: EntityManagerFactory EntityManager Spring Data will hide these APIs, we need not deal with the above classes :)       Also, a lot of annotations are available. For Eg:                     To Map java classe

Linux commands - Frequently Used

To view all the process: ps -ef | grep <pid> Unzip:  unzip filename.zip   unzip file.zip -d destination_folder   grep commands: find . -name "*.*" | xargs grep " Search Text " -sl   To print file name, highlight matching text:  find . -type f -name "*.*" -print0 | xargs --null grep --with-filename --line-number --no-messages --color --ignore-case " Search text " To search in jar/zip file:   find . -name "*.jar" -exec zipgrep " Search Text " '{}' \; find . -name "*.jar" | xargs -I{} sh -c 'echo searching in "{}"; zipgrep " Search Text " {}'            find . -iname '*.jar' -printf "unzip -c %p | grep -q ' Search Text ' && echo %p\n" | sh docker cmd to find containers:  docker ps | grep "container name"     tail commands: tail -F *.log | grep -E ' text-1' To grep multiple strings: tail -F *.log | grep " text-1|text-2|text

JMS / RabbitMQ

Image
RabbitMQ - Messaging Broker    RabbitMQ Setup: Steps to download and install RabbitMQ for Windows:  https://www.rabbitmq.com/install-windows-manual.html  Download the MQ zip file and supported Erlang exe from the above link.  1. Install Erlang, set ERLANG_HOME and path in Environment variable.  ERLANG_HOME: C:\Program Files\erl-24.0.4  PATH:  C:\Program Files\erl-24.0.4\bin  2. Enable Rabbitmq management:  C:\Program Files\rabbitmq_server-3.9.1\sbin> rabbitmq-plugins.bat enable rabbitmq_management 3. Execute the batch file to start rabbitMQ  C:\Program Files\rabbitmq_server-3.9.1\sbin\ rabbitmq-server 4. Launch the URL in the browser http://localhost:15672/  (guest/guest) Types Of Exchanges: Direct Fanout Topic Headers Direct: The message will be redirected by Exchange to the specific queue based on the Key. Do the below steps in RabbitMQ management: 1. Create Exchange (Type=direct) 2. Create Queues 3. Bind the queues with Exchange with routing key Fanout: The message will be redire

GIT commands

Image
Git command Flow: Setup: git config --global user.name “[firstname lastname]” set a name that is identifiable for credit when review version history git config --global user.email “[valid-email]” set an email address that will be associated with each history marker git config --system core.longpaths true Git has a limit of 4096 characters for a filename, except on Windows when Git is compiled with msys. It uses an older version of the Windows API and there's a limit of 260 characters for a filename. So as far as I understand this, it's a limitation of msys and not of Git. You can read the details here:  https://github.com/msysgit/git/pull/110     Setup & Init: git init Initialize an existing directory as a Git repository git clone <repository_url> retrieve an entire repository from a hosted location via URL git clone <URL> --b