<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abhishek Gururani on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Gururani on Medium]]></description>
        <link>https://medium.com/@abhishekgururani?source=rss-c7d3eb8b576------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6q1Pt0yYED_Y7k0kFIH4Hw.jpeg</url>
            <title>Stories by Abhishek Gururani on Medium</title>
            <link>https://medium.com/@abhishekgururani?source=rss-c7d3eb8b576------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 00:19:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhishekgururani/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The problem of threesome.]]></title>
            <link>https://abhishekgururani.medium.com/the-problem-of-threesome-e29569551972?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/e29569551972</guid>
            <category><![CDATA[java-dsa]]></category>
            <category><![CDATA[sad]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Tue, 04 Aug 2026 20:59:04 GMT</pubDate>
            <atom:updated>2026-08-04T20:59:04.750Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yZxtFIQNpwocgGw8MGhFTg.png" /><figcaption>Thumbnail</figcaption></figure><p>Well, don’t get me wrong, it’s this LC medium — <a href="https://leetcode.com/problems/3sum/description/">https://leetcode.com/problems/3sum/description/</a></p><p>The idea is to blurt out <strong>all</strong> the <strong>3 numbers</strong> which <strong>sum up to zero</strong>. How can the sum be zero? because there are negative numbers as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*-sevNLw0ET6Mlb-p9C5ddQ.png" /><figcaption>LC Screenshot</figcaption></figure><p>Let’s take a test case : nums = [-1, 0, 1, 2, -1, -4]</p><blockquote>It’s a problem of Arrays, and if don’t know what to do, sorting it up usually simplifies the data, and gives inspirations.</blockquote><p>after sorting : nums = [-4, -1, -1, 0, 1, 2]</p><p>Now I’ll have to think in loops, let me pick the first number for my triplet, [-4], now from the rest of the array I need to find out 2 numbers that sum up to 4. I can do the next part in many ways but as the array is sorted. I can use two-pointers.</p><p>Simple problem, but here’s a catch to the problem statement,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*BbD0EQhuWvu-ze2IAj-ltg.png" /><figcaption>LC Screenshot</figcaption></figure><p>How to make sure the triplet is unique.</p><ol><li>Make sure the first digit is not repeated, cases like [1, X, X], [1, X, X]…</li><li>Make sure the second digit is not repeated, cases like [1, 1, X], [1, 1, X]…</li><li>If first and second digits are ensured to be unique then the 3rd digit will manage itself.</li></ol><pre>class Solution {<br>    public List&lt;List&lt;Integer&gt;&gt; threeSum(int[] nums) {<br>        int len = nums.length; // good to have lenght stored somewhere<br>        Arrays.sort(nums); // sort nums, to avoid consecutive duplicates<br>        List&lt;List&lt;Integer&gt;&gt; res = new ArrayList&lt;&gt;(); // result array<br><br>        // pick ith element, <br>        for(int idx = 0; idx &lt; len; idx++) {<br>            int a = nums[idx];  <br>            // to avoid duplicates this element should not be equal to previous element, <br>            if(idx &gt; 0 &amp;&amp; a == nums[idx-1]) {<br>                continue; <br>            }<br><br>            // we&#39;ve ensured that the first element is unique <br>            // use two pointers to find the next two elements<br>            int jdx = idx + 1, kdx = len - 1, tSum = -1 * a; <br>            while(jdx &lt; kdx) {<br>                if(nums[jdx] + nums[kdx] == tSum) {<br>                    // we&#39;ve found a triplet - add it to the result.<br>                    res.add(List.of(a, nums[jdx], nums[kdx])); <br>                    // this can be of the form [1, 1, X], we need to ensure that [1, 1, X] is <br>                    // not repeated, making sure the second number doesn&#39;t repeat.  <br>                    // what to do now? <br>                    // break? - Nope, we might find more numbers that together with unique first number sum up to zero<br>                    // move pointers, how? - Move jth pointer, sure it&#39;s unique<br>                    // as the array is sorted, make sure it is not equal to the previous one. <br>                    jdx++; <br>                    while(nums[jdx] == nums[jdx-1] &amp;&amp; jdx &lt; kdx) jdx++; <br>                } else if(nums[jdx] + nums[kdx] &gt; tSum) {<br>                    kdx--; // two pointer logic - sum is greater than expected sum : move right pointer to the left<br>                } else {<br>                    jdx++; // two pointer logic - sum is lesser than expected sum : move left pointer to the right <br>                }<br>            }    <br><br>        }<br>        return res; // return result<br>    <br>    }<br>}</pre><p>Hopefully this will solve your problem of threesome. XD.</p><p>Regards.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e29569551972" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maven, a build automation tool for Java projects.]]></title>
            <link>https://abhishekgururani.medium.com/maven-a-build-automation-tool-for-java-projects-55dd35a0b70e?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/55dd35a0b70e</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[maven]]></category>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Tue, 09 Jun 2026 07:04:47 GMT</pubDate>
            <atom:updated>2026-06-12T19:45:57.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3FydrLzNt890lnG9TuLoQ.png" /><figcaption>Thumbnail for the article</figcaption></figure><p>When you use a framework, you require dependencies, but manually adding these dependencies is a tedious task. Suppose you need Spring MVC, it’ll require Spring Core, which will require Commons Logging and so on. Missing to include even one dependency in your project will lead to build failure.</p><p><strong>Here’s another problem,</strong> the dependencies are compatible on the basis of versions, a few mismatches and you’ll run through what is called <em>the JAR hell.</em></p><h4>Here’s another scenario</h4><p>If you’re building a modern Java Project the code will probably have thousands of classes, million lines code, more than a hundred external dependencies(Spring, Lombok, Hibernate, etc)<br>If we want to compile and build it, the programmer might have to compile thousands of classes, and add compatible versions of more than hundred external dependencies. But we don’t do that, do we? So what actually helps the programmer? <em>Let’s see through a Java Spring Boot project.</em></p><p>Below is a bootstrapped project, I created it using a build tool call Maven, it works, but I don’t remember adding the below dependencies manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4GsRx2IM2fN7ZQQeefw1g.png" /><figcaption>Snip of a Java Project</figcaption></figure><p>So how did they automatically get added? I remember adding below statement in POM.xml file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0WjjckwI9Fm91_1BHTufIw.png" /><figcaption>Snip of POM.xml file</figcaption></figure><p>This is an entry in POM.xml file, think of POM.xml as an “instruction manual” that Maven uses to build and manage your project. Maven will automatically download the JAR for these dependencies. And it will also download all the transitive dependencies, which means not just Spring-Boot-Starter but Spring Core, and Common Logging as well.</p><blockquote><strong>But what is Maven?</strong></blockquote><p>Maven is one of the most popular build automation tool. It standardizes project structure, dependency management, build lifecycle.</p><p>In a nutshell, <em>“You focus on the code, and let Maven handle the assembly.”</em></p><blockquote><strong>Where is Maven downloading all this from?</strong></blockquote><p>That’s where the idea of Maven repository comes from. Maven utilises a dual repository structure. Central, and Local. <br>Maven gets directive from the POM.xml file, and when the build is triggered it checks for the dependency in Central Maven repository. If the dependency is found it caches it in Local Repository(~/.m2/repository) from where it can be used in future.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suGzWAsHFvD9-DEYiIAWNw.png" /><figcaption>Maven JAR download flow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sae9HHuWMMDPxhWSIrbGYg.png" /><figcaption>Snip of Maven Central Search Engine</figcaption></figure><blockquote>Bonus : if you’re wondering who manages Maven Central, a lot of people wrongly assume that Maven Central repository is maintained by Apache, but instead it is maintained by another software company called <strong>Sonatype</strong>. If you’ve worked for a private organisation then you must have heard the word “Nexus Respository”. Think of it as a <strong>private Maven Central for your company.</strong></blockquote><p>Maven also enforces a standard folder structure, this <strong>standardizes </strong>a project structure across all Maven projects, making it easier for developers to switch between multiple projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SHSHrP89kupTe4MbtAljOg.png" /><figcaption>Snip of folder structure standardized by Maven.</figcaption></figure><p>Maven commands run in specific order, <em>validate -&gt; compile -&gt; test -&gt; package -&gt; verify -&gt; install -&gt; deploy. Which means if you use </em><strong><em>Maven Deploy</em></strong><em> all the commands before it will get auto triggered.</em></p><blockquote><strong>Spring x Maven : Maven and Spring goes hand in hand.</strong></blockquote><p>Maven simplifies the process of building Spring Applications. Take a Spring Boot application for example. Below is its POM.xml, you’ll see how I’ve added <em>“spring-boot-starter” </em>in the dependency section. Maven will resolve this and will download not just this but all the required transitive dependeices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m2cTN-uK9FAnIq5xnDfsng.png" /><figcaption>snip from POM.xml</figcaption></figure><p>In IntelliJ IDEA there is a separate section for Maven menu here you’ll see all the dependencies that are resolved by Maven(downloaded + cached + added)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dkdccaiZS_aQU-MRj62S6A.png" /><figcaption>Snip from Maven menu in IntellijIdea</figcaption></figure><p><strong>POM Chaining<br></strong>When we add a dependency like <em>spring-boot-starter</em> it brings with it <em>spring-boot-starter-4.0.4.pom.xml, </em>this will further have POM.xml for all the transitive dependencies, say <em>spring-boot-starter-logging, which will in turn bring with itself spring-boot-starter-logging-4.0.4.pom.xml. </em>This model is followed by Maven, and I call it <strong>POM chaining.</strong></p><p>Let’s check the dependency tree using the below command,</p><pre>mvn dependency: tree</pre><p>The command failed for me, because Maven Dependency Plugin is not installed. The below command will first download the maven-dependency-plugin, and then will run it.</p><pre>mvn org.apache.maven.plugins:maven-dependency-plugin:tree</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMKG411o-14Yv7Sm3UKUIA.png" /><figcaption>snip of the output of mvn dependecy: tree command</figcaption></figure><p>This tree shows under which dependency the transitive dependencies are downloaded.</p><p><strong>Spring Specific Plugins</strong></p><p>Maven also provides with plugins that are specific to Spring projects. Take the below Spring Boot project for example, you can see multiple Maven plugins that can be used to run/start/stop/run tests/etc.. for the Spring Application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pshehT3gKrI_oO8OzeLRXw.png" /><figcaption>snip of Maven Plugins specific to Spring Boot Application.</figcaption></figure><p>We can summarise that Maven is a build automation tool that simplifies the build process for Java Applications. It does so by following a central POM.xml that works as its instruction manual to download the dependencies. It follows a structure of what I call <strong>POM Chaining</strong>, that helps to resolve transitive dependencies. It also provides us with commands that run in a specific order, and plugins that provides us with commands specific to the Java Project. This is all for today, check this link to <a href="https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html">Learn Maven in 5 mins</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55dd35a0b70e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RestAPIs using Spring Boot 4 and MongoDB]]></title>
            <link>https://abhishekgururani.medium.com/mongodb-using-springboot-4-3da4fba02783?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/3da4fba02783</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Tue, 02 Jun 2026 15:57:19 GMT</pubDate>
            <atom:updated>2026-06-02T16:24:58.750Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I got a chance to attend <a href="https://medium.com/u/db5cd12199bd">MongoDB</a> day hosted by the MongoDB team in collaboration with my organisation. This turned out to be a great opportunity to learn about the technicalities of MongoDB from the people who are actually building it. In order to get my hands dirty, I built some CRUD SpringBoot RestAPIs while using MongoDB as the primary database.</p><p>Documenting the process for doing so in this article. Also find the Github repository link below.</p><p>To interact with MongoDB database using SpringBoot we need <a href="https://spring.io/projects/spring-data-mongodb#overview"><em>Spring Data MongoDB</em></a>, which is part of umbrella Spring Data offering.</p><p>Before going forward, let’s get some idea about MongoDB.</p><p>MongoDB is designed for general purpose mission critical workloads. It’s an expressive query language, that supports ACID transactions, Security, and management. It’s a NoSQL DB, which means the data is not stored in the traditional SQL way. It’s made for scale and distribution, and it supports multiple clouds.</p><p>MongoDB stores data in BSON format, which refers to Binary JSON format. <br>The data in MongoDB is stored in the form of collections/and documents. If like me you come from SQL database, t<strong>hink of a collection as a table and a document as a row</strong>, but in an un-structured/NoSQL way.</p><p><strong><em>Term to remember in MongoDB : “Collections have Documents”</em></strong></p><p>Let’s create a data class, make sure to annotate id field, this is required as every document in a collection has a unique _id. Below is the code snippet for model, please note that this serves as an example data class for Books Management CRUD service.</p><pre>package com.example.mongodb.data;<br><br>import lombok.AllArgsConstructor;<br>import lombok.Data;<br>import lombok.NoArgsConstructor;<br>import org.springframework.data.annotation.Id;<br>import org.springframework.data.mongodb.core.mapping.Document;<br><br>@Document(collection = &quot;books&quot;)<br>@Data<br>@NoArgsConstructor<br>@AllArgsConstructor<br>public class Book {<br><br>    @Id<br>    private String id;<br><br>    private String name;<br>    private String author;<br>    private Double price;<br>    private String genre;<br>    private Integer publishedYear;<br>}</pre><p>Once the data class is ready, let’s dive into framing the Books Management Service with Repository — Service — Controller architecture pattern.</p><p>I will now create a repository interface, that will extend MongoRepository Interface. Spring will automatically generate queries from the method names.</p><pre>package com.example.mongodb.data;<br><br>import org.springframework.data.mongodb.repository.MongoRepository;<br>import org.springframework.stereotype.Repository;<br><br>import java.util.List;<br><br>@Repository<br>public interface BookRepository extends MongoRepository&lt;Book, String&gt; {<br><br>    List&lt;Book&gt; findByAuthor(String author);<br><br>    List&lt;Book&gt; findByGenre(String genre);<br><br>    List&lt;Book&gt; findByPriceLessThan(Double price);<br><br>    List&lt;Book&gt; findAll();<br><br>}</pre><p>I will run the MongoDB instance on docker, and will expose it on the port number : 27017, you can use the below docker-compose.yml.</p><pre>services:<br>  mongodb:<br>    image: mongo:latest<br>    container_name: mongodb<br><br>    ports:<br>      - &quot;27017:27017&quot;<br><br>    volumes:<br>      - mongo_data:/data/db<br><br>volumes:<br>  mongo_data:</pre><blockquote>in application.properties make sure to add mongoDB path, also please be noted, <strong><em>spring.data.mongodb.uri </em></strong>is changed to <strong><em>spring.mongodb.uri</em></strong>, from Spring 4.0.0 onwards. <a href="https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-4.0-Configuration-Changelog">Link</a> to 4.0.0 configuration changes.</blockquote><pre>spring.mongodb.uri=mongodb://localhost:27017/books</pre><p>We can also use MongoDB shell to query, update and manage data interactively.</p><pre>docker exec -it mongodb mongosh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9aJH6vIkrgdqIjqBF9ScRw.png" /><figcaption>Dummy Record</figcaption></figure><p>We’ll try to fetch this dummy record through the API call.</p><blockquote>calling <a href="http://localhost:8080/books/author/Abhishek">http://localhost:8080/books/author/Abhishek</a> Gururani</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2skeThauZJtPEiJ1E0ygUg.png" /><figcaption>insomnia response for getBooksByAuthor()</figcaption></figure><blockquote>calling <a href="http://localhost:8080/books">http://localhost:8080/books</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGVojN6Oq7DtziID-kQMzQ.png" /><figcaption>insomnia response for getAllBooks()</figcaption></figure><blockquote>calling <a href="http://localhost:8080/books/price/500">http://localhost:8080/books/price/500</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3awAux37IqCho2RlregEw.png" /><figcaption>insomnia response for getBooksUnderX</figcaption></figure><p>Against the methods in repository one can see the generated mongoDB backend queries in the logs. Below is the query generated for <em>findByPriceLessThan() </em>repository method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVzxPYuEdrNuHa9kmaxmlg.png" /><figcaption>query created against findByPriceLessThan() repository method</figcaption></figure><p>Here is the <a href="https://github.com/gururani-abhishek/mongoDB-demo-springboot4.0.0/tree/main">Github Link</a> for the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m2Ckvw34E-ooqkA2_8dtyQ.png" /><figcaption>thumbnail</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3da4fba02783" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the “Repository” in Spring Boot MVC]]></title>
            <link>https://abhishekgururani.medium.com/exploring-the-repository-in-spring-boot-mvc-856f8d7949f4?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/856f8d7949f4</guid>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Sat, 16 May 2026 14:00:58 GMT</pubDate>
            <atom:updated>2026-05-16T14:00:58.181Z</atom:updated>
            <content:encoded><![CDATA[<p>In most modern Restful APIs, the Repository is where the logic for DB Queries, CRUD operations, JPA/Hibernate interactions are put. It is supposed to be a dumb layer, with the sole purpose of reading and returning from the DB.</p><p>In this article, I’ll shed light on 4 standard ways we can write Repository for a Rest API using the Spring Boot MVC framework. Every style builds on the previous one, abstracts a lot boilerplate code, and make it more modular. But as they say “the devil lies in the progression”, so let’s see how it started with plain PreparedStatement objects in JDBC to abstracted EntityManagers in Spring Data JPA. Let’s begin,</p><h4>using JDBC</h4><p>JDBC stands for Java Database Connectivity API, it provides us with a set of APIs that can be used to connect with a database. Below is an example of a JDBC Repository that interacts with H2 in-memory database.</p><pre>@Repository<br>public class JDBCRepository {<br>    private String url = &quot;############&quot;;  // in-memory DB<br>    private String user = &quot;############&quot;;<br>    private String password = &quot;############&quot;;<br><br>    private String query = &quot;SELECT empId, leaves FROM leave where empId = ?&quot;;<br><br>    public Leave getLeavesByEmpId(Integer empId) {<br>        try (<br>            Connection conn = DriverManager.getConnection(url, user, password);<br>            PreparedStatement stmt = conn.prepareStatement(query);<br>        ) {<br>            stmt.setLong(1, empId);<br><br>            ResultSet rs = stmt.executeQuery();<br>            if(rs.next()) {<br>                Leave leave = new Leave();<br>                leave.setEmpId(rs.getInt(&quot;empId&quot;));<br>                leave.setLeaves(rs.getInt(&quot;leaves&quot;));<br>                return leave;<br>            }<br><br>        } catch (Exception exception) {<br>            throw new RuntimeException(exception);<br>        }<br><br>        return null;<br>    }<br>}</pre><p>As you can see, first we define <em>url, user, passcode</em> for our DB, then using DriverManager, which is a JDBC driver we attempt to make a connection with the database. Next we create a PreparedStatement object that is nothing but precompiled object that wraps around our SQL query. PreparedStatement object comes with many methods, like executeQuery() which in this case runs the query, and provides us with a ResultSet object. From which we can further extract the values, in this case “empId”, and “leaves”.</p><h4>using Spring JDBC</h4><p>Spring JDBC simplifies database operations by removing boilerplate JDBC code. It handles connection management, resource cleanup, and exception handling automatically.</p><p><strong>Jdbc Template </strong>is the core class in Spring JDBC module, that provides efficient ways to execute SQL queries, and handle results.</p><pre>@Repository<br>public class SpringJDBCRepository {<br><br>    private JdbcTemplate jdbcTemplate;<br><br>    public SpringJDBCRepository(JdbcTemplate jdbcTemplate) {<br>        this.jdbcTemplate = jdbcTemplate;<br>    }<br><br>    private String QUERY_BY_EMPID =<br>            &quot;&quot;&quot;<br>                SELECT * FROM LEAVE WHERE EMPID = ?<br>            &quot;&quot;&quot;;<br><br>    public Leave getLeavesByEmpId(Integer empId) {<br>        try {<br>            return jdbcTemplate.queryForObject(QUERY_BY_EMPID,<br>                    (rs, rowNum) -&gt; {<br>                        Leave leave = new Leave();<br>                        leave.setEmpId(rs.getInt(&quot;empId&quot;));<br>                        leave.setLeaves(rs.getInt(&quot;leaves&quot;));<br>                        return leave;<br>                    }, empId);<br>        } catch(Exception e) {<br>            return null;<br>        }<br>    }<br>}</pre><p>In the above example we are doing exactly what we did previously. Using SpringJDBC there is no need of managing connection using DriverManager, or having precompile SQL queries using PreparedStatement objects. We simply need an object of <strong>JdbcTemplate</strong>, which provides us with methods like update(for insert, update, delete), and query(if expecting multiple rows), queryForObject(if only expecting one single row) to access the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YOi5yqYBNyhY9DcnTuavDw.png" /></figure><h4>JPA</h4><p>Java Persistence API is a Java specification that makes working with databases efficient.</p><h4>Spring Data JPA</h4><p>Spring Data JPA is a wrapper over JPA which further removes more boilerplate code from JPA.</p><h4>Hibernate ORM/Eclipse Link/Open JPA</h4><p>As JPA is a specification, which is a contract about the API, what methods it exposes, etc. It needs some implementation, this is provided by many tools like Hibernate ORM, or Eclipse Link, or Open JPA. Let’s understand with the help of some code.</p><h4>JPA + Hibernate</h4><pre>@Repository<br>public class JPARepository {<br><br>    @PersistenceContext<br>    private EntityManager entityManager;<br><br>    public Leave findById(Integer empId) {<br>        return entityManager.find(Leave.class, empId);<br>    }<br>}</pre><p>See how for the same DB query the repository is so slim. This is the magic of JPA + Hibernate.</p><p>One thing to note here is the use of @PersistenceContext instead of @Autowired that’s because we need a unique entityManager which is created and managed by JPA container instead of Spring’s. This annotation injects a transactional, proxied, thread-safe EntityManager that participates in JPA lifecycle management.</p><h4>Spring JPA + Hibernate</h4><p><em>Step 1 : create an interface for the repository, and extend JpaRepository&lt;T, ID&gt; this will be your repository.</em></p><pre>@Repository<br>public interface SDJPARepository extends JpaRepository&lt;Leave, Integer&gt;{<br><br>}</pre><p><em>Step 2 : utilise all the methods SpringDataJpaRepository provides</em></p><pre>// beginning of service class //<br>// autowiring SDJPARepository : sdjpaRepository<br><br>    public Leave getLeaveByEmpId4(Integer empId) {<br>      return sdjpaRepository.findById(empId).orElse(null);<br>    }<br><br>// end of service class //</pre><p>Do you notice how the code is further abstracted, and there is no need to manage EntityManager either. That’s the beauty of Spring Data JPA. The idea behind writing this article was to show you the same operation through 4 stages of evolution, starting from JDBC -&gt; SpringJDBC -&gt; JPA -&gt; SpringDataJPA.</p><p>That’s it for now, in the next article I’ll talk about Repository &lt;-&gt; Database interaction concepts like Lazy Loading, Eager Loading, Transactions, Persistence Context, etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=856f8d7949f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Series : Working under the hood at HSBC, demystifying Apache Tomcat.]]></title>
            <link>https://abhishekgururani.medium.com/series-working-under-the-hood-at-hsbc-demystifying-apache-tomcat-c7a8768ed612?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7a8768ed612</guid>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Sun, 10 May 2026 18:31:33 GMT</pubDate>
            <atom:updated>2026-05-14T04:07:29.178Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bKzWqmDYu3BrbuRdeCpEEQ.png" /></figure><p>Recently we ran into a bug with a legacy high traffic service that was manually deployed on Apache Tomcat. No fancy CI/CD, nothing. A simple create JAR operation, lift it and shift it to Tomcat instance, that’s it. One of those services that end up serving half-a-million customers like a cheesecake. And then for a small subset of customers they break, and that’s the exact time to get your hands dirty.</p><p>While solving the bug was a Eureka moment, the deeper dive into Tomcat was a great learning experience. Here’s a brief on Apache Tomcat, some tips and tricks to save your time.</p><h3>What is Apache Tomcat?</h3><p>Apache Tomcat is a free, open-source Java servlet container that hosts Java-based web applications. Tomcat has components like Catalina (the servlet container), Coyote (an HTTP connector), and Jasper 2 (the JSP engine). As my fiddling with Tomcat was specific to Catalina, I’ll keep the discussion restricted to it.</p><p>In simple words Tomcat receives HTTP requests and routes them into your Java web application, while also managing things like request/response objects, sessions, threading, and lifecycle.</p><p>The reason why Tomcat is widely used it because it is Lightweight(as it’s not a full enterprise feature set), Mature and stable(been around since 1999), easy to operate(easy to spin, but this makes it hard to debug), Flexible(can run standalone, behind a reverse proxy, in containers, or embedded. <br>TLDR : if your application is “just” a web app(Servlet/Spring MVC, Rest APIs, etc.), Tomcat is often all you need.</p><h3>What are Common Tomcat Deployment Models?</h3><p>Traditional WAR deployment, Embedded Tomcat(Spring Boot Style) : deployment in question, Tomcat behind a reverse proxy.</p><p>The legacy service that we were trying to debug was of the deployment type Embedded Tomcat.</p><h3><strong>Tomcat Key Concepts</strong></h3><p><strong>a. Connectors :</strong> A connector is how Tomcat listens for traffic.</p><p><strong>b. Threading Model :</strong> Tomcat uses thread-per-request model(with a poo). Your application must be thread safe and avoid blocking unnecessarily.</p><p><strong>c. Sessions : </strong>Tomcat can manage HTTP sessions in memory by default. In clustered environment, you’ll need a strategy (sticky sessions, replication, or external session stores).</p><p><strong>d. Classloading : </strong>this is where most “works locally but not server” excuses arise. Tomcat has a layered classloader model(common libs, server libs, webapp libs).</p><h3>Production Basics : How to run Tomcat well?</h3><h4><strong>Use a supported Version</strong></h4><p>Pick a Tomcat version aligned to your Jakarta Servlet/JSP requirements and your Java runtime. As Tomcat is widely deployed, so it’s widely scanned : keep it patched.</p><h4><strong>Configure memory and GC sensibly</strong></h4><p>At minimum, set JVM options appropriate to your workload. Make sure the configuration of Heap sizing, GC logging(very important for troubleshooting) is set correctly.</p><h4>Tune threads and connection handling</h4><p>maxThreads(request processing concurrency), acceptCount(queue length when all threads are busy), connectionTimeout should be driven by laod testing, and real metric, not guesswork.</p><h4>TLS termination</h4><p>Most of the teams terminate TLS at a reverse proxy, or load balancer.</p><h4>Security Hygiene</h4><p>Remove default apps you don’t need(docs/examples/manager/host-manager) or lock them down. Run as a non-root user. Restrict admin endpoints, Keep dependencies updated(your app matters as much as Tomcat)</p><h3><strong>When is Tomcat not a good options?</strong></h3><p>You need full Jakarta EE features out of the box.</p><p>You want a “single binary” micro-service approach (embedded server)</p><p>You’re are standardising on a platform that abstracts the runtime(eg : serverless, managed PaaS)</p><h3><strong>Conclusion</strong></h3><p>Tomcat remains popular because it hits the sweet spot: it’s lightweight enough to be easy to run, but mature enough to be trusted in the production. If your Java application speaks HTTP and lives in the Servlet world, Tomcat is often the most straightforward way to get it running quickly</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0gxOTJfZWtTdAXW65oYHA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7a8768ed612" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in Kotlin for Android, #GoogleIO 2023]]></title>
            <link>https://abhishekgururani.medium.com/whats-new-in-kotlin-for-android-googleio-2023-b922abb827e9?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/b922abb827e9</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[googleio]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Thu, 11 May 2023 09:03:23 GMT</pubDate>
            <atom:updated>2023-05-11T13:21:09.483Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Last year in 2022, Kotlin completed 5 whole years as the officially supported language for Android Development. Here’s a list of 4 new updates to the Android Kotlin Ecosystem that were announced in Google IO ’23.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y2aztu-CfRcocTwi" /><figcaption>Photo by <a href="https://unsplash.com/ko/@abeso?utm_source=medium&amp;utm_medium=referral">Sebastian Bednarek</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Kotlin compiler version 2.0</h3><p>If you’re a Kotlin developer, you might be excited to hear that the language is getting a major upgrade with version 2.0. What’s cool is that the new Kotlin compiler version 2.0 will be the default one for Kotlin 2.0.</p><p>This heavily enhances the performance as compared to previous Kotlin Compiler version 1.8.</p><figure><img alt="A table that depicts the difference in performance between Kotlin 1.8 compiler and Kotlin 2.0 compiler." src="https://cdn-images-1.medium.com/max/1024/1*qt_j-3A1ikaZkcweg0Bhzg.png" /><figcaption>Google IO</figcaption></figure><p>Final updates are to be given by the next year(2024). With Kotlin 2.0 compiler Google is aiming for higher developer productivity, ease of use, and the new 2.0 compiler will also encourage more feature advancements in the Kotlin Language.</p><p>If you want to try out the new Kotlin 2.0 compiler simply update the Kotlin language version to 2.0 in your module’s Gradle Build file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLhDI1Xf4FGQOSApZ8fRTg.png" /><figcaption>Google IO</figcaption></figure><h3>Kotlin DSL for Gradle Builds</h3><p>Google is absolutely bullish on promoting the use of Kotlin Language to completely develop Android Apps. Starting from <em>Android Studio Giraffe</em> the default DSL script for writing Gradle Build Script files will be Kotlin DSL instead of Groovy DSL.</p><p>To use the Kotlin DSL in your Gradle build script, simply name your file build.gradle.kts instead of build.gradle.</p><p>One advantage of using Kotlin DSL is that it makes syntax hinting much accurate, and syntax errors are reported right there even before syncing the build.gradle files.</p><p>Apart from this developers can also use <em>Gradle version catalogs</em> to put all the Apps dependencies at one centralised place, which sounds amazing for the purpose of scalability.</p><p>Check this up : <a href="https://docs.gradle.org/current/dsl/index.html">If you’re looking to migrate Gradle build logic from Groovy to Kotlin.</a></p><p>To see a sample, checkout <a href="https://github.com/android/nowinandroid">NowInAndroid</a> repository on Github.</p><h3><strong>KSP(Kotlin Symbol Processor) : a better alternative to Kapt(Kotlin Annotation Processing Tool)</strong></h3><p>Originally Kapt was used to generate Java Stubs from Kotlin code, allowing annotation processors written in Java to work with Kotlin.</p><p>Through Kapt, annotation processing was a time consuming two step procedure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*QJvkgvCMPsCZclf_iwj76g.png" /><figcaption>Working of Kapt, source : Google IO</figcaption></figure><p>KSP is a Kotlin-first alternative to Kapt, for directly analysing Kotlin code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*CYFIJT6M5xq9Zxrli6I5Jg.png" /><figcaption>Working of KSP, source : Google IO</figcaption></figure><p><strong>KSP has following advantages over Kapt,</strong></p><ol><li>It’s 2X faster, as it doesn’t have to generate Java stubs.</li><li>Better typing : as it understands Kotlin language specific nuances like nullability.</li><li>It’s multiplatform ready as it doesn’t depend on Java source code.</li></ol><p>To get started with migrating from Kapt to KSP <a href="https://developer.android.com/build/migrate-to-ksp">checkout the following official migration documentation</a>.</p><p>Popular libraries like -&gt; Room, Glide, Moshi…to name a few, have already added support for KSP. Whereas, <strong><em>Dagger and Hilt are yet to support KSP.</em></strong></p><h3>Kotlin Multiplatform</h3><p>Kotlin Multiplatform is still <em>beta</em>, and in experimental stages. Google is bringing three popular Jetpack libraries to the Kotlin Multiplatform ecosystem, they are -&gt; <strong><em>Annotations, Collections, and DataStore</em></strong></p><p>I personally believe that multiplatform is the future of Mobile Development. And any step in that direction seems like the right step.</p><p>To see the use of DataStore in Kotlin Multiplatform check <a href="https://github.com/Kotlin/kmm-basic-sample">this kmm-samples repo</a>. And to read more about Kotlin Multiplatform read <a href="https://developer.android.com/kotlin/multiplatform">this official documentation</a>.</p><p>If you found this insightful, do give it an upvote. Thanks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b922abb827e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use popUpTo and popUpToInclusive in Navigation Framework?]]></title>
            <link>https://abhishekgururani.medium.com/how-to-use-popupto-and-popuptoinclusive-in-navigation-framework-d6a5a09370fe?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6a5a09370fe</guid>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Fri, 28 Apr 2023 06:38:38 GMT</pubDate>
            <atom:updated>2023-05-01T04:06:24.251Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hSGTyN6JMVcuLS-H" /><figcaption>Photo by <a href="https://unsplash.com/@mariashanina?utm_source=medium&amp;utm_medium=referral">Maria</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Are you struggling to understand how Navigation Component in Android deals with the Back Stack when transitioning between fragments? If so, you’re not alone. The good news is that the framework provides two powerful attributes, popUpTo and popUpToInclusive, to help simplify the process. In this article, we’ll explore how these attributes work and provide a live project example to help you gain a better understanding. So, let’s dive in and unravel the mysteries of Android Jetpack’s Navigation component framework!</p><h3>Theory :</h3><blockquote><strong>“Back Stack” is your typical Stack that holds an entry of your fragments in the same order you visit them.</strong></blockquote><blockquote><strong>“Action” is transition from one Fragment to Another.</strong></blockquote><p>Suppose you have 5 fragments (<strong>A</strong>, <strong>B</strong>, <strong>C</strong>, <strong>D, E</strong>), and <strong>A</strong> is your home fragment. When you launch your activity which is a host to all 5 of these fragments, it’ll first display fragment <strong>A.</strong></p><p><strong><em>Back Stack : A</em></strong></p><p>From A you transitioned to B, and then to C, and from there to D.</p><p>action 1 : fragmentA_to_fragmentB, 2 : fragmentB_to_fragmentC, 3: fragmentC_to_fragmentD</p><p><strong><em>Back Stack : A, B, C, D,</em></strong></p><p>Let’s create a new action where we move from fragment <strong>D</strong> to fragment <strong>E</strong>, but we’ll now use the attribute, “popUpTo&quot;</p><pre>action 3 : fragmentD_to_fragmentE, popUpTo : fragment B </pre><p><strong><em>Back Stack : A, B, C, D, E(*without popUpTo)</em></strong></p><h4>Behind the scenes with popUpTo,</h4><p>Because the back stack is simply a stack, it follows LIFO(Last in First Out). <strong>With action 3,</strong></p><ol><li>fragment <strong>E</strong> will be added to the back stack,</li><li>popUpTo : fragment <strong>B, what this means is : between fragment E(fragment E will also be excluded) and fragment B(exclusive) all the fragments will be popped.</strong></li></ol><p><strong><em>Back Stack : A, B, E</em></strong></p><p>Let’s recreate the same action and this time, also use the attribute popUpToInclusive and don’t forget to set it to true.</p><pre>action 3 : fragmentD_to_FragmentE, popUpTo : fragmentB, popUpToInclusive = &quot;true&quot;</pre><h4>Behind the scenes with the duo popUpTo &amp; popUpToInclusive,</h4><ol><li>fragment <strong>E</strong> will be added to the back stack,</li><li>popUpTo : fragment <strong>B, what this means is : between fragment E(fragment E will be excluded) and fragment B(inclusive) all the fragments will be popped.</strong></li><li>popUpToInclusive : true, will make sure that B is also popped out.</li></ol><p><strong><em>Back Stack : A, E</em></strong></p><h3>That’s pretty much it with the Theory part, let’s now dive in a project.</h3><p>This navigation graph involves three fragments,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YtFaEn00bccGHFW2xfW76A.png" /><figcaption>Three fragments that transition between each other in a cyclic order</figcaption></figure><p>Requirements with the transition cycle are as follows,</p><ol><li>When transitioning from <strong>giveTextFragment -&gt; gameFragment</strong>, I want to have<strong> [giveTextFragment, gameFragment] </strong>in the Back Stack.</li><li>When transitioning from <strong>gameFragment -&gt; resultFragment</strong>, I want to clear the entire <strong>Back Stack</strong>, and only have <strong>[resultFragment] </strong>in the Back Stack,<strong> </strong>so that the user couldn’t transition back.</li><li>The final transition from <strong>resultFragment -&gt; giveTextFragment</strong>, should also clear the entire back stack. So that only <strong>[giveTextFragment]</strong> is in the Back Stack.</li></ol><p>actions for all three of these transitions,</p><p>action 1 : giveTextFragment -&gt; gameFragment</p><pre>&lt;action<br>    android:id=&quot;@+id/action_giveTextFragment_to_gameFragment&quot;<br>    app:destination=&quot;@id/gameFragment&quot;/&gt;</pre><p><strong><em>Back Stack : [giveTextFragment, gameFragment]</em></strong></p><p><strong><em>pressing back from gameFragment will take us to giveTextFragment.</em></strong></p><p>action 2 : gameFragment -&gt; resultFragment</p><pre>&lt;action<br>      android:id=&quot;@+id/action_gameFragment_to_resultFragment&quot;<br>      app:destination=&quot;@id/resultFragment&quot;<br>      app:popUpTo=&quot;@id/giveTextFragment&quot;<br>      app:popUpToInclusive=&quot;true&quot;/&gt;</pre><p><strong><em>With this action, Back Stack will be popped between resultFragment, and giveTextFragment[inclusive].</em></strong></p><p><strong><em>Back Stack : [resultFragment]</em></strong></p><p><strong><em>pressing back from resultFragment will close the application, because there’s no entry behind resultFragment in the Back Stack.</em></strong></p><p>action 3 : resultFragment -&gt; giveTextFragment</p><pre> &lt;action<br>       android:id=&quot;@+id/action_resultFragment_to_giveTextFragment&quot;<br>       app:destination=&quot;@id/giveTextFragment&quot;<br>       app:popUpTo=&quot;@id/resultFragment&quot;<br>       app:popUpToInclusive=&quot;true&quot;/&gt;</pre><p><strong><em>With this action, Back Stack will be popped between giveTextFragment, and resultFragment[inclusive].</em></strong></p><p><strong><em>Back Stack : [giveTextFragment]</em></strong></p><p><strong><em>pressing back from here will close the application, reason being, there’s not entry behind giveTextFragment in the Back Stack.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Xa3KqCfxKv60JqF0dHhiOw.gif" /><figcaption>GIF of the implementation</figcaption></figure><p>In conclusion, the popUpTo and popUpToInclusive attributes in the Android Navigation Component are powerful tools that can simplify the management of the Back Stack in your app. By understanding how these attributes work and how to use them effectively, you can create a more seamless and intuitive user experience. I hope this article has helped you gain a better understanding of these attributes and how they can be used in your own projects.</p><p>If you have any questions or feedback, feel free to leave a comment below. Keep Androiding!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6a5a09370fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google’s recommended way to implement Splash-Screen in your Android App]]></title>
            <link>https://abhishekgururani.medium.com/googles-recommended-way-to-implement-spash-screen-in-your-android-app-6e56be8196a0?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e56be8196a0</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[splash-screen]]></category>
            <category><![CDATA[androiddev]]></category>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Fri, 30 Sep 2022 19:21:50 GMT</pubDate>
            <atom:updated>2022-10-05T07:19:37.497Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m4LSWY62X2wtlgMfRqQtNg.png" /><figcaption>Thumbnail</figcaption></figure><p>Let’s quickly understand why do we need a splash-screen in our apps, startup of any android application can be divided into three types,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*4L2Y849-_Jbn_G9KebX-Cg.png" /><figcaption>source : developer.android.com</figcaption></figure><p>During the cold and warm start, the activity is yet to be created, and for the time being the screen of the application is “white”, in order to cover-up for that “white” screen a splash-screen is shown.</p><blockquote>The most “naive and non-recommended” way to show a splash-screen is by first creating a dummy splash-screen MainActivity and then delaying it for some time using <a href="https://developer.android.com/reference/android/os/Handler#:~:text=A%20Handler%20allows%20you%20to,is%20bound%20to%20a%20Looper%20.">Handler()</a>, before you move on to your real MainActivity.</blockquote><p>But this way isn’t cool, as it doesn’t solve the problem of “white” screen during the cold/warm start. Infact it may lead to cold start, because the app will now take some extra time to load the layout of this dummy splash-screen MainActivity.</p><p>Instead of this we’ll use the latest Android Splash-Screen API.</p><p>step 1 : include Splash-Screen compat library in your app&#39;s build.gradle</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*zUG5DEtTOWz41HidC_7mgA.png" /><figcaption>Android Splash-Screen API</figcaption></figure><p>step 2 : add a new style inside of values -&gt; themes -&gt; themes.xml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a43c77ff91bb5c449147736ce2e573a/href">https://medium.com/media/3a43c77ff91bb5c449147736ce2e573a/href</a></iframe><blockquote>there are three attributes here, <strong>windowSplashScreenBackground(for setting the bkg), windowSplashScreenAnimatedIcon(for splash-screen icon), postSplashScreenTheme(to set the theme to be shown post splash-screen theme).</strong></blockquote><p>Here, my background is : white , icon is pre-stored : mipmap logo and my post splash-screen theme : Theme.YourMainActivityName</p><p>step 3 : go to your app&#39;s AndroidManifest.xml and add this &quot;Theme.App.Starting&quot; to your application element and activity sub-element,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*iZZkjLpQOHmrWEdShk7ZyQ.png" /><figcaption>adding theme</figcaption></figure><p>step 4 : simply call the function, <em>installSplashScreen(), and voila!!</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2bdeb391f39d8585e83bed12f342692/href">https://medium.com/media/b2bdeb391f39d8585e83bed12f342692/href</a></iframe><p>This now shows splash-screen(THE RIGHT WAY) before the MainActivity, but only for a fraction of milli-second. If you want splash-screen to be shown for longer period(for any custom time), here are the steps,</p><blockquote><em>installSplashScreen()</em> returns the splash-screen object, which you can optionally use to customize animation or keep the splash-screen on screen for a longer duration.</blockquote><blockquote><strong>~ developer.android.com</strong></blockquote><p>step 5 : create a ViewModel,</p><blockquote>A ViewModel is just gonna do some dummy work in a coroutine and attach the splash-screen object to it using setKeepOnScreenCondtion. And till the ViewModel does the dummy work in background, your splash-screen will be up, and MainActivity&#39;s onCreate method will be delayed.</blockquote><p>add the required ViewModel dependency,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*2z3uCGe2zm4UsMoQYcpXNQ.png" /><figcaption>dependency required to use ViewModel class</figcaption></figure><p>before super.oncreate(...),</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94b8b3388c9eb9e9a5bfad0d2f06187f/href">https://medium.com/media/94b8b3388c9eb9e9a5bfad0d2f06187f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5463ff2a90f0500134b29f8423db0e37/href">https://medium.com/media/5463ff2a90f0500134b29f8423db0e37/href</a></iframe><blockquote>setKeepOnScreenCondition, will keep the splash-screen on the screen till the condition is true, once it becomes false(here, after the delay of 800 millisecond) splash-screen will be removed. In order to delay for 800 milli seconds, I&#39;m using coroutines.</blockquote><p>Here is a quick video of an application that implements splash-screen using the above mentioned way,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*HGfl-GlJZbjeN8UVNxoc6w.gif" /><figcaption>teaser of an application I’m working on, yaay!!</figcaption></figure><p>I hope you had a wonderful time, and you’ve learned how to implement splash-screen <strong><em>using the google recommended splash-screen API.</em></strong></p><p>Viva-La-Vida.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e56be8196a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leetcode : Best Time To Buy And Sell Stock IV]]></title>
            <link>https://abhishekgururani.medium.com/leetcode-best-time-to-buy-and-sell-stock-iv-336185e6407b?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/336185e6407b</guid>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Sat, 10 Sep 2022 09:14:46 GMT</pubDate>
            <atom:updated>2022-09-10T09:14:46.207Z</atom:updated>
            <content:encoded><![CDATA[<h3>Leetcode : Best Time To Buy And Sell Stock IV</h3><p>Here’s the problem statement -&gt; <a href="https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/">link</a></p><p>Hmm, let’s get started with our little stock market today. Here are some of the rules to ponder,</p><ol><li>You can make at most ‘k’ transactions.</li><li>You cannot engage in multiple transactions. (i.e. Harshad Mehta, if you have bought a stock, before buying any new stock you have to sell this pre-possessed stock)</li></ol><p>This seemed like an exhaustive problem to me, wherein I just have to exhaustively choose when I buy a stock &amp; when to sell that stock, plus keep in mind that I’ve to maximize the profits.</p><h4>Let’s recursively think of my choices under the conditions,</h4><p><strong><em>At any point I can either buy a stock or I can sell an already bought stock. I cannot buy any new stock before I sell my already possessed stock.</em></strong></p><p>So, what I can do is, I can keep track of whether I’ve bought a stock or not.</p><p>1 &gt; If I’ve bought a stock, then I can either sell it right now or I can sell it later.</p><p>2 &gt; If I haven’t bought a stock, then I can either buy one right now or I can buy it later.</p><p>A recursive solution would be something like this -&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*ulpQMFUUAVA5HI7uruihhg.png" /><figcaption>Driver Function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*2BGprOK92ZktquzcFIWGaQ.png" /><figcaption>recursive function</figcaption></figure><p>My base case is pretty straightforward, either I get done with all the transactions, or I run out of my prices array.</p><p>I’m keeping the count of bought and sold, by using a variable bought, if bought is even(0, 2, 4, 6..) that means I haven’t bought any stock, if it’s odd(1, 3, 5, 7..) that means I’ve already bought a stock.</p><p><strong><em>In case I’ve previously bought a stock, I have two options -&gt;</em></strong></p><p><strong><em>I can either sell it, I can skip selling it right now and might sell it later. Similarly, if I haven’t bought any stocks previously, then I can either buy a stock right now, or skip today and maybe buy it later.</em></strong></p><p><strong>So, I’m exhaustively exploring all the ways, and returning the one which return the max value, in this manner I can easily maximize my profits.</strong></p><p>But, here’s the thing, the complexity of recursive solution will be O(2 ^ N), where N is the size of prices array, because at every call I have two options either to &lt;(buy/sell) plus skip&gt;</p><p>No issues, as I can simply memoize my recursive solution, because there will be many overlapping subproblems/subcases. And I need not to compute those cases again and again.</p><p>A memoized solution would be something like this -&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*pamsja88WOfmUpjggk7KSw.png" /><figcaption>driver function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*HWBr5oq5QC9XFPs-1yz9kQ.png" /><figcaption>memoized recursive solution</figcaption></figure><p>time complexity of this will be : O(N * N) -&gt; as now my overlapping subproblems will only be computer once.</p><p>But here’s something that’s bugging me, in memoized solution the space complexity will be an extra space of O(N) apart from O(N*N) for the dp array. But that can be removed by converting this memoized(or top down) dp solution to tabulated(or bottom up) dp solution.</p><p>A bottom up dp solution will look something like this -&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*noSQ6fZlSnD80A00bNqjRw.png" /><figcaption>bottom up dp</figcaption></figure><p>Here the base case will be pre-defined, as the entire array is already initialized to 0.</p><p>That’s it for today, hasta-la-vista baby!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=336185e6407b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying S.T.L. functions upper_bound() & lower_bound();]]></title>
            <link>https://abhishekgururani.medium.com/demystifying-s-t-l-functions-upper-bound-lower-bound-a34a1068a70c?source=rss-c7d3eb8b576------2</link>
            <guid isPermaLink="false">https://medium.com/p/a34a1068a70c</guid>
            <category><![CDATA[c]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Abhishek Gururani]]></dc:creator>
            <pubDate>Wed, 03 Aug 2022 08:44:00 GMT</pubDate>
            <atom:updated>2022-08-03T08:44:00.024Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-9Oq150wUkBdOYSJR4dfQw.png" /><figcaption>catchy picture to gather views.</figcaption></figure><h4>There are a lot of articles/documentations on the internet that start with the defintion of upper_bound() &amp; lower_bound(), but I don’t want to indulge in all that bare talking. We’ll come to the defintions, but not right now.</h4><h4><em>Lets dive directly into the examples :</em></h4><p><strong>let’s consider a sorted array : 10, 20, 30, 40, 50</strong></p><p>and now let’s find upper_bound() for the following values :</p><p>val : 30, upper_bound : 40, index = 3</p><p>val : 40, upper_bound : 50, index = 4</p><p><strong><em>… can you see a pattern in this? if not let me throw some more values,</em></strong></p><p>val : 45, upper_bound : 50, index = 4</p><p>val : 15, upper_bound : 20, index = 1</p><p>val : 18, upper_bound : 20, index = 1</p><p>val : 10, upper_bound : 20, index = 1</p><h3>well, upper_bound() returns an element from the array that is just greater than val.</h3><p>Let’s talk about an exception, what if our val is : 60, or 65, or anything greater than the last element of the given array?</p><p>val : 60, upper_bound returns : end of the array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*xVGEXgl-PXM12zG-QfPyyw.png" /><figcaption>cpp program</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*SSQ0x4-amldi501-e1lGZw.png" /><figcaption>output</figcaption></figure><p>and what if, we have too many duplicate just greater than elements than our val,</p><p>val : 40, array : 10, 20, 30, 40, 50, 50, 50, 50, 60</p><p>upper_bound : 50, of index : 4(0 based indexing).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*_858aEDdJ8KiAB18ySACdw.png" /><figcaption>val : 40</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*2aZ79xg4rCvEEL7IXUcjZA.png" /><figcaption>upper_bound for val = 40</figcaption></figure><h3><em>So, upper_bound() </em>returns an iterator pointing to the first element in the range [first, last) that is greater than value, or <strong>end of the array</strong> if no such element is found.</h3><h4>Now, let’s talk about lower_bound(), and once again let’s dive directly into the examples,</h4><p><strong>let’s consider a sorted array : 10, 20, 30, 40, 50</strong></p><p>val : 30, lower_bound : 30, index : 2</p><p>val : 35, lower_bound : 40, index : 3</p><p>val : 10, lower_bound : 10, index : 0</p><p>val : 20, lower_bound : 20, index : 1</p><p>val : 25, lower_bound : 30, index : 2</p><p><strong><em>…did you notice some caveat?</em></strong></p><h3><strong><em>well, lower_bound returns an element that is just not less than the given val, in simple words, if val is found it returns val otherwise it returns the element just greater than val.</em></strong></h3><p>Let’s talk about an exception, what if the element we’re looking for is absent plus the element just greater than is also not in the array,</p><p>then lower_bound returns the end of the array.</p><p>val : 60, lower_bound : end of the array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*tMMUIq4gey9FAallTYsCsA.png" /><figcaption>dummy cpp program</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*VwWvcs2db5HUyMmcIKdnlA.png" /><figcaption>output</figcaption></figure><p>What about the case when there are multiple occurrences of val??</p><p>val : 30, array : 10, 20, 30, 30, 30, 30, 40, 50</p><p>lower_bound : 30, at index : 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*kEbWBQkDSZnZsVVsbh0ODg.png" /><figcaption>dummy cpp program</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/347/1*lK_ZnYxG77cMZYc4GXRVLw.png" /><figcaption>output</figcaption></figure><blockquote><em>Viva-La-Vida</em></blockquote><p><strong><em>Here’s some practice questions for you,</em></strong></p><p><strong><em>find lower_bound &amp; upper_bound for the array : 10, 20, 30,40,50,60</em></strong></p><p><strong><em>values : 10, 20, 45, 50, 60, 70</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a34a1068a70c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>