<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mallikarjun H T</title>
    <description>The latest articles on DEV Community by Mallikarjun H T (@mallikarjunht).</description>
    <link>https://dev.to/mallikarjunht</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F406157%2F99e182ce-68ed-44c4-a88a-167c507c7aa7.jpg</url>
      <title>DEV Community: Mallikarjun H T</title>
      <link>https://dev.to/mallikarjunht</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mallikarjunht"/>
    <language>en</language>
    <item>
      <title>Lucene V/S KQL</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Thu, 01 May 2025 14:20:10 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/lucene-vs-kql-206b</link>
      <guid>https://dev.to/mallikarjunht/lucene-vs-kql-206b</guid>
      <description>&lt;h2&gt;
  
  
  A Tour of  KQL  vs  Lucene
&lt;/h2&gt;

&lt;p&gt;Elasticsearch is a search engine, and Kibana can be used to search documents in Elasticsearch.&lt;br&gt;
A search is executed by sending a query to Elasticsearch. A query can answer many different types of questions. &lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Who are the customers with the first name Edison?&lt;br&gt;
What are the names of customers in India?&lt;br&gt;
Are there any orders for Men’s Clothing OR Electronics section?&lt;/p&gt;
&lt;h2&gt;
  
  
  Should I use  KQL  or  Lucene  in the Kibana query bar?
&lt;/h2&gt;

&lt;p&gt;It Depends, Both KQL and Lucine have a quite a lot in common.&lt;br&gt;
I recoment to start with KQL then switch to Lucine for Specific Aggrigation use Case.&lt;/p&gt;
&lt;h2&gt;
  
  
  Learn By Executing.
&lt;/h2&gt;

&lt;p&gt;in order to learn use the Free trial or download the pre prepared data sets to run locally if cloud trial expires.&lt;/p&gt;
&lt;h2&gt;
  
  
  KQL Features.
&lt;/h2&gt;

&lt;p&gt;once you load your data you can use kibana to explore and learn about the features.&lt;/p&gt;

&lt;p&gt;NOTE: KQL is case in sencitive and Lucine operaters are All Caps only&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Autocomplete - KQL&lt;/li&gt;
&lt;li&gt;Full Testsearch - KQL and Lucine&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Exact Match
&lt;/h2&gt;

&lt;p&gt;You can search for documents that contain an exact term in a provided field of data type keyword(opens in a new tab), which will not be analyzed. Not analyzed strings are case sensitive.&lt;/p&gt;

&lt;p&gt;Example:  Customer_first_name.keyword: Elyssa &lt;/p&gt;

&lt;p&gt;Note: keyword is a type that only supports Exact search, if not given while searching then anything close to the word is returned.&lt;/p&gt;
&lt;h2&gt;
  
  
  Phrase search
&lt;/h2&gt;

&lt;p&gt;To search text fields where the search terms are in the order provided, surround the value in double quotation marks, as follows:&lt;/p&gt;

&lt;p&gt;Example:  “Elyssa Underwood” - this is all field search&lt;br&gt;
Example:  Customer_full_name: “Elyssa Underwood”  - this ia field specific search&lt;/p&gt;
&lt;h2&gt;
  
  
  Fuzzy Search only available in Lucine
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;arjun~1 - will match any word with 1ch differance, the number determines the no of charecters that can differ&lt;/li&gt;
&lt;li&gt;arj*n - whild charecter search one or more charecters can occur in between arj and n&lt;/li&gt;
&lt;li&gt;arj?n - single charecter only&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;NOTE: bad idea to use &lt;code&gt;**&lt;/code&gt; or &lt;code&gt;?*&lt;/code&gt; as this can cause perfomance issues.&lt;br&gt;
to allow change the settings in elastic search.&lt;/p&gt;
&lt;h2&gt;
  
  
  Regex
&lt;/h2&gt;

&lt;p&gt;A regular expression is a way to match patterns in data using placeholder characters called operators. It returns documents that contain terms matching a regular expression. Syntax is based on the &lt;em&gt;Lucene regular expression&lt;/em&gt; engine.&lt;/p&gt;

&lt;p&gt;Example:  /.&lt;em&gt;+91[0-9]{9}.&lt;/em&gt;/ &lt;/p&gt;

&lt;p&gt;this will match number with &lt;code&gt;+91 xxx xxx xxx&lt;/code&gt; &lt;/p&gt;
&lt;h2&gt;
  
  
  Ranges
&lt;/h2&gt;

&lt;p&gt;To search documents that contain terms within a provided range, use KQL’s &lt;a href="https://www.elastic.co/docs/explore-analyze/query-filter/languages/kql#_filter_for_documents_within_a_range" rel="noopener noreferrer"&gt;range syntax&lt;/a&gt;. You can use the range syntax for string values, IP addresses, and timestamps.&lt;/p&gt;

&lt;p&gt;KQL Supports the following syntax &lt;code&gt;&amp;gt;, &amp;gt;=, &amp;lt;, and &amp;lt;=&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Lucene  supports bracketed &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/8.5/query-dsl-query-string-query.html#_ranges" rel="noopener noreferrer"&gt;range syntax&lt;/a&gt;. Ranges can be specified for date, numeric or string fields. Inclusive ranges are specified with square brackets [min TO max] and exclusive ranges with curly brackets {min TO max}.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; date:[2012-01-01 TO 2012-12-31]
 count:[1 TO 5]
 tag:{alpha TO omega}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;## Proximity Search&lt;br&gt;
 &lt;strong&gt;Lucine Exclusive&lt;/strong&gt;&lt;br&gt;
 Proximity search(opens in a new tab) allows the specified words to be further apart or in a different order, a proximity search allows us to specify a maximum edit distance of words in a phrase. The closer the text in a field is to the original order specified in the query string, the more relevant that document is considered to be&lt;/p&gt;

&lt;p&gt;“open data”~1 &lt;/p&gt;

&lt;p&gt;The above example will find all the documents where “open data” is found as a phrase and also “open source data” is a hit where one more term is present in between open and data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Boosting
&lt;/h2&gt;

&lt;p&gt;Lucene &lt;/p&gt;

&lt;p&gt;Use the boost operator ^ to make one term more relevant than another. For instance, if we want to find all documents about foxes, but we are especially interested in quick foxes:&lt;/p&gt;

&lt;p&gt;quick^2 fox &lt;/p&gt;

&lt;p&gt;The default boost value is 1, but can be any positive floating point number. Boosts between 0 and 1 reduce relevance.&lt;/p&gt;

&lt;p&gt;Boosts can also be applied to phrases or to groups:&lt;/p&gt;

&lt;p&gt;"john smith"^2   (foo bar)^4&lt;/p&gt;

&lt;h2&gt;
  
  
  Searching for IP addresses
&lt;/h2&gt;

&lt;p&gt;KQL   Lucene  &lt;/p&gt;

&lt;p&gt;Use  ""  around IP addresses while using Lucene syntax. &lt;br&gt;
Lucene also supports CIDR notation.&lt;/p&gt;

&lt;p&gt;Example:  "192.168.03.01" &lt;/p&gt;

&lt;h2&gt;
  
  
  Nested fields
&lt;/h2&gt;

&lt;p&gt;KQL &lt;/p&gt;

&lt;p&gt;Querying nested fields requires a special syntax. &lt;/p&gt;

&lt;p&gt;Example:  user.names:{ first: "Alyssa" and last: "Underwood" } &lt;/p&gt;

&lt;h2&gt;
  
  
  Runtime fields
&lt;/h2&gt;

&lt;p&gt;KQL    Lucene &lt;/p&gt;

&lt;p&gt;A runtime field is a field that is evaluated at query time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzkh5zbp2y6k59okcc51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjzkh5zbp2y6k59okcc51.png" alt="Image description" width="691" height="821"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>lucene</category>
      <category>opensource</category>
      <category>elasticsearch</category>
      <category>kibana</category>
    </item>
    <item>
      <title>KQL and syntex</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Wed, 23 Apr 2025 14:07:07 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/kql-and-syntex-3jjo</link>
      <guid>https://dev.to/mallikarjunht/kql-and-syntex-3jjo</guid>
      <description>&lt;h3&gt;
  
  
  Should I use  KQL  or  Lucene  in the Kibana query bar?
&lt;/h3&gt;

&lt;p&gt;It depends! KQL and Lucene have quite a lot in common, but there are some differences. Let's explore some key-features one by one to find out the best use-case for each language.&lt;/p&gt;

&lt;p&gt;For new users, we recommend starting with KQL(opens in a new tab) and switching to Lucene(opens in a new tab) if any particular feature is unavailable in KQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  KQL
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Kibana Query Language (KQL) is a simple text-based query language for filtering data.&lt;/li&gt;
&lt;li&gt;KQL only filters data, and has no role in aggregating, transforming, or sorting data.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Semi-structured search
&lt;/h2&gt;

&lt;p&gt;free text search with field-based search.&lt;/p&gt;

&lt;p&gt;The semi-structured search will filter documents for matches, and only return matching documents.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F95tt1ryrgf4teo7zey7s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F95tt1ryrgf4teo7zey7s.png" alt="KQL querry" width="729" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Filter for documents where a field exists
&lt;/h2&gt;

&lt;p&gt;To filter documents for which an indexed value exists for a given field, use the * operator. &lt;/p&gt;

&lt;p&gt;For example, to filter for documents where the http.request.method field exists, use the following syntax:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;http.request.method: *&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This checks for any indexed value, including an empty string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Filter for documents that match a value
&lt;/h2&gt;

&lt;p&gt;Use KQL to filter for documents that match a specific number, text, date, or boolean value. For example, to filter for documents where the http.request.method is GET, use the following query:&lt;br&gt;
&lt;code&gt;http.request.method: GET&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;to search all fields for “Hello”, use the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Hello&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To  querying keyword, numeric, date, or boolean fields, the value must be an exact match, including punctuation and case.&lt;/p&gt;

&lt;p&gt;To Search text field that has "null pointer" then querry using &lt;code&gt;http.request.body.content: "null pointer"&lt;/code&gt; if the &lt;code&gt;\"&lt;/code&gt; are not used then you will get all documents that has &lt;code&gt;null pointer&lt;/code&gt; OR &lt;code&gt;Pointer null&lt;/code&gt;. This is called term querry.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;to search urls use &lt;code&gt;\&lt;/code&gt; or you will find syntax error OR try with &lt;code&gt;"&lt;/code&gt;.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http.request.referrer: "https://example.com"  
http.request.referrer: https\://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;[!Note] &lt;br&gt;
&lt;code&gt;\():&amp;lt;&amp;gt;"*&lt;/code&gt; excape These Charecters with &lt;code&gt;\&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Filter for documents within a range
&lt;/h2&gt;

&lt;p&gt;to search for all documents for which http.response.bytes is less than 10000, use the following syntax:&lt;br&gt;
&lt;code&gt;http.response.bytes &amp;lt; 10000&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;to search In Range use this&lt;br&gt;
&lt;code&gt;http.response.bytes &amp;gt; 10000 and http.response.bytes &amp;lt;= 20000&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Filter for documents using wildcards
&lt;/h2&gt;

&lt;p&gt;To search for documents matching a pattern, use the wildcard syntax. For example, to find documents where http.response.status_code begins with a 4, use the following syntax:&lt;/p&gt;

&lt;p&gt;http.response.status_code: 4*&lt;br&gt;
By default, leading wildcards are not allowed for performance reasons. You can modify this with the query:allowLeadingWildcards advanced setting.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[!Note]&lt;br&gt;
Only * is currently supported. This matches zero or more characters.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Negating a query
&lt;/h2&gt;

&lt;p&gt;use &lt;strong&gt;NOT&lt;/strong&gt; in front of querry like:&lt;br&gt;
&lt;code&gt;NOT http.request.method: GET&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Querying nested fields
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;.&lt;/code&gt; operater to query nested fields like:&lt;br&gt;
&lt;code&gt;user.names:{ first: "Alice" and last: "White" }&lt;/code&gt;&lt;/p&gt;

</description>
      <category>elk</category>
      <category>elasticsearch</category>
      <category>kql</category>
    </item>
    <item>
      <title>Installing Elastic Search 7.14 with docker</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Tue, 10 Sep 2024 04:52:53 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/installing-elastic-search-714-with-docker-4edn</link>
      <guid>https://dev.to/mallikarjunht/installing-elastic-search-714-with-docker-4edn</guid>
      <description>&lt;p&gt;Welcome to the ultimate guide on Elastic Search and Kibana! If you're looking for a powerful, open-source tool that can help you search, analyze, and visualize your data like never before, then look no further. In this comprehensive guide, we'll take you through everything you need to know about Elastic Search and Kibana - from what they are and how they work together to their installation with Docker. Whether you're a developer or just getting started with these tools, get ready to learn everything there is to know about using Elastic Search and Kibana with Docker in this exciting blog post!&lt;/p&gt;

&lt;h4&gt;
  
  
  Introduction to Elasticsearch and Kibana
&lt;/h4&gt;

&lt;p&gt;Elasticsearch is a powerful open source search and analytics engine that makes data easy to explore. Kibana is an open source data visualization platform that allows you to interact with your data through beautiful visualizations. In this guide, we'll show you how to use Docker to install and run Elasticsearch and Kibana on your local machine.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is Elastic Search?
&lt;/h4&gt;

&lt;p&gt;Elastic Search is a powerful, open source, distributed search and analytics engine. It is built on top of the Apache Lucene search library and supports full text search, as well as structured data search with SQL-like query syntax. Elastic Search can be used to power search for websites, applications, and enterprise search solutions. It is also commonly used for log analysis, monitoring, and security analytics.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is Kibana?
&lt;/h4&gt;

&lt;p&gt;Kibana is an open source data visualization plugin for the Elasticsearch stack. It provides a rich set of tools to help you visualize and explore your data in Elasticsearch. Kibana is a great way to get started with visualizing your data in Elasticsearch.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Install Elastic Search and Kibana with Docker
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;2.2'&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;node01&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;docker.elastic.co/elasticsearch/elasticsearch:7.14.1&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node01&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;node.name=node01&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;cluster.name=es-my-cluster&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;discovery.type=single-node&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;bootstrap.memory_lock=true&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ES_JAVA_OPTS=-Xms512m&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;-Xmx512m"&lt;/span&gt;
    &lt;span class="na"&gt;ulimits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;memlock&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;soft&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;-1&lt;/span&gt;
        &lt;span class="na"&gt;hard&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;-1&lt;/span&gt;
    &lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;data01:/usr/share/elasticsearch/data&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;9200:9200&lt;/span&gt;
    &lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;elastic&lt;/span&gt;
  &lt;span class="na"&gt;kib01test&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;docker.elastic.co/kibana/kibana:7.14.1&lt;/span&gt;
    &lt;span class="na"&gt;container_name &lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kib01test&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;ELASTICSEARCH_HOSTS=http://node01:9200&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;5601:5601&lt;/span&gt;
    &lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;elastic&lt;/span&gt;

&lt;span class="na"&gt;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;data01&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;driver&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;local&lt;/span&gt;

&lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;elastic&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;driver&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bridge&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>elasticsearch</category>
      <category>elk</category>
      <category>kibana</category>
      <category>docker</category>
    </item>
    <item>
      <title>ES - Node APIs</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Tue, 13 Aug 2024 09:40:44 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/es-node-apis-4fdk</link>
      <guid>https://dev.to/mallikarjunht/es-node-apis-4fdk</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# If no filters are given, the default is to select all nodes
curl -X GET "localhost:9200/_nodes?pretty"
# Explicitly select all nodes
curl -X GET "localhost:9200/_nodes/_all?pretty"
# Select just the local node
curl -X GET "localhost:9200/_nodes/_local?pretty"
# Select the elected master node
curl -X GET "localhost:9200/_nodes/_master?pretty"
# Select nodes by name, which can include wildcards
curl -X GET "localhost:9200/_nodes/node_name_goes_here?pretty"
curl -X GET "localhost:9200/_nodes/node_name_goes_*?pretty"
# Select nodes by address, which can include wildcards
curl -X GET "localhost:9200/_nodes/10.0.0.3,10.0.0.4?pretty"
curl -X GET "localhost:9200/_nodes/10.0.0.*?pretty"
# Select nodes by role
curl -X GET "localhost:9200/_nodes/_all,master:false?pretty"
curl -X GET "localhost:9200/_nodes/data:true,ingest:true?pretty"
curl -X GET "localhost:9200/_nodes/coordinating_only:true?pretty"
# Select nodes by custom attribute (e.g. with something like `node.attr.rack: 2` in the configuration file)
curl -X GET "localhost:9200/_nodes/rack:2?pretty"
curl -X GET "localhost:9200/_nodes/ra*:2?pretty"
curl -X GET "localhost:9200/_nodes/ra*:2*?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>ES - CAT APIs</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Tue, 13 Aug 2024 09:38:43 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/es-cat-apis-ilp</link>
      <guid>https://dev.to/mallikarjunht/es-cat-apis-ilp</guid>
      <description>&lt;h3&gt;
  
  
  cat APIs
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Introduction
&lt;/h4&gt;

&lt;p&gt;All the cat commands accept a query string parameter help to see all the headers and info they provide, and the /_cat command alone lists all the available commands.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common parameters
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Verbose - &lt;code&gt;curl -X GET "localhost:9200/_cat/master?v&amp;amp;pretty"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Help - &lt;code&gt;curl -X GET "localhost:9200/_cat/master?help&amp;amp;pretty"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Headers - &lt;code&gt;curl -X GET "localhost:9200/_cat/nodes?h=ip,port,heapPercent,name&amp;amp;pretty"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Numeric formats - &lt;code&gt;curl 'localhost:9200/_cat/indices?bytes=b' | sort -rnk8&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Response as text, json, smile, yaml or cbor - &lt;code&gt;curl 'localhost:9200/_cat/indices?format=json&amp;amp;pretty'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Sort - &lt;code&gt;curl -X GET "localhost:9200/_cat/templates?v&amp;amp;s=order:desc,index_patterns&amp;amp;pretty"&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  cat aliases
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/aliases?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat allocation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/allocation?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat count
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/count?v&amp;amp;pretty"

curl -X GET "localhost:9200/_cat/count/twitter?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat fielddata
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/fielddata?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat health
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/health?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat indices
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/indices?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apply Filter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/indices/twi*?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat un healthy index
&lt;/h3&gt;

&lt;p&gt;indices which are not ready&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/indices?v&amp;amp;health=yellow&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;sort by dock count&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/indices?v&amp;amp;s=docs.count:desc&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat master
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/master?v&amp;amp;pretty"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat nodes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/nodes?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.4/cat-nodes.html" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  cat pending tasks
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/pending_tasks?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat plugins
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/plugins?v&amp;amp;s=component&amp;amp;h=name,component,version,description&amp;amp;pretty"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat recovery
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/recovery?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat repositories
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/repositories?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  cat thread pool
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/thread_pool?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for field data visit &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.4/cat-thread-pool.html" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  cat shards
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/shards?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reasion for un assigned shared look &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.4/cat-shards.html" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;INDEX_CREATED | Unassigned as a result of an API creation of an index.&lt;/p&gt;

&lt;p&gt;CLUSTER_RECOVERED | Unassigned as a result of a full cluster recovery.&lt;/p&gt;

&lt;p&gt;INDEX_REOPENED | Unassigned as a result of opening a closed index.&lt;/p&gt;

&lt;p&gt;DANGLING_INDEX_IMPORTED | Unassigned as a result of importing a dangling index.&lt;/p&gt;

&lt;p&gt;NEW_INDEX_RESTORED | Unassigned as a result of restoring into a new index.&lt;/p&gt;

&lt;p&gt;EXISTING_INDEX_RESTORED | Unassigned as a result of restoring into a closed index.&lt;/p&gt;

&lt;p&gt;REPLICA_ADDED | Unassigned as a result of explicit addition of a replica.&lt;/p&gt;

&lt;p&gt;ALLOCATION_FAILED | Unassigned as a result of a failed allocation of the shard.&lt;/p&gt;

&lt;p&gt;NODE_LEFT | Unassigned as a result of the node hosting it leaving the cluster.&lt;/p&gt;

&lt;p&gt;REROUTE_CANCELLED | Unassigned as a result of explicit cancel reroute command.&lt;/p&gt;

&lt;p&gt;REINITIALIZED | When a shard moves from started back to initializing, for example, with shadow replicas.&lt;/p&gt;

&lt;p&gt;REALLOCATED_REPLICA | A better replica location is identified and causes the existing replica allocation to be cancelled. &lt;/p&gt;

&lt;h3&gt;
  
  
  cat segments
&lt;/h3&gt;

&lt;p&gt;this where your data is saved on the FS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/segments?v&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  snapshots
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/snapshots/repo1?v&amp;amp;s=id&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  templates
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_cat/templates?v&amp;amp;s=name&amp;amp;pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>elasticsearch</category>
      <category>kibana</category>
      <category>nosql</category>
      <category>elk</category>
    </item>
    <item>
      <title>ES - Index API - part 4</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Mon, 05 Aug 2024 08:04:39 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/es-index-api-part-4-3ech</link>
      <guid>https://dev.to/mallikarjunht/es-index-api-part-4-3ech</guid>
      <description>&lt;h3&gt;
  
  
  Indices Stats
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_stats?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Indices Segments
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/test/_segments?pretty"

curl -X GET "localhost:9200/test/_segments?verbose=true&amp;amp;pretty"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Indices Recovery
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/_recovery?human&amp;amp;pretty"

curl -X GET "localhost:9200/_recovery?human&amp;amp;detailed=true&amp;amp;pretty"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Indices Shard Stores
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# return information of only index test
curl -X GET "localhost:9200/test/_shard_stores?pretty"
# return information of only test1 and test2 indices
curl -X GET "localhost:9200/test1,test2/_shard_stores?pretty"
# return information of all indices
curl -X GET "localhost:9200/_shard_stores?pretty"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Clear Cache
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "localhost:9200/twitter/_cache/clear?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Flush
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "localhost:9200/twitter/_flush?pretty"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Synced Flush
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "localhost:9200/twitter/_flush/synced?pretty"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Refresh
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "localhost:9200/twitter/_refresh?pretty"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Force Merge
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "localhost:9200/twitter/_forcemerge?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>ES Index API - part 3</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Mon, 05 Aug 2024 07:47:49 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/es-index-api-part-3-1i76</link>
      <guid>https://dev.to/mallikarjunht/es-index-api-part-3-1i76</guid>
      <description>&lt;h3&gt;
  
  
  PUT Mappings
&lt;/h3&gt;

&lt;h4&gt;
  
  
  create index with mappings
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/twitter?pretty" -H 'Content-Type: application/json' -d'
{}'

curl -X PUT "localhost:9200/twitter/_mapping/_doc?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "email": {
      "type": "keyword"
    }
  }
}'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  update existing index
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/my_index?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "properties": {
            "first": {
              "type": "text"
            }
          }
        },
        "user_id": {
          "type": "keyword"
        }
      }
    }
  }
}'

curl -X PUT "localhost:9200/my_index/_mapping/_doc?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "name": {
      "properties": {
        "last": { 
          "type": "text"
        }
      }
    },
    "user_id": {
      "type": "keyword",
      "ignore_above": 100 
    }
  }
}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get Mappings
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/twitter/_mapping/_doc?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  GET field mapping
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/publications/_mapping/_doc/field/title?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>ES Index API- part 2</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Mon, 05 Aug 2024 07:33:31 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/es-index-api-part-2-3pmj</link>
      <guid>https://dev.to/mallikarjunht/es-index-api-part-2-3pmj</guid>
      <description>&lt;h3&gt;
  
  
  Delete Index
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X DELETE "localhost:9200/twitter?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get Index
&lt;/h3&gt;

&lt;p&gt;this will return mappings and settings if index exist&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X GET "localhost:9200/twitter?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  check if index exist
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -I "localhost:9200/twitter?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Open / Close Index API
&lt;/h3&gt;

&lt;p&gt;use this with caution - like updating or to prevent new document insertion - search will work but indexing will not work&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "localhost:9200/my_index/_close?pretty"
curl -X POST "localhost:9200/my_index/_open?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Shrink Index
&lt;/h3&gt;

&lt;p&gt;use this to reduce the number of shards for version &amp;lt; 7 it is 5 and above it is 1 shard.&lt;/p&gt;

&lt;h4&gt;
  
  
  Preparing an index for shrinking
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/my_source_index/_settings?pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.routing.allocation.require._name": "shrink_node_name", 
    "index.blocks.write": true 
  }
}
'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Shrinking an index
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "localhost:9200/my_source_index/_shrink/my_target_index?copy_settings=true&amp;amp;pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.routing.allocation.require._name": null, 
    "index.blocks.write": null 
  }
}
'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Shrinking with settings
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST "localhost:9200/my_source_index/_shrink/my_target_index?copy_settings=true&amp;amp;pretty" -H 'Content-Type: application/json' -d'
{
  "settings": {
    "index.number_of_replicas": 1,
    "index.number_of_shards": 1, 
    "index.codec": "best_compression" 
  },
  "aliases": {
    "my_search_indices": {}
  }
}
'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rollover Index
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Defining the new index
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/logs-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "aliases": {
    "logs_write": {}
  }
}'

curl -X POST "localhost:9200/logs_write/_rollover?pretty" -H 'Content-Type: application/json' -d'
{
  "conditions" : {
    "max_age": "7d",
    "max_docs": 1000,
    "max_size": "5gb"
  },
  "settings": {
    "index.number_of_shards": 2
  }
}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Dry run
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/logs-000001?pretty" -H 'Content-Type: application/json' -d'
{
  "aliases": {
    "logs_write": {}
  }
}'

curl -X POST "localhost:9200/logs_write/_rollover?dry_run&amp;amp;pretty" -H 'Content-Type: application/json' -d'
{
  "conditions" : {
    "max_age": "7d",
    "max_docs": 1000,
    "max_size": "5gb"
  }
}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>elasticsearch</category>
      <category>elk</category>
      <category>documentation</category>
      <category>nosql</category>
    </item>
    <item>
      <title>ES index API - part 1</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Mon, 05 Aug 2024 07:13:56 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/es-index-api-part-1-1km2</link>
      <guid>https://dev.to/mallikarjunht/es-index-api-part-1-1km2</guid>
      <description>&lt;h2&gt;
  
  
  Indices APIs
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Index management:
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create Index
Delete Index
Get Index
Indices Exists
Open / Close Index API
Shrink Index
Split Index
Rollover Index
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;### Mapping management:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Put Mapping
Get Mapping
Get Field Mapping
Types Exists
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Alias management:
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Index Aliases
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Index settings:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Update Indices Settings
Get Settings
Analyze
Index Templates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Monitoring:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Indices Stats
Indices Segments
Indices Recovery
Indices Shard Stores
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Status management:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Clear Cache
Refresh
Flush
Force Merge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Create Index
&lt;/h4&gt;

&lt;p&gt;index creation without any mappings&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/twitter?pretty"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: &lt;/p&gt;

&lt;p&gt;Index name limitations&lt;/p&gt;

&lt;p&gt;There are several limitations to what you can name your index. The complete list of limitations are:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Lowercase only
Cannot include \, /, *, ?, ", &amp;lt;, &amp;gt;, |, ` ` (space character), ,, #
Indices prior to 7.0 could contain a colon (:), but that’s been deprecated and won’t be supported in 7.0+
Cannot start with -, _, +
Cannot be . or ..
Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Index Settings
&lt;/h4&gt;

&lt;p&gt;To update index use this, in this payload we are setting number of shards and no of replicas&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/twitter?pretty" -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "number_of_shards" : 3,
        "number_of_replicas" : 2
    }
}
'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Mappings
&lt;/h4&gt;

&lt;p&gt;setting mappings to an index while creation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/test?pretty" -H 'Content-Type: application/json' -d'
{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "_doc" : {
            "properties" : {
                "field1" : { "type" : "text" }
            }
        }
    }
}
'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  setting Aliases on existing index
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
curl -XPUT localhost:9200/index1/_alias/index2&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
multiple Aliases and filtering&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X PUT "localhost:9200/test?pretty" -H 'Content-Type: application/json' -d'
{
    "aliases" : {
        "alias_1" : {},
        "alias_2" : {
            "filter" : {
                "term" : {"user" : "kimchy" }
            },
            "routing" : "kimchy"
        }
    }
}
'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>elasticsearch</category>
      <category>elk</category>
      <category>nosql</category>
      <category>documentation</category>
    </item>
    <item>
      <title>java prep - part 3</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Tue, 18 Jun 2024 02:42:49 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/java-prep-part-3-5c7e</link>
      <guid>https://dev.to/mallikarjunht/java-prep-part-3-5c7e</guid>
      <description>&lt;h3&gt;
  
  
  can we disable the default behaviour of spring explain with example
&lt;/h3&gt;

&lt;p&gt;Yes, in Spring Framework, you can disable or customize default behaviors by overriding configurations or using specific annotations to alter how Spring manages components and processes requests. Let's explore a couple of examples where you might want to disable default behaviors in Spring:&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1: Disabling Default Spring Security Configuration
&lt;/h3&gt;

&lt;p&gt;By default, Spring Security applies a set of security configurations to your application, including basic authentication and authorization rules. You might want to disable these default behaviors if you have custom security requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-step Example:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Disable Security Auto-Configuration&lt;/strong&gt;:
To disable Spring Security's default configuration, you can exclude the &lt;code&gt;SecurityAutoConfiguration&lt;/code&gt; class from auto-configuration in your main application class or configuration class.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.SpringApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.autoconfigure.SpringBootApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

   &lt;span class="nd"&gt;@SpringBootApplication&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exclude&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;SecurityAutoConfiguration&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;})&lt;/span&gt;
   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyApplication&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

       &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="nc"&gt;SpringApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@SpringBootApplication&lt;/code&gt; is annotated with &lt;code&gt;exclude = {SecurityAutoConfiguration.class}&lt;/code&gt;, which disables Spring Security's auto-configuration.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Customize Security Configuration&lt;/strong&gt;:
After disabling default configuration, you can then customize security settings by creating your own &lt;code&gt;SecurityConfig&lt;/code&gt; class and configuring it based on your specific requirements using &lt;code&gt;@EnableWebSecurity&lt;/code&gt; and extending &lt;code&gt;WebSecurityConfigurerAdapter&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.context.annotation.Configuration&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.security.config.annotation.web.configuration.EnableWebSecurity&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

   &lt;span class="nd"&gt;@Configuration&lt;/span&gt;
   &lt;span class="nd"&gt;@EnableWebSecurity&lt;/span&gt;
   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SecurityConfig&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;WebSecurityConfigurerAdapter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

       &lt;span class="nd"&gt;@Override&lt;/span&gt;
       &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;configure&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;HttpSecurity&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="c1"&gt;// Customize your security configuration here&lt;/span&gt;
           &lt;span class="n"&gt;http&lt;/span&gt;
               &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;authorizeRequests&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                   &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;antMatchers&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/public/**"&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;permitAll&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                   &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;anyRequest&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;authenticated&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                   &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;and&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
               &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;formLogin&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                   &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;loginPage&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/login"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                   &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;permitAll&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                   &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;and&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
               &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;logout&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
                   &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;permitAll&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This &lt;code&gt;SecurityConfig&lt;/code&gt; class provides customized security configurations, overriding the default behavior that was disabled.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 2: Disabling Spring Boot Banner
&lt;/h3&gt;

&lt;p&gt;Spring Boot displays a banner by default during application startup. You may want to disable this banner for specific reasons, such as cleaner log output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-by-step Example:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Disable Banner Programmatically&lt;/strong&gt;:
You can disable the banner programmatically by setting &lt;code&gt;spring.main.banner-mode&lt;/code&gt; property to &lt;code&gt;OFF&lt;/code&gt; in your &lt;code&gt;application.properties&lt;/code&gt; or &lt;code&gt;application.yml&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;   &lt;span class="py"&gt;spring.main.banner-mode&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;OFF&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration instructs Spring Boot not to display the banner during application startup.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Disable Banner via Configuration Class&lt;/strong&gt;:
Alternatively, you can disable the banner by creating a configuration class and using &lt;code&gt;SpringApplication.setBannerMode(Banner.Mode.OFF)&lt;/code&gt; in your main application class.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.Banner&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.SpringApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.autoconfigure.SpringBootApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

   &lt;span class="nd"&gt;@SpringBootApplication&lt;/span&gt;
   &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyApplication&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

       &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
           &lt;span class="nc"&gt;SpringApplication&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SpringApplication&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setBannerMode&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Banner&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Mode&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;OFF&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
           &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
       &lt;span class="o"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;SpringApplication.setBannerMode(Banner.Mode.OFF)&lt;/code&gt; disables the banner explicitly for the &lt;code&gt;MyApplication&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Spring Framework provides flexibility to disable default behaviors by excluding auto-configurations, overriding configuration classes, or configuring properties. This approach allows developers to customize Spring applications according to specific requirements, ensuring that the framework's default behaviors align with application needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  How caching works with example/ archtecture diagram as code
&lt;/h3&gt;

&lt;p&gt;Caching in software systems, including those built with Spring Boot, involves storing frequently accessed data in a faster access storage to improve performance and reduce load on backend systems.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.cache.annotation.Cacheable&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.stereotype.Service&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@Service&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@Cacheable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"usersCache"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"#userId"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="nf"&gt;getUserDetails&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Long&lt;/span&gt; &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Simulate fetching user details from a database&lt;/span&gt;
        &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;userRepository&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;findById&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Enable caching
spring.cache.type=ehcache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  with Redis example
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.io.Serializable&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;Serializable&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;isbn&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;author&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Getters and setters (omitted for brevity)&lt;/span&gt;

    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Book{"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                &lt;span class="s"&gt;"isbn='"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;isbn&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sc"&gt;'\''&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                &lt;span class="s"&gt;", title='"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sc"&gt;'\''&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                &lt;span class="s"&gt;", author='"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;author&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sc"&gt;'\''&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
                &lt;span class="sc"&gt;'}'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.beans.factory.annotation.Autowired&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.data.redis.core.RedisTemplate&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.stereotype.Service&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@Service&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BookService&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;final&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="no"&gt;REDIS_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"books"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;@Autowired&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;RedisTemplate&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;redisTemplate&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;saveBook&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;redisTemplate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;opsForHash&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;put&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;REDIS_KEY&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getIsbn&lt;/span&gt;&lt;span class="o"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Book&lt;/span&gt; &lt;span class="nf"&gt;getBook&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;isbn&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Book&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="n"&gt;redisTemplate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;opsForHash&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;REDIS_KEY&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;isbn&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;deleteBook&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;isbn&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;redisTemplate&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;opsForHash&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;delete&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="no"&gt;REDIS_KEY&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;isbn&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>java interview prep part 2</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Tue, 18 Jun 2024 02:25:52 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/java-interview-prep-part-2-300i</link>
      <guid>https://dev.to/mallikarjunht/java-interview-prep-part-2-300i</guid>
      <description>&lt;h3&gt;
  
  
  Explain restcontroller annotation in springboot
&lt;/h3&gt;

&lt;p&gt;In Spring Boot, @RestController is a specialized version of the @Controller annotation. It is used to indicate that the class is a RESTful controller that handles HTTP requests and directly maps them to the methods inside the class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.web.bind.annotation.GetMapping&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.web.bind.annotation.RestController&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@RestController&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloController&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="nd"&gt;@GetMapping&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/hello"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Hello, World!"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Purpose of @RestController:&lt;br&gt;
API Endpoint Handling:&lt;/p&gt;

&lt;p&gt;@RestController combines @Controller and @ResponseBody. It is primarily used to create RESTful web services where HTTP requests (GET, POST, PUT, DELETE, etc.) are mapped directly to the methods in the class.&lt;br&gt;
Automatic JSON/XML Conversion:&lt;/p&gt;

&lt;p&gt;Methods in a @RestController return domain objects directly. Spring Boot automatically converts these objects into JSON or XML responses (based on the Accept header of the request) using Jackson or another configured message converter.&lt;br&gt;
Simplification of Controller Code:&lt;/p&gt;

&lt;p&gt;By annotating a class with @RestController, developers can streamline the code as they no longer need to add @ResponseBody to every request handling method.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explain microstructure architecture
&lt;/h3&gt;

&lt;p&gt;Microservices Architecture:&lt;br&gt;
Microservices Architecture is an architectural style that structures an application as a collection of loosely coupled services. Each service is self-contained, independently deployable, and typically focuses on performing a single business function.&lt;/p&gt;

&lt;p&gt;Benefits of Microservices Architecture:&lt;br&gt;
Scalability: Individual microservices can be scaled independently based on demand.&lt;br&gt;
Flexibility and Agility: Enables rapid development, deployment, and updates of services.&lt;br&gt;
Improved Fault Isolation: Failures are contained within a single service, reducing impact on the overall system.&lt;br&gt;
Technology Diversity: Allows for the use of different technologies and frameworks for different services.&lt;br&gt;
Enhanced Maintainability: Smaller, focused services are easier to understand, modify, and maintain compared to monolithic applications.&lt;/p&gt;

&lt;p&gt;Challenges:&lt;br&gt;
Increased Complexity: Managing a distributed system introduces complexity in deployment, testing, monitoring, and debugging.&lt;br&gt;
Data Management: Maintaining consistency and managing data across multiple services can be challenging.&lt;br&gt;
Service Discovery and Communication: Ensuring reliable communication and discovering services dynamically in a distributed environment.&lt;br&gt;
Operational Overhead: Requires robust infrastructure and operational practices to support and monitor microservices effectively.&lt;/p&gt;

&lt;p&gt;Microservices architecture can be categorized into several types or patterns, each emphasizing different aspects of service decomposition, communication patterns, and deployment strategies. Here are some common types of microservices architecture patterns:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Monolithic Application Decomposition&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: In this approach, a monolithic application is decomposed into smaller services, but each service may still be relatively large and cohesive compared to other microservices architectures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Characteristics&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Services are typically larger and might handle multiple related functionalities.&lt;/li&gt;
&lt;li&gt;Often uses synchronous communication (e.g., RESTful APIs) between services.&lt;/li&gt;
&lt;li&gt;Deployment and scaling are often handled per service, but still may share some components (e.g., databases).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Layered Architecture&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Services are organized into layers, where each layer represents a set of related functionalities or responsibilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Characteristics&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Each layer may be implemented as one or more microservices.&lt;/li&gt;
&lt;li&gt;Communication between layers can be synchronous or asynchronous.&lt;/li&gt;
&lt;li&gt;Promotes separation of concerns and scalability within each layer.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Event-Driven Architecture&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Services communicate through events (messages) asynchronously. Events represent state changes or significant actions within the system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Characteristics&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Services are decoupled and communicate through message brokers or event buses.&lt;/li&gt;
&lt;li&gt;Enables loose coupling and scalability by allowing services to react to events without direct dependencies.&lt;/li&gt;
&lt;li&gt;Supports eventual consistency and fault isolation.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;API Gateway Pattern&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: An API Gateway acts as a single entry point for clients to interact with multiple microservices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Characteristics&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Provides a unified interface for clients, routing requests to appropriate microservices.&lt;/li&gt;
&lt;li&gt;May handle authentication, rate limiting, and request aggregation.&lt;/li&gt;
&lt;li&gt;Improves client-side performance and simplifies the client's view of the system architecture.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  5. &lt;strong&gt;Service Mesh&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: A dedicated infrastructure layer for handling service-to-service communication, including load balancing, service discovery, encryption, and monitoring.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Characteristics&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Enhances visibility, reliability, and security of microservices communication.&lt;/li&gt;
&lt;li&gt;Typically implemented using a sidecar proxy (e.g., Envoy) alongside each microservice instance.&lt;/li&gt;
&lt;li&gt;Allows centralized management of microservices communication policies.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  6. &lt;strong&gt;Saga Pattern&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Handles long-lived transactions that span multiple microservices, ensuring eventual consistency without distributed transactions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Characteristics&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Uses a series of local transactions (compensating actions) within each microservice.&lt;/li&gt;
&lt;li&gt;Coordination and orchestration are typically managed by a Saga orchestrator.&lt;/li&gt;
&lt;li&gt;Enables rollback and compensation in case of failures, ensuring data consistency across microservices.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  7. &lt;strong&gt;Containerization and Orchestration&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description&lt;/strong&gt;: Microservices are deployed as lightweight, isolated containers (e.g., Docker) and orchestrated using platforms like Kubernetes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Characteristics&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Simplifies deployment, scaling, and management of microservices.&lt;/li&gt;
&lt;li&gt;Provides infrastructure automation and supports microservices resilience.&lt;/li&gt;
&lt;li&gt;Enables efficient resource utilization and scalability through container orchestration.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;Each type of microservices architecture pattern offers distinct advantages and is suitable for different scenarios based on scalability needs, communication requirements, and operational considerations. The choice of architecture pattern depends on factors such as application complexity, team expertise, scalability requirements, and operational goals.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Java prep for 3+ years</title>
      <dc:creator>Mallikarjun H T</dc:creator>
      <pubDate>Tue, 18 Jun 2024 02:09:00 +0000</pubDate>
      <link>https://dev.to/mallikarjunht/java-prep-for-3-years-4n8b</link>
      <guid>https://dev.to/mallikarjunht/java-prep-for-3-years-4n8b</guid>
      <description>&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Tell me the difference between Method Overloading and Method&lt;br&gt;
Overriding in Java. with example&lt;/p&gt;

&lt;p&gt;Method Overloading:&lt;br&gt;
Method Overloading refers to defining multiple methods in the same class with the same name but different parameters. The methods can differ in the number of parameters, type of parameters, or both.&lt;/p&gt;

&lt;p&gt;Key Points:&lt;/p&gt;

&lt;p&gt;Method overloading is achieved within the same class.&lt;br&gt;
It is also known as compile-time polymorphism or static polymorphism.&lt;br&gt;
The return type may or may not be different, but the parameters must differ in type, sequence, or number.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OverloadingExample&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="c1"&gt;// Method with the same name but different parameters&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Overloaded method with different parameter types&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Overloaded method with different number of parameters&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Overloaded method with different sequence of parameters&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Method Overriding:&lt;br&gt;
Method Overriding occurs when a subclass provides a specific implementation of a method that is already provided by its superclass. The method in the subclass has the same name, parameter list, and return type as the method in the parent class.&lt;/p&gt;

&lt;p&gt;Key Points:&lt;/p&gt;

&lt;p&gt;Method overriding is achieved between a superclass and its subclass.&lt;br&gt;
It is also known as runtime polymorphism or dynamic polymorphism.&lt;br&gt;
The method signatures (name, parameters, return type) must be identical in both the superclass and subclass.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Superclass&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Animal makes a sound"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Subclass overriding the makeSound() method&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dog barks"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;animal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;animal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Animal makes a sound&lt;/span&gt;

        &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="n"&gt;dog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;dog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Dog barks&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;ol&gt;
&lt;li&gt; What do you mean by the class loader in Java? &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It seems like you're summarizing the types of built-in class loaders in Java, and you've provided an overview of each type. Let's elaborate on each type of class loader based on your description:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Bootstrap Classloader
&lt;/h3&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- **Description**: The Bootstrap Classloader is the first class loader that initiates when the JVM starts up. It is responsible for loading core Java classes from the bootstrap classpath, which typically includes the `rt.jar` file (or `classes.jar` in older JDK versions). These classes form the Java Standard Edition libraries.

- **Loaded Classes**: Classes loaded by the Bootstrap Classloader include fundamental Java classes like those in `java.lang`, `java.net`, `java.util`, `java.io`, `java.sql`, etc.

### 2. Extension Classloader

- **Description**: The Extension Classloader is the child class loader of the Bootstrap Classloader. It loads classes from the JDK's extension directories (`$JAVA_HOME/jre/lib/ext` by default). These directories contain optional extensions to the standard core Java classes.

- **Loaded Classes**: Classes loaded by the Extension Classloader typically include classes from JAR files located in `$JAVA_HOME/jre/lib/ext`.

### 3. System Application Classloader (Application Classloader)

- **Description**: The System Application Classloader, also known as the Application Classloader, is the child class loader of the Extension Classloader. It loads classes from the application classpath, which is set by the `CLASSPATH` environment variable or specified explicitly using the `-cp` or `-classpath` command-line option.

- **Loaded Classes**: Classes loaded by the Application Classloader include application-specific classes and third-party libraries that are included in the classpath.

### Class Loading Hierarchy Summary:

- **Bootstrap Classloader**: Loads core Java classes (`java.lang`, `java.util`, etc.) from the bootstrap classpath.
- **Extension Classloader**: Loads classes from extension directories (`$JAVA_HOME/jre/lib/ext`).
- **Application Classloader**: Loads classes from the application classpath (specified by `CLASSPATH` or `-cp` option).

### Why Understanding Class Loaders is Important:

- **Class Loading Flexibility**: Java's class loading mechanism allows applications to dynamically load classes at runtime, enabling features like plugin systems, dynamic class loading, and hot swapping.
- **Security and Isolation**: Class loaders provide a level of security and isolation, ensuring that classes from different sources (system libraries, extensions, applications) do not interfere with each other.
- **Customization**: Developers can create custom class loaders to load classes from non-standard sources or apply specific loading policies.

Overall, understanding the role of each built-in class loader in Java helps developers grasp how classes are loaded and managed within the JVM environment, facilitating effective application development and runtime behavior management.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;What do you mean by inheritance in Java?&lt;/p&gt;

&lt;p&gt;In Java, inheritance is a mechanism through which an object acquires all the properties and behavior of another class. It is usually used for Method Overriding and Code Reusability.&lt;/p&gt;

&lt;p&gt;The concept of inheritance in Java is based on the fact that it creates new classes that are built upon the existing classes. Therefore, these methods and fields of the parent class can be reused if we inherit from an existing class. And also, we can add new methods and fields to our current class.&lt;/p&gt;

&lt;p&gt;In Java, the inheritance is of five types-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hybrid Inheritance&lt;/li&gt;
&lt;li&gt;Hierarchical Inheritance&lt;/li&gt;
&lt;li&gt;Single-level Inheritance&lt;/li&gt;
&lt;li&gt;Multi-level Inheritance&lt;/li&gt;
&lt;li&gt;Multiple Inheritance
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Superclass&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Field&lt;/span&gt;
    &lt;span class="kd"&gt;protected&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Constructor&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Animal&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Method&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;eat&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" is eating."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Subclass inheriting from Animal&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Constructor&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nf"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;super&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Call to superclass constructor&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Additional method specific to Dog&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;bark&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" is barking."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Main class to demonstrate inheritance&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Create an instance of Dog&lt;/span&gt;
        &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="n"&gt;myDog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Buddy"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Access inherited method from Animal&lt;/span&gt;
        &lt;span class="n"&gt;myDog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;eat&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Buddy is eating.&lt;/span&gt;

        &lt;span class="c1"&gt;// Access method specific to Dog&lt;/span&gt;
        &lt;span class="n"&gt;myDog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;bark&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Buddy is barking.&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Why can we not override the static method in Java?&lt;/p&gt;&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;The reasons why we cannot override the static method in Java are :&lt;/p&gt;

&lt;p&gt;(a) The static method does not belong to the object level. Instead, it belongs to the class level. The object decides which method can be called in the method overriding.&lt;/p&gt;

&lt;p&gt;(b) In the static method, which is the class level method, the type reference decides on which method is to be called without referring to the object. It concludes that the method that is called is determined at the compile time.&lt;/p&gt;

&lt;p&gt;If any child class defines the static method with the same signature as the parent class, then the method in the child class hides the method in the parent class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SuperClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;staticMethod&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Static method in SuperClass"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SubClass&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;SuperClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;staticMethod&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Static method in SubClass"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;SuperClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;staticMethod&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Static method in SuperClass&lt;/span&gt;
        &lt;span class="nc"&gt;SubClass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;staticMethod&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;   &lt;span class="c1"&gt;// Output: Static method in SubClass&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Can you tell us what the Dynamic Method Dispatch is in Java?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Dynamic Method Dispatch in Java refers to the mechanism by which the correct method implementation is determined at runtime, based on the object type rather than the reference type. It enables polymorphic behavior in Java, allowing a subclass to provide a specific implementation of an inherited method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Animal makes a sound"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dog barks"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Cat meows"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;animal1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Dog object&lt;/span&gt;
        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;animal2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Cat object&lt;/span&gt;

        &lt;span class="n"&gt;animal1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Dog barks&lt;/span&gt;
        &lt;span class="n"&gt;animal2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;makeSound&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: Cat meows&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
