<?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 Abhijit Jadhav on Medium]]></title>
        <description><![CDATA[Stories by Abhijit Jadhav on Medium]]></description>
        <link>https://medium.com/@abhijithjadhav?source=rss-d84b6adcd7dc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PKUg68964HGvm6qIB1W3vQ.jpeg</url>
            <title>Stories by Abhijit Jadhav on Medium</title>
            <link>https://medium.com/@abhijithjadhav?source=rss-d84b6adcd7dc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:25:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhijithjadhav/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[Lambda Provisoned Concurrency vs SnapStart — When to use what]]></title>
            <link>https://aws.plainenglish.io/lambda-provisoned-concurrency-vs-snapstart-when-to-use-what-9736501e77a5?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/9736501e77a5</guid>
            <category><![CDATA[aws-in-plain-english]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[lambda-function]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Sat, 19 Oct 2024 05:38:49 GMT</pubDate>
            <atom:updated>2024-11-11T14:25:59.152Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lambda Provisoned Concurrency vs SnapStart — When to use what</h3><p>After the launch of SnapStart, talks are going on in the AWS Dev community stating that SnapStart will replace the provisioned concurrency. Well Not really, everything has pros and cons, and we should know when to use what. Let&#39;s see in today&#39;s blog will try to provide a clear road map of when to use what.</p><p>The world without provisioned concurrency and snapstart will go through the cold start for each request adding some extra milliseconds of latency to the execution, even though you will not be billed for the init phase still it might be a problem for latency-sensitive applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*nzdISC0LyqKRQRUEi3gkng.jpeg" /></figure><p>The main objective of both features is to optimize the init (initialization) time, also known as the Cold Start time for the lambda and decrease the latency of the incoming requests.</p><h3>Provisioned Concurrency</h3><h4>How it works</h4><p>When using Provisioned Concurrency AWS pre-allocated the configured number of lambda environments that are kept warn and ready to handle the incoming request. This ensures that your lambda function is already initialized and ready to execute the business logic. i.e. code inside the handler.</p><p>Let&#39;s say you have configured 5 as the provisioned concurrency so 5 pre-initialized lambda functions have already executed the code written out of the handler. Now you can serve 5 concurrent requests with very less ms of execution time, and definitely, the 6th request that comes will go through the init phase adding up some extra ms of execution time and increasing the latency of the request.</p><h4>Cost</h4><p>You will have to pay for the number of provisioned concurrency instances you provision and for the period o f time you provision it.</p><p>Lets say you provisioned 1 instance for 24 hours in ap-south-1 (Asia Mumbai) Region then you will be charged around half a dollar.</p><pre>The Provisioned Concurrency price is $0.0000044985 per GB-s<br>Total period of time for which Provisioned Concurrency is enabled (seconds): 24 hours * 3,600 seconds = 86,400 seconds<br>Total concurrency configured (GB): 1 * 1536MB/1024MB = 1.5 GB<br>Total Provisioned Concurrency amount (GB-s): 1.5 GB * 86,400 seconds =129,600 GB-s  129,600<br>Provisioned Concurrency charges: 129,600 GB-s * $0.0000044985 = $ 0.59</pre><p>It&#39;s just the cost of provisioned concurrency, the lambda costing is separated from this.</p><h4>Common Use Cases</h4><ul><li>Loading config values from the System Manager Parameter Store</li><li>Retrieving username password from Secret Manager</li><li>Caching SSL certificates from Secret Manager for Api Call.</li></ul><h4>Recommended Use Cases</h4><ul><li>Ideal for applications with <strong>predictable traffic patterns where low latency is crucial</strong>, such as APIs. For applications with consistent traffic and where low latency is critical, Provisioned Concurrency ensures that you always have pre-initialized Lambda environments ready to process requests with no delay. e.g Real-time payment processing services where every millisecond matters. Cold starts could lead to transaction delays or timeouts, which can negatively impact business operations.</li><li>For <strong>Lambda Authorizer with Api Gateway</strong> for request authorization. e.g A mobile banking app that requires fast and reliable user authentication to provide access to account information and services.</li><li><strong>Real-Time APIs and Web Applications</strong> : When you’re building APIs or serving web requests, users expect near-instant responses. Any latency due to cold starts can lead to poor user experiences, especially in high-traffic or time-sensitive applications. e.g An e-commerce website API that handles user logins, product searches, and checkout processes. Provisioned Concurrency ensures that the Lambda functions powering these critical paths respond instantly, even during peak traffic periods.</li><li><strong>Interactive Applications (e.g., Gaming or Real-Time Communication):</strong> Interactive apps, such as multiplayer gaming platforms or real-time messaging services, require instant responses to user actions, and cold start delays can disrupt the user experience.<strong>e.g</strong>: A multiplayer online game where user actions need to be processed in near real-time to maintain a smooth gaming experience.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*_mNfTtEwJZiSeIZNi5vrHw.jpeg" /></figure><h3>Lambda SnapStart</h3><h4>How it works</h4><p>SnapStart optimizes the startup time for the Lambda function by taking a snapshot of the initialized execution environment once the initialized phase completes. When the new invocation happens, Lambda restores the pre-initialized snapshot and uses the pre-initialized snapshot for the processing rather than going through starting the code from scratch going through the init phase of lambda again. AWS says that SnapStart can improve the startup performance for a latency-sensitive application by up to 10x with no extra cost.</p><h4>Cost</h4><p>SnapStart is free, you will only be charged for the business logic inside the handler.</p><h4>Recommended Use Cases:</h4><ul><li>It is ideal for <strong>not latency-sensitive applications</strong> enough to justify the continuous cost of provisioned concurrency</li><li><strong>Unpredictable spikes or infrequent bursts of activity:</strong> In such cases, the cost of Provisioned Concurrency could be excessive because you’d be paying to keep environments warm for times when there is no traffic.</li><li><strong>Cost-Sensitive Applications with Latency Requirements:</strong> SnapStart allows you to reduce cold start delays without incurring the higher costs of Provisioned Concurrency, making it ideal for applications that need fast response times but also have strict cost-control measures. e,g A startup using serverless architecture for an API that needs to scale with demand but also must remain cost-efficient during low-traffic periods.</li><li><strong>Backend Services with Sporadic Triggers</strong>: Backend functions that perform tasks like file processing, image manipulation, or data transformation, triggered by sporadic events such as file uploads to S3 or data changes in a database, can benefit from SnapStart e.g A Lambda function that processes images when they are uploaded to an S3 bucket for resizing and optimization.</li><li><strong>Background Jobs and Automation Tasks: </strong>Functions scheduled to run infrequently, such as periodic background jobs or tasks (e.g., data aggregation, batch processing), can use SnapStart to start quickly, even after periods of inactivity.e.g A Lambda function that runs nightly to aggregate usage data across various systems but is not frequently invoked during the day.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*VGC491v8r2_81LUyhDGnCQ.jpeg" /></figure><p>Both have its pros and cons but if you want to take away a thumb rule then I would say if cost is not your concern the for latency sensitive application go with provisioned concurrency and for non-latency sensitive application go with snapstart.</p><p>Don&#39;t forget to give a clap and feel to write your comments of more use-cases you came across.</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a></li><li><a href="https://differ.blog/"><strong>Create a free AI-powered blog on Differ.</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9736501e77a5" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/lambda-provisoned-concurrency-vs-snapstart-when-to-use-what-9736501e77a5">Lambda Provisoned Concurrency vs SnapStart — When to use what</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PySpark Docker Image creation and run Pyspark test cases]]></title>
            <link>https://abhijithjadhav.medium.com/pyspark-docker-image-creation-and-run-pyspark-test-cases-65aba6ff8acc?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/65aba6ff8acc</guid>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pyspark-dataframes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[pyspark]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Wed, 22 May 2024 15:21:26 GMT</pubDate>
            <atom:updated>2024-05-22T15:21:26.459Z</atom:updated>
            <content:encoded><![CDATA[<p>Let&#39;s see how we can create the docker image of PySpark and further use the created docker image to run your PySpark test cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*FDaOWD-1dEV-NAijL8NV_g.jpeg" /></figure><p>Create a Dockerfile.pyspark and add the below code to it</p><pre>FROM openjdk:8-jdk-alpine<br><br>ENV SPARK_VERSION=3.3.1 \<br>    HADOOP_VERSION=3.4.0 \<br>    PYSPARK_PYTHON=python3 \<br>    PYSPARK_DRIVER_PYTHON=python3<br><br>RUN apk add --no-cache \<br>    bash \<br>    curl \<br>    python3 \<br>    py3-pip<br><br>RUN curl -O https://downloads.apache.org/hadoop/common/hadoop-${HADOOP_VERSION}/hadoop-${HADOOP_VERSION}.tar.gz &amp;&amp; \<br>    tar -xzf hadoop-${HADOOP_VERSION}.tar.gz &amp;&amp; \<br>    mv hadoop-${HADOOP_VERSION} /usr/local/hadoop &amp;&amp; \<br>    rm hadoop-${HADOOP_VERSION}.tar.gz<br><br>RUN curl -O https://archive.apache.org/dist/spark/spark-${SPARK_VERSION}/spark-${SPARK_VERSION}-bin-hadoop3.tgz &amp;&amp; \<br>    tar -xzf spark-${SPARK_VERSION}-bin-hadoop3.tgz &amp;&amp; \<br>    mv spark-${SPARK_VERSION}-bin-hadoop3 /usr/local/spark &amp;&amp; \<br>    rm spark-${SPARK_VERSION}-bin-hadoop3.tgz<br><br>ENV HADOOP_HOME=/usr/local/hadoop \<br>    SPARK_HOME=/usr/local/spark \<br>    PATH=$HADOOP_HOME/bin:$SPARK_HOME/bin:$PATH<br><br>RUN pip3 install pyspark<br><br>CMD [&quot;pyspark&quot;]</pre><p>Now build the docker image by using the below command</p><pre>docker build -t pyspark-custom-image -f Dockerfile.pyspark . </pre><p>Okay so now you will have a docker image created. Its time to write some test cases.</p><p>Write a simple code to create data frame in create_dataframe.py file</p><pre>from pyspark.sql import SparkSession<br><br>def create_dataframe(json_data):<br>    spark = SparkSession.builder.appName(&quot;ExampleApp&quot;).getOrCreate()<br>    columns = [&quot;Name&quot;, &quot;Age&quot;]<br>    df = spark.createDataFrame(json_data, columns)<br>    return df<br><br>if __name__ == &quot;__main__&quot;:<br>    json_data = [<br>        {<br>            &quot;Name&quot; : &quot;Alice&quot;,<br>            &quot;Age&quot;: 34<br>        },<br>        {<br>            &quot;Name&quot;: &quot;Bob&quot;,<br>            &quot;Age&quot;: 45<br>        },<br>        {<br>            &quot;Name&quot;: &quot;Catherine&quot;,<br>            &quot;Age&quot;: 29<br>        }<br>    ]<br>    df = create_dataframe(json_data)<br>    df.show()</pre><p>And the test case of the same in the test_create_dataframe.py file</p><pre>import unittest<br>from create_dataframe import create_dataframe<br><br><br>class TestCreateDataFrame(unittest.TestCase):<br><br>    def test_create_dataframe(self):<br>        json_data = [<br>            {<br>                &quot;Name&quot;: &quot;Foo&quot;,<br>                &quot;Age&quot;: 34<br>            },<br>            {<br>                &quot;Name&quot;: &quot;bar&quot;,<br>                &quot;Age&quot;: 45<br>            }<br>        ]<br>        df = create_dataframe(json_data)<br>        columns = [&quot;Name&quot;, &quot;Age&quot;]<br><br>        self.assertEqual(df.count(), len(json_data))<br>        self.assertEqual(df.columns, columns)</pre><p>Now it is time to create a Docker image using the above pyspark-custom-image.</p><p>Create a Dockerfile.application and add the below code</p><pre>FROM pyspark-custom-image<br><br>RUN pip3 install pytest pytest-cov coverage<br><br>COPY create_dataframe.py /app/create_dataframe.py<br>COPY test_create_dataframe.py /app/test_create_dataframe.py<br><br>WORKDIR /app<br><br># CMD [&quot;coverage&quot;, &quot;run&quot;, &quot;-m&quot;, &quot;pytest&quot;, &quot;test_example.py&quot;] &amp;&amp; coverage report<br><br>CMD [&quot;sh&quot;, &quot;-c&quot;, &quot;coverage run -m pytest test_example.py &amp;&amp; coverage html &amp;&amp; coverage report&quot;]</pre><p>Now its time to build this docker image</p><pre>docker build -t my-application -f Dockerfile.application .</pre><p>Lets run some tests now.</p><pre>docker run -t my-application</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*5D0oLXJtG3yMZBzZDQVrWw.png" /></figure><p>Hurray !!! we are now successfully able to create a Pyspark image and able to unit testing using a custom image.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65aba6ff8acc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricky Java Interview Questions Series: Release 6]]></title>
            <link>https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-6-bc11ba9a3344?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc11ba9a3344</guid>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Sat, 06 Aug 2022 08:05:28 GMT</pubDate>
            <atom:updated>2022-08-06T08:05:28.393Z</atom:updated>
            <content:encoded><![CDATA[<p>Read <a href="https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-5-fe394cbdb4af">Release 5</a> first or you can get the whole list <a href="https://medium.com/@abhijithjadhav/list/java-tricky-interview-questions-ac7425b8d045">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*sa4GO9vrUlYfMGbexexnwQ.jpeg" /><figcaption>Tricky Java Interview Questions Series: Release 6</figcaption></figure><h4><strong>51. What is “out” in “System.out.println()”?</strong></h4><p>The System is the final class that comes from java.lang package. out is an instance variable of PrintStream type, which is a public static member of the System class. println() is a method available in the System class. This method prints any argument passed to it and adds a new line to the output.</p><h4><strong>52. What do you understand by the payload in the request?</strong></h4><p>The payload in the HTTP request or response consists of HTTP protocol information such as headers, a URL, body content, and version and status information. In simple words, It contains the data that you send to the server when you make an API request.</p><h4><strong>53. What are the major important files used in configuring JWT-based Spring Security?</strong></h4><p>The four main important files for configuring JWT-based Spring Security are</p><ol><li>AuthenticationException.java</li><li>JWTAuthenticationRestController.java</li><li>JWTTokenRequest.java</li><li>JWTTokenResponse.java</li></ol><h4><strong>54. Suppose we have 100 microservices that are communicating with each other and due to some issue in one of the microservices the application stopped working. In this scenario which Spring cloud utility will you use the trace the request and get the logs?</strong></h4><p>In this scenario will take the help of some Distributed Tracing server like Zipkin. Zipkin will help us to trace the request coming in and out, from or to the microservice by assigning them a unique identifier with the help of sleuth dependency. Zipkin also helps us with a UI to do the analysis of the request.</p><h4>55. Can we test the private and static methods using Mockito?</h4><p>There is no direct support in Mockito to rest the private and static methods. We can use an extension of the Mockito that is PowerMock to test the private and static methods in java.</p><h4>56. What is the use of @Transactional in Spring?</h4><p>@Transactional makes sure that the data is persisted properly in the database and database is consistent after the transaction has been executed.</p><p>Let&#39;s understand this with an example.</p><p>Suppose you are working on an amazon website and it has around 1000 microservices running and you have payment microservice and placeOrder microservice. Now you are in a scenario where we are not using @Transactional. Now what happens if the payment microservice is successfully able to do payment and data is persisted in the payment database. But the placeOrder microservice fails due to some exception in it and now user is has done the payment but his order is not placed.</p><p>So @Transactional solves this issue it makes sure that either both the transaction will happen or none of them will happen. In the above scenario the @Transactional will roll back the payment microservcie transaction and maintain the data consistency in the database.</p><h4>57. How can you handle when one microservice calls another microservice and that microservice takes more time to respond?</h4><p>There are many approaches to resolve this issue but we will stick to standard approaches.</p><p>The first approach is that we can go for circuit breaker pattern and use a circuit breaker framework like resilience4j and return a fallback response to the calling microservice.</p><p>Another approach is that we can configure a Timeout class that will wait for a particular time to get the response and after that, it may or may not return a fallback response.</p><h4>58. Can you give an example of a Builder design pattern related to spring security?</h4><p>In the WebSecurityConfigurerAdapter the protected void configure(HttpSecurity http) is a very good example of the Builder design pattern.</p><h4>59. How do spring boot archives convention over configurations?</h4><p>In spring boot we have AutoConfiguration which scans our classpath for the requirement and configures our application automatically according to the requirement. For example, if we add spring-boot-starter-web dependency then Spring boot understands that we are going to make a web application then it configures a Tomcat server, web dispatcher, etc automatically for us.</p><p>Another convention over configuration is Dependency Injection in spring. In the old approach, we will need to have an XML file where we specify the dependencies that need to be injected but in the new approach we need to use the @Autowired annotation and the dependency can be easily injected without doing many configurations.</p><p>Another one is the application.properties file we can just specify the database name, URL, and password in the file, and spring boot will auto configure the database connection for us.</p><h4>60. What will be the output of the below code?(Type Promotion)</h4><pre>public class Main{<br>       public static void main(String[] args) {<br>            add(2,3);<br>       }<br> <br>       public static void add(int a, long b){<br>            System.out.println( a + b);<br>       }<br>}</pre><p>Output:</p><pre>5</pre><p>Here the Integer 3 will be type promoted to long 3 and the add method will be called and we receive the output as 5.</p><p>Now let&#39;s take look at another situation.</p><pre>public class Main{<br>      public static void main(String[] args) {<br>           add(2,3);<br>      }<br> <br>      public static void add(int a, long b){<br>           System.out.println( a + b);<br>      }</pre><pre>      public static void add(long a, int b){<br>           System.out.println( a + b);<br>      }<br>}</pre><p>Now the above code will throw a compilation error because of the ambiguous situation the compiler is not able to figure out which add method need to be called.</p><p>Let&#39;s take one more example to understand things better.</p><pre>public class Main{<br>    <br>       public static void main(String[] args) {<br>              add(2,3);<br>       }<br> <br>       public static void add(int a, long b){<br>              System.out.println( a + b);<br>       }</pre><pre>       public static void add(long a, int b){<br>              System.out.println( a + b);<br>       }<br> <br>       public static void add(int a, int b){<br>              System.out.println( a + b);<br>       }<br>}</pre><p>Output:</p><pre>5</pre><p>Now there is no need for type promotion as there is a direct method of add(int a, int b) will be called and we will get 5 as output.</p><p>Stay tuned for more such questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc11ba9a3344" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricky Java Interview Questions Series: Release 5]]></title>
            <link>https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-5-fe394cbdb4af?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe394cbdb4af</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java-interview-questions]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Fri, 29 Jul 2022 06:27:46 GMT</pubDate>
            <atom:updated>2022-08-06T08:06:48.104Z</atom:updated>
            <content:encoded><![CDATA[<p>Before reading these interview questions make sure you have gone through the earlier <a href="https://medium.com/@abhijithjadhav/tricky-java-interview-questions-series-release-4-d4bb62951b43">Release 4 </a>or you can get the whole list <a href="https://medium.com/@abhijithjadhav/list/java-tricky-interview-questions-ac7425b8d045">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*UNoJRZw-6H8qL5bnBxlyMw.jpeg" /><figcaption>Tricky Java Interview Questions Series: Release 5</figcaption></figure><h4>41. How can we make sure that thread t1,t2, and t3 will execute in the same sequence in java?</h4><p>We can achieve this by using the join() method of the there. We need to make sure that t3 calls t2.join() and t2 will call t1.join(). Then t1 will get a chance to execute first and t3 will execute at the end.</p><h4>42. Write a stream API to count the number of occurrences in the String.</h4><pre>String string = &quot;java springboot springcode spring java&quot;;</pre><pre>List&lt;String&gt; list = Arrays.asList(string.split(&quot; &quot;));</pre><pre>Map&lt;String, Long&gt; collect = list.stream().collect(Collectors.groupingBy(Function.identity(),Collectors.counting()));</pre><pre>System.out.println(collect.toString());</pre><p>Output:</p><pre>{spring=1, java=2, springcode=1, springboot=1}</pre><h4>43. Between Thread and Runnable which is a better approach to create a thread and Why?</h4><p>When we extend the Thread class then each of our Thread creates a unique object associated with it and When we implement Runnable it shares the same object with multiple threads.</p><p>Also when we extend the thread class we can’t extend any other class even when we require to and when we implement Runnable we can save space for our class to extend any other class in the future.</p><p>So clearly Runnable in a better approach that Thread.</p><h4>44. What do you mean when you say Java is a statically-typed language?</h4><p>It means that all the variables must be declared before we can assign value to it.</p><h4>45. What is the problem with the equals() method in inheritance that violates the symmetric behavior in Java and how to resolve it?</h4><p>The answer is given in this <a href="https://medium.com/@abhijithjadhav/problem-with-equals-method-in-inheritance-that-violates-the-symmetric-behavior-in-java-418b1b58d394">post</a></p><h4>46. Can we use stream API directly on the array instead of Collections?</h4><p>Yes, we can apply stream API on array also. We can use Stream.of() method which will convert them to stream so that multiple stream operations can be applied.</p><pre>Stream.of(1,11,111,1111).filter(i -&gt; i &gt; 11).forEach(System.out::println);</pre><h4>47. What is an atomic operation in java ?</h4><p>An atomic action cannot be suspended in the middle of being executed. It either completes or it doesn’t happen at all. Once a thread starts to run an atomic action, we can be confident that it won&#39;t be suspended until it has completed the action.</p><p>Following are the atomic actions in java.</p><ul><li>Reading and writing reference variable: For example, MyObj1 = MyObj2 would be atomic. A thread can’t be suspended in the middle of executing this statement.</li><li>Reading and writing primitive variables except those of type <em>long</em> and <em>double</em>.</li></ul><pre>myInt = 10 // thread cannot be suspended<br>myDouble = 1.234 // thread can be suspended</pre><ul><li>Reading and writing all variables declared volatile.</li></ul><h4>48. How can we test a method that returns a void?</h4><p>We can use verify() method which lets us verify whether the mock void method is being called or not.</p><h4>49. What annotation is used to specify the composite primary key?</h4><p><em>@EmbeddedId</em> is used to specify the composite primary key</p><h4>50. How can we access the environment variable in the java code.</h4><p>We can use System.getenv() to access the environment variable.</p><blockquote><a href="https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-6-bc11ba9a3344">Read Release 6 here</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe394cbdb4af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Problem with equals() method in inheritance that violates the symmetric behavior in Java]]></title>
            <link>https://abhijithjadhav.medium.com/problem-with-equals-method-in-inheritance-that-violates-the-symmetric-behavior-in-java-418b1b58d394?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/418b1b58d394</guid>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Wed, 27 Jul 2022 15:37:13 GMT</pubDate>
            <atom:updated>2022-07-27T15:37:13.589Z</atom:updated>
            <content:encoded><![CDATA[<p>When we Inherit the class and override the equals method then the instanceof will violate the symmetric behavior that the equals method should follow according to the contract.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*tDkmqw_iSbYBQ_a7tW6yww.jpeg" /><figcaption>Problem with equals() method in inheritance that violates the symmetric behavior in Java</figcaption></figure><p>Let&#39;s see first what the contract of the equals method says. The equals method should be</p><ul><li><strong>Reflexive</strong>: for any non-null reference value x.equals(x) should be True</li><li><strong>Symmetric</strong> : for any non-null value x.equals(y) and y.equals(x) both should be True.</li><li><strong>Transitive</strong>: for any non-null value x.equals(y), y.equals(z), z.equals(x) all should be True</li><li><strong>Consistent</strong>: for multiple invocations of x.equals(y) should always return the same value.</li></ul><p>Now let&#39;s see how instanceof violates the symmetric behavior of the equals method during inheritance.</p><pre>class Dog{<br>      private String name;<br>      <br>      public Dog(String name) {<br>           super();<br>           this.name = name;<br>      }<br>   <br>      @Override<br>      public boolean equals(Object obj) {<br>           if (this == obj)<br>                 return true;<br>           if (obj instanceof Dog)<br>                 return true;<br>           return false;<br>      }<br>}</pre><pre>class Labrador extends Dog{<br>      public Labrador(String name) {<br>            super(name);<br>      }</pre><pre>      public boolean equals(Object obj) {<br>           if (this == obj)<br>                 return true;<br>           if (obj instanceof Labrador)<br>                 return true;<br>           return false;<br>      }<br>}</pre><pre>public class Main {<br>      public static void main(String[] args) {<br>           Labrador rover1 = new Labrador(&quot;Rover&quot;);<br>           Dog rover2 = new Dog(&quot;Rover&quot;);<br>           System.out.println(rover1.equals(rover2));<br>           System.out.println(rover2.equals(rover1));<br>      }<br>}</pre><p>Output:</p><pre>false<br>true</pre><p>Ideally, the output of both statements should be true.</p><p>To avoid this issue we need to make the equals() and hashcode() method final.</p><pre>class Dog{<br>      private String name;<br>      <br>      public Dog(String name) {<br>           super();<br>           this.name = name;<br>      }<br>   <br>      @Override<br>      public <strong>final</strong> boolean equals(Object obj) {<br>           if (this == obj)<br>                 return true;<br>           if (obj instanceof Dog)<br>                 return true;<br>           return false;<br>      }<br>}</pre><pre>class Labrador extends Dog{<br>      public Labrador(String name) {<br>            super(name);<br>      }<br>}</pre><pre>public class Main {<br>      public static void main(String[] args) {<br>           Labrador rover1 = new Labrador(&quot;Rover&quot;);<br>           Dog rover2 = new Dog(&quot;Rover&quot;);<br>           System.out.println(rover1.equals(rover2));<br>           System.out.println(rover2.equals(rover1));<br>      }<br>}</pre><p>Output:</p><pre>true<br>true</pre><p>This is how we can resolve the violation of symmetric behavior in the equals method during inheritance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=418b1b58d394" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricky Java Interview Questions Series: Release 4]]></title>
            <link>https://medium.com/javarevisited/tricky-java-interview-questions-series-release-4-d4bb62951b43?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4bb62951b43</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[questions]]></category>
            <category><![CDATA[java-interview-questions]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 16:59:51 GMT</pubDate>
            <atom:updated>2022-08-18T15:30:37.140Z</atom:updated>
            <content:encoded><![CDATA[<p>Another day another release of tricky java interview questions. You can go through Release 3 <a href="https://medium.com/@abhijithjadhav/tricky-java-interview-questions-series-release-3-5adf4b2d1abe">here</a>. and the whole list <a href="https://medium.com/@abhijithjadhav/list/java-tricky-interview-questions-ac7425b8d045">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*YitvtO_7SZXcMzxQ0t5LPw.jpeg" /></figure><h4>31. What is the best candidate for the HashMap Key? Are Strings a good candidate for HashMap Key?</h4><p>Immutable objects are very good candidates for the HashMap Key, as they cannot be changed once created. As Strings are immutable in nature they are a very good candidate for the<a href="https://javarevisited.blogspot.com/2017/08/how-to-remove-key-value-pairs-from-hashmap-java8-example.html"> HashMap Key</a>.</p><h4>32. Can a variable be local and static at the same time?</h4><p>No the variable cannot be local and static at the same time, doing so will give you a compilation error. Only final is permitted locally.</p><h4>33. Is it possible to define a method in java class and provide its implementation in another programming language like C++?</h4><p>Yes, you can do this by using the native method stack. In the case of native method stack development, we will define<a href="https://javarevisited.blogspot.com/2011/12/main-public-static-java-void-method-why.html"> public static methods</a> in our Java class without its implementation and then provide the implementation in another language like<a href="https://medium.com/javarevisited/10-advanced-c-books-and-courses-for-experienced-programmers-a90c3942471a"> C++</a></p><h4>34. Can we declare an abstract class final ?</h4><p>No, we cannot declare the abstract class final. Logically the main aim of the abstract class is to provide the feasibility of having the abstract and non-abstract methods and if we <a href="https://javarevisited.blogspot.com/2022/08/can-we-declare-abstract-class-or-method.html">declare the abstract class fina</a>l then we will not be able to extend the abstract class and the whole scenario won&#39;t make any sense 😊.</p><pre>// The below code will give compilaiton errors<br>public abstract final class Car{<br>}</pre><h4>35. Can we use a default constructor of a class even if an explicit constructor is defined?</h4><p>If we have a parameterized constructor then we can not call the internal default constructor automatically, It would give a compilation error.</p><h4>36. When a thread is executing synchronized methods then is it possible to execute other synchronized method simultanously by other thread?</h4><p>No it is not possible to execute synchronized method by other threads when a thread is inside a <a href="https://www.java67.com/2013/01/difference-between-synchronized-block-vs-method-java-example.html">synchronized method.</a></p><h4>37. If two threads have same priority which thread will be executed first?</h4><p>It will totally depends on thread scheduler to which thread to execute. The scheduler can do pick any thread from the pool and run it till it completes or it can give equal oppurtunity for all the threads by time slicing.</p><h4>38. Can sleep() method causes another thread to sleep?</h4><p>No <a href="https://javarevisited.blogspot.com/2011/12/difference-between-wait-sleep-yield.html">sleep() method </a>causes only the current thread to sleep not any other thread.</p><h4>39. In context to thread, when will IllegalMonitorStateException will be thrown?</h4><p>when wait(), notify(), notifyall() are called in non-synchronized context we will recieve a IllegalMonitorStateException.</p><h4>40. Can we serialize static variables in java ?</h4><p>We can’t serialize static variable in java. The reason being static variable are class that belong to a class not to object but serialization saves only object state not the class state.</p><blockquote>We have <a href="https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-5-fe394cbdb4af">Release 5 here</a> 😊</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4bb62951b43" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/tricky-java-interview-questions-series-release-4-d4bb62951b43">Tricky Java Interview Questions Series: Release 4</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricky Java Interview Questions Series: Release 3]]></title>
            <link>https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-3-5adf4b2d1abe?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/5adf4b2d1abe</guid>
            <category><![CDATA[java-interview-questions]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-question]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Thu, 21 Jul 2022 15:12:20 GMT</pubDate>
            <atom:updated>2022-07-28T11:57:02.075Z</atom:updated>
            <content:encoded><![CDATA[<p>We are back with another release of tricky interview questions for a quick interview revision and preparation. You can go through Release 2 <a href="https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-2-88b05a665536">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*teSFOKRcBWJ9tAGA" /><figcaption>Photo by <a href="https://unsplash.com/@vantaymedia?utm_source=medium&amp;utm_medium=referral">Van Tay Media</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hurray !!! in the further releases, we will also be covering answers to the questions.</p><h4><strong>Readers be like :</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*QS0GnUx8QknyB2bwPdAY7g.jpeg" /><figcaption>Credits: Unknown</figcaption></figure><h4><strong>21. Why String is immutable in nature?</strong></h4><p>The main reason for a String to be immutable is Security because strings are shared in different areas like flat file systems, networking, database connections, etc. Immutability allows the string to be safe and secure so that no one can change the references of the string once it gets created.</p><p>Another reason is to avoid changing the shared references from anywhere.</p><h4>22. Can we use the assignment operator in the ‘if’ block.</h4><p>Yes, variables can be assigned in the ‘if’ block but cannot be declared in the if block.</p><pre>int i;<br>if((i = someMethod()) != 0) return true;</pre><h4>23. What is the difference between synchronized block and synchronized method?</h4><p>There is no visible difference between both, both achieve the same objective. It&#39;s just what context they are used is making a difference. The synchronized keyword used at the method level makes the whole method thread-safe. Whereas synchronized block only makes the code written inside it thread-safe.</p><h4>24. Can we have a static method and non-static method with the same name in single class?</h4><p>No, we can not have a static method and non-static method with the same name in a single class, the compiler will give a compile time error. The below scenario is not allowed.</p><pre>class Main{<br>     public static void main(){<br>           //some code<br>     }<br>     public void main(){<br>          //some code<br>     }<br>}</pre><h4>25. How can we make the main thread a Daemon thread?</h4><p>Ideally, when we have to make thread daemon thread we use the setDaemon() method from the thread class but we cannot make the Main thread as the Daemon thread.</p><h4>26. Can you use hashcode() default implementation in the Interface?</h4><p>You cannot give your default implementation of the hashcode() in the interface for all the implementing classes to use.</p><p>We are not allowed to override java.lang.Object classes method as a default method in interface else will get a compile-time error.</p><h4>27. How does the default method in the interfaces cope up with the diamond problem.</h4><p>The diamond problem in java is when two interfaces contain the same default methods and implementing class gets confused about which method to call this is called a diamond problem in java. In such a situation, the code will not compile.</p><p>The solution to this is to override the ambiguous method and call Interface.super.methodName().</p><h4>28. Are static methods in the interface available to the implementing classes by default?</h4><p>Static methods are not available for the implementing classes by default. You can call these static methods using the interface name explicitly from the implementing class as implementing class won&#39;t have access to these methods directly.</p><h4>29. Why does the PermGen replaced by MetaStore in Java Memory Management?</h4><p>The issue with PerGen was it was very hard to predict how much size PermGen will need and MetaStore helps in improving the garbage collection performance.</p><h4>30. Suppose if we have multiple classes in the same source file then what will happen during the compile time?</h4><p>Suppose we have a .java file with class A, class B, and class C in the same while then during the compilation there will be a separate .class file created for each class even though they are in a single java file.</p><p>You can go through more just tricky interview questions in <a href="https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-4-d4bb62951b43">Release 4 here</a> and don’t forget to follow me for more such questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5adf4b2d1abe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricky Java Interview Questions Series: Release 2]]></title>
            <link>https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-2-88b05a665536?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/88b05a665536</guid>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Wed, 13 Jul 2022 14:29:59 GMT</pubDate>
            <atom:updated>2022-07-28T11:55:34.854Z</atom:updated>
            <content:encoded><![CDATA[<p>We are back with the second release of tricky interview questions for a quick interview revision and preparation. You can go through Release 1 <a href="https://medium.com/@abhijithjadhav/tricky-java-interview-questions-series-release-1-edad8c84ca30">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZqKAy5LIA1u1pq1F" /><figcaption>Photo by <a href="https://unsplash.com/@mkvandergriff?utm_source=medium&amp;utm_medium=referral">Maranda Vandergriff</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>11. What is the difference between these two?</p><pre>List&lt;Integer&gt; list = new ArrayList&lt;&gt;(10);<br>List&lt;Integer&gt; list = new ArrayList&lt;&gt;();</pre><p>12. What are the different ways to break a Singleton pattern?</p><p>13. Will the below code compile if you create an object of Child in the main class.</p><pre>class Parent {<br>    private void doSomething() throws FileNotFoundException {}<br>}<br>class Child extends Parent {<br>    private void doSomething() throws IOException {}<br>}</pre><p>14. What is a Co variant return type?</p><p>15. How the instanceof method violates the symmetric contract of the equals method during inheritance in the working of the hashtable?</p><p>16. Write a stream API code to find the duplicate elements without using the Set?</p><pre>list.stream().filter(i -&gt; Collections.frequency(list,i) &gt; 1).collect(Collectors.toSet)</pre><p>17. How is spring security intercepting your request and what are the different interceptors available in java.</p><p>18. What is Client Side Discovery and what are its pros and cons in the application?</p><p>19. What status code you will return if the requested resource is not found during a GET request to your REST endpoint?</p><p>20. What is the volatile keyword in java?</p><p>You can go through more just tricky interview questions in <a href="https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-3-5adf4b2d1abe">Release 3 here</a> and don&#39;t forget to follow me for more such questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88b05a665536" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricky Java Interview Questions Series: Release 1]]></title>
            <link>https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-1-edad8c84ca30?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/edad8c84ca30</guid>
            <category><![CDATA[java-interview-questions]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Tue, 12 Jul 2022 15:54:44 GMT</pubDate>
            <atom:updated>2022-07-28T11:53:22.433Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello readers I am back with a java interview questions series. We will be covering the tricky Java Interview Questions asked in the interview. These questions are truly based on the interview experience of me and some of my colleagues. We will not be covering the simple questions here that are easily available on different websites. We will only be covering questions that will need a deep understanding of the concepts.</p><p>Our main aim for this series is to get you a quick revision or practice before the interview. So you can read the question and try to answer them. If you are stuck don&#39;t worry you can always google the answer. Stay tuned for new questions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GzL0UgfLFnkwfcIg" /><figcaption>Photo by <a href="https://unsplash.com/@amyhirschi?utm_source=medium&amp;utm_medium=referral">Amy Hirschi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Also, we will only cover answers wherever possible but not for all scenarios.</p><ol><li><strong>Identify the output of the below code:</strong></li></ol><pre>class ABC {<br>      static {<br>          System.out.println(&quot;static block of ABC&quot;);<br>      }</pre><pre>      public static void display() {<br>          System.out.println(&quot;static method class ABC&quot;);<br>      }</pre><pre>      public ABC() {<br>          System.out.println(&quot;No parameterized constructor ABC&quot;);<br>      }<br>      <br>      public ABC(int a) {<br>          System.out.println(&quot;Parameterized constructor ABC &quot; + a);<br>      }<br>}</pre><pre>class CDE extends ABC {<br>      static {<br>          System.out.println(&quot;static block CDE&quot;);<br>      }<br>     <br>      public static void display() {<br>          System.out.println(&quot;static method class CDE&quot;);<br>      }<br>  <br>      public CDE() {<br>         System.out.println(&quot;No parameterized constructor CDE&quot;);<br>      }</pre><pre>      public CDE(int a) {<br>         System.out.println(&quot;Parameterized constructor CDE&quot;);<br>      }<br>}</pre><pre>public class Interview {<br>      public static void main(String[] args) {<br>           ABC abc = new CDE(1);<br>           //  ABC abc = new CDE();<br>           //  ABC abc = new ABC(1);<br>           //  CDE cde = new CDE(1);<br>      }<br>}</pre><p>OUTPUT:</p><pre>static block of ABC</pre><pre>static block CDE</pre><pre>No parameterized constructor ABC</pre><pre>Parameterized constructor CDE</pre><p>2. What is the difference between Runnable and Callable interfaces?</p><p>3. What are the scenarios where you will use the Abstract Class and Interface ?</p><p>4. In the Spring security implementation what will happen if you receive a fake or invalid token?</p><p>5. Can we override the static method and if so then how?</p><p>6. Can we run a program without the main method?</p><p>7. If we have an interface of Hardisk and two classes Samsung and Lenevo implements the interface then how will we inject the dependency into the other Laptop class?</p><p>8. What is the real-life use case of the Builder Design pattern?</p><p>9. Suppose you want to connect to MySQL and MongoDB at the same time and in the same application then how will you achieve this? Which design pattern you will go for and Why?</p><p>10. What will be your approach for migrating a monolithic architecture to microservice architecture?</p><blockquote>You can read Release 2 <a href="https://abhijithjadhav.medium.com/tricky-java-interview-questions-series-release-2-88b05a665536">here</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edad8c84ca30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deepfake Detection using Deep Learning Code Walkthrough (Part 1)]]></title>
            <link>https://abhijithjadhav.medium.com/deepfake-detection-using-deep-learning-code-walkthrough-part-1-b5e43d45e59c?source=rss-d84b6adcd7dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5e43d45e59c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[deepfakes]]></category>
            <category><![CDATA[machine-intelligence]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Abhijit Jadhav]]></dc:creator>
            <pubDate>Thu, 12 May 2022 11:04:23 GMT</pubDate>
            <atom:updated>2022-05-12T11:04:23.367Z</atom:updated>
            <content:encoded><![CDATA[<p>Deepfakes are indistinguishable human synthesized images created using deep learning algorithms. In simple terms, we can say that deepfakes are morphed videos that are mostly created for a bad cause.</p><p>The deepfakes are created using different deeplearning-based tools like Faceswap, Faceit, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wn9xFr-heq7jokh2jUd_mQ.png" /><figcaption>FaceSwap deepfake</figcaption></figure><p>The main purpose of creating deepfakes</p><ul><li>may be to spread fake news are create hoaxes around the audience</li><li>it also may be to pretend like someone else and do a financial fraud.</li><li>It may be used to slander the reputation of the famous personality like celebrity or politician by creating there unusual videos and publishing it over the internet.</li></ul><p>Today we will be looking at the code I have developed to detect the deepfakes using CNN for feature extraction and LSTM temporal analysis. You can find the <a href="https://github.com/abhijitjadhav1998/Deepfake_detection_using_deep_learning/tree/master/Model%20Creation">source code here</a>.</p><p>We will be dividing the code into three parts.</p><ul><li>In the first part, we take look at the Pre-processing stage of the model. In this stage, we will load the dataset, Split the video into frames, crop the face from each frame, and save the face-cropped video.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2N3_ZLqKSMTqZQlFyHkpiw.png" /><figcaption>Preprocessing stage</figcaption></figure><ul><li>After doing the preprocessing its time now to train the deep learning model. In this stage we will the preprocessed video and labels from a CSV file, Create a PyTorch model using transfer learning with RestNext50 and LSTM, Split the data into train and test data, Train the model, Test the model, save the model in the .pt file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*fFn1jzMD-PpW6Wv3OOpvtQ.png" /><figcaption>Training Workflow</figcaption></figure><ul><li>Now our model is trained and ready now its time to do prediction in the prediction stage. We will load the saved PyTorch model, and predict the output based on trained weights.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*QAZGIZLPlU6DzHwv5O-GrQ.png" /><figcaption>Prediction Workflow</figcaption></figure><p>At the end of the Code walkthrough series, you will be able to train your own deepfake model and predict the result.</p><p>We have also developed the Django application to demonstrate the real-time usage of the model for prediction.</p><p>Hope you are excited about the code walkthrough series, as I am too. Stay tuned for further posts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5e43d45e59c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>