<?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 Satyajit Nath Bhowmik on Medium]]></title>
        <description><![CDATA[Stories by Satyajit Nath Bhowmik on Medium]]></description>
        <link>https://medium.com/@satyajit0618?source=rss-5cd0fd2e6353------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mK1FzbFWXLXm7Wlg.</url>
            <title>Stories by Satyajit Nath Bhowmik on Medium</title>
            <link>https://medium.com/@satyajit0618?source=rss-5cd0fd2e6353------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:49:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@satyajit0618/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[Reactive Programming basics in Java — Part 1]]></title>
            <link>https://medium.com/javarevisited/reactive-programming-basics-in-java-part-1-557989b13c8f?source=rss-5cd0fd2e6353------2</link>
            <guid isPermaLink="false">https://medium.com/p/557989b13c8f</guid>
            <category><![CDATA[spring-webflux]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[reactive]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Satyajit Nath Bhowmik]]></dc:creator>
            <pubDate>Sun, 21 Feb 2021 04:46:28 GMT</pubDate>
            <atom:updated>2021-08-01T15:05:41.393Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reactive Programming basics in Java</h3><p>When I started learning about reactive programming I found a lot of important concepts here and there, so thought of making notes, then later realized why not to publish it as a blog. So here you go,</p><h4><strong>What is reactive programming in java?</strong></h4><p>Reactive programming is a programming paradigm that promotes an asynchronous, non-blocking, event-driven approach to data processing.</p><p>The term, “reactive,” refers to programming models that are built around reacting to change — network components reacting to I/O events, UI controllers reacting to mouse events, and others.</p><p>In that sense, non-blocking is reactive, because, instead of being blocked, we are now in the mode of reacting to notifications as operations complete or data becomes available.</p><h4><strong>What are Mono and Flux?</strong></h4><p>Mono and Flux both are publishers. in java, both are implements from CorePublisher, and CorePublisher is extending from Publisher.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*YCuuxQ8Fm0P5jW8IkyAE5A.png" /><figcaption>Flux implements CorePublisher</figcaption></figure><figure><a href="https://javarevisited.blogspot.com/2021/04/best-reactive-spring-and-webflux-courses-for-java-developers.html"><img alt="" src="https://cdn-images-1.medium.com/max/484/1*39zMWOnk-_ugn27OQVwfJQ.png" /></a><figcaption>Core Publisher extends Publisher</figcaption></figure><p>Flux is a publisher that publishes zero or more values and Mono publishes zero or one value.</p><p><em>Let&#39;s see some examples now</em></p><p>Below is the example of Flux,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*rxpzylMfPoUOewcLyir1-Q.png" /></figure><p>And to make the data flow you have to do subscribe, without subscription data never flows. By default stream is lazy and that means without you consume nothing is executed.</p><p><strong>Output</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*lyIpE-pAjHgLv3LaLB5chA.png" /></figure><p>And <a href="https://medium.com/javarevisited/7-best-webflux-and-reactive-spring-boot-courses-for-java-programmers-33b7c6fa8995">flux </a>can be infinite. We can make use of functions like takeUntil or take to stop.</p><p>Usages of takeUntil</p><pre>Flux.<em>fromIterable</em>(lists).takeUntil(s -&gt; s.equalsIgnoreCase(&quot;End&quot;)).subscribe(System.<em>out</em>::println);</pre><h4><strong>What is publishOn and subscribeOn ?</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*AC66hK3pjR41XD27-XTNUA.png" /></figure><p>publishOn &amp; subscribeOn are convenient methods in Project Reactor which accepts any of the Schedulers to change the task execution context for the operations in a reactive pipeline. While subscribeOn forces the source emission to use specific Schedulers, publishOn changes Schedulers for all the downstream operations.</p><p><strong>publishOn</strong> Example :</p><pre>Flux&lt;Integer&gt; flux = Flux.<em>range</em>(0, 2)<br>        .publishOn(Schedulers.<em>parallel</em>())<br>        .map(i -&gt; {<br>            System.<em>out</em>.println(&quot;First Block Thread : &quot; + Thread.<em>currentThread</em>().getName());<br>            return i;<br>        }).map(i-&gt; {<br>            System.<em>out</em>.println(&quot;Second Block Thread : &quot; + Thread.<em>currentThread</em>().getName());<br>            return i;<br>        });<br><br>flux.subscribe();<br>Thread.<em>sleep</em>(1000);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PbwIXlWRqxEtCfxnVvmMLA.png" /></figure><p>So, above example after <strong>publishOn</strong> all the operation runs on same thread until we see another publishOn, when we see publishOn method is encountered it changes the context and run in the separate thread (based on the schedulers mentioned).</p><p><strong>SubscribeOn</strong> Example :</p><pre>Flux&lt;Integer&gt; flux = Flux.<em>range</em>(0, 2)<br>        .subscribeOn(Schedulers.<em>boundedElastic</em>())<br>        .map(i -&gt; {<br>            System.<em>out</em>.println(&quot;First Block Thread : &quot; + Thread.<em>currentThread</em>().getName());<br>            return i;<br>        }).<br>        subscribeOn(Schedulers.<em>single</em>())<br>      .map(i-&gt; {<br>            System.<em>out</em>.println(&quot;Second Block Thread : &quot; + Thread.<em>currentThread</em>().getName());<br>            return i;<br>        });<br><br>flux.subscribe();<br>Thread.<em>sleep</em>(1000);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2wQxGTQhaAXXEkyoOfK5Pw.png" /></figure><p>Above Example, Even though we have defined multiple subscribeOn methods ( one is <em>boundedElastic and another is single scheduler) </em>only the first subscribeOn method which is close to source takes precedence.</p><p><strong>Note :</strong> <em>We can have multiple publishOn methods which will keep switching the context. However, the subscribeOn method can not do like that. Only the very first subscribeOn method which is close to the source takes precedence.</em></p><h4><strong>What is schedulers and their types?</strong></h4><p>A Scheduler is an abstraction that gives the user control over <a href="https://javarevisited.blogspot.com/2014/07/top-50-java-multithreading-interview-questions-answers.html#axzz6hX6XfwBD">threading</a>. There are mainly four types of it or you can choose to write your own scheduler as well.</p><ol><li>Schedulers.single() — A single reusable thread for all the callers.</li><li>Schedulers.immediate() — To keep the execution in the current thread.</li><li>Schedulers.boundedElastic() — same as elastic, but its thread pool size (10* number of cpu cores), it is good choice for IO operations/ Non blocking call.</li><li>Schedulers.parallel() — is good for CPU-intensive but short-lived tasks. It can execute N such tasks in parallel (by default N == number of CPUs)</li></ol><h4>Schedulers.elastic() — This is a thread pool with unlimited threads which is no longer preferred.</h4><p>Important References :</p><ol><li><a href="https://spring.io/blog/2016/06/07/notes-on-reactive-programming-part-i-the-reactive-landscape">https://spring.io/blog/2016/06/07/notes-on-reactive-programming-part-i-the-reactive-landscape</a></li><li><a href="https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html">https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html</a></li><li><a href="https://spring.io/blog/2019/12/13/flight-of-the-flux-3-hopping-threads-and-schedulers">https://spring.io/blog/2019/12/13/flight-of-the-flux-3-hopping-threads-and-schedulers</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=557989b13c8f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/reactive-programming-basics-in-java-part-1-557989b13c8f">Reactive Programming basics in Java — Part 1</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[Why Kotlin ? — Its advantages]]></title>
            <link>https://satyajit0618.medium.com/why-kotlin-its-advantages-b5aa37533bdd?source=rss-5cd0fd2e6353------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5aa37533bdd</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Satyajit Nath Bhowmik]]></dc:creator>
            <pubDate>Fri, 22 Sep 2017 16:39:12 GMT</pubDate>
            <atom:updated>2017-09-22T16:39:12.372Z</atom:updated>
            <content:encoded><![CDATA[<p>Why kotlin ?</p><p>While there’s been a lot of buzz around Kotlin and google announced that kotlin is first class language for writing android apps — so why should actually use it ?</p><p><strong>Kotlin</strong> : It’s a Statically typed programming language targeting JVM, Android, JavaScript &amp; Native / Sponsored and Developed by JetBrains. Kotlin compiles to bytecode, so it can perform just as well as Java.</p><p>What does Kotlin do that Java doesn’t? — kotlin does most of the things what java does but it does in a better way.</p><p>So, As a developer We love clean, concise code. Less code takes less time to write, less time to read, and is less susceptible to bugs — makes our reviewers life better 🙂. let me give one example before I am going to details about kotlin features.</p><p>In every project we have number of classes which exist solely to store data or state — may be it contains : -</p><ol><li>constructor</li><li>Fields to store data</li><li>Getter and setter functions</li><li>hascode() , equals(), tostring() functions etc.</li></ol><p>So how the above things we implement in Java :</p><p>Lets take an example to store some user details: —</p><pre>public class Details {</pre><pre>private String firstName;</pre><pre>private String lastName;</pre><pre>private int age;</pre><pre>public Details(String firstName, String lastName, int age) {</pre><pre>this.firstName = firstName;</pre><pre>this.lastName = lastName;</pre><pre>this.age = age;</pre><pre>}</pre><pre>public String getName() {</pre><pre>return firstName;</pre><pre>}</pre><pre>public void setName(String name) {</pre><pre>this.firstName = firstName;</pre><pre>}</pre><pre>public String getLastName() {</pre><pre>return lastName;</pre><pre>}</pre><pre>public void setLastName(String lastName) {</pre><pre>this.lastName = lastName;</pre><pre>}</pre><pre>public int getAge() {</pre><pre>return age;</pre><pre>}</pre><pre>public void setAge(int reviewScore) {</pre><pre>this.age = age;</pre><pre>}</pre><pre>@Override</pre><pre>public boolean equals(Object details) {</pre><pre>if (this == details) return true;</pre><pre>if (details == null || getClass() != details.getClass()) return false;</pre><pre>Details detailsObject = (Details) details;</pre><pre>if (age != detailsObject.age)</pre><pre>return false;</pre><pre>if (firstName != null ? !firstName.equals(detailsObject.firstName) :</pre><pre>detailsObject.firstName != null) {</pre><pre>return false;</pre><pre>}</pre><pre>return lastName != null ?</pre><pre>lastName.equals(detailsObject.lastName) :</pre><pre>detailsObject.lastName == null;</pre><pre>}</pre><pre>@Override</pre><pre>public int hashCode() {</pre><pre>int result = firstName != null ? firstName.hashCode() : 0;</pre><pre>result = 31 * result + (lastName != null ?</pre><pre>lastName.hashCode() : 0);</pre><pre>result = 31 * result + age;</pre><pre>return result;</pre><pre>}</pre><pre>@Override</pre><pre>public String toString() {</pre><pre>return &quot;Details{&quot; +</pre><pre>&quot;firtName=&#39;&quot; + firstName + &#39;\&#39;&#39; +</pre><pre>&quot;, lastName=&#39;&quot; + lastName + &#39;\&#39;&#39; +</pre><pre>&quot;, age=&quot; + age +</pre><pre>&#39;}&#39;;</pre><pre>}</pre><pre>public static void main(String []args) {</pre><pre>Details s = new Details(&quot;Cold&quot;, &quot;Play&quot;, 21);</pre><pre>System.out.println(&quot;&quot;+s.toString());</pre><pre>}</pre><pre>}</pre><p>So, its almost 40–50 lines of code to store 3 fields of data in java.</p><p>Fortunately,</p><p>The above code is no longer necessary due to <strong>data class</strong> concept in Kotlin.</p><p>To do the same in kotlin its just one line of code :</p><pre>- data class Details(val firstName: String, val lastName: String, var age: Int)</pre><p>Better huh ? — when we specify the <strong>data</strong> keyword in our class definition Kotlin automatically generates field accessors, hashCode(), equals(), toString() etc.</p><p>We can create instance and we can access the members</p><p>Example :</p><pre> val object: Details = Details (“Cold”, “Play”, 21)</pre><pre><em> println</em>(object. firstName) // Cold<br> <em>println</em>(object. lastName) // Play<br> <em>println</em>(object.age) // 21</pre><p>So, <strong>Kotlin requires atleast 20% less code compare to java</strong>.</p><p>Now, Let me talk about some features which I love about kotlin :</p><p><strong>Features</strong> :</p><p>1) <strong>Null Safety</strong> :</p><p>No more NullPointerExceptions(NPE)</p><p>- Types are non-null by default, and can be made nullable by adding a ?</p><pre><strong>var</strong> a: String = “abc”<br> a = <strong>null</strong> // compile error</pre><pre><strong>var</strong> mightBeNull: String? = null — this variable can be null</pre><p><strong>2) Java Interoperability</strong> :</p><p>Kotlin<strong> </strong>is <strong>100% interoperable </strong>with Java. All Java frameworks are available.Existing java code can be called from kotlin.</p><p><strong>3) Smart Casts :</strong></p><p>The Kotlin compiler tracks your logic and auto-casts types if possible, which means no more instanceof<em> </em>checks followed by explicit casts:</p><pre>if (obj is String) {<br> <em>println</em>(obj.<em>toUpperCase</em>()) // obj is now known to be a String<br> }</pre><p>4) <strong>Adopting Kotlin is very easy :</strong></p><ul><li>Kotlin classes export a Java API that looks identical to that of regular Java code. So, adopting kotlin is much easier.</li></ul><p>5) <strong>Operator Overloading :</strong></p><p>A predefined set of operators can be overloaded to improve readability.As an example, here’s how you can overload the unary minus operator:</p><pre><strong>data</strong> <strong>class</strong> Point(<strong>val</strong> x: Int, <strong>val</strong> y: Int)  <br><strong>operator</strong> <strong>fun</strong> Point.unaryMinus() = Point(-x, -y)  <br><strong>val</strong> point = Point(10, 20) <br>println(-point)  // prints &quot;(-10, -20)&quot;</pre><p>6) <strong>Extenstion function Kotlin :</strong></p><p>Kotlin provides the ability to extend a class with new functionality without having to inherit from the class or use any type of design pattern such as Decorator. This is done via special declarations called <em>extensions.</em></p><p>7) <strong>Lambda functions</strong> :</p><p>Love the lambda function in kotlin 🙂.</p><p>Consider the following example that demonstrates the syntax of a lambda expression:</p><p>{x, y -&gt; x+y}</p><p>This is a simple lambda expression that takes two parameters, x and y, and returns their sum. The parameters of the function are listed before the -&gt; operator and the body of the function starts after the -&gt; operator. This lambda expression can be assigned to a variable and used as follows:</p><p>val sumFunction: (Int, Int) -&gt; Int = {x,y -&gt; x+y}</p><p>val sum = sumFunction(3,4)</p><p>Note that the type of the variable that holds the lambda expression specifies the types of its parameters and its return value.</p><p>Creating a higher order function that can accept the above lambda expression as a parameter is just as easy. For example, to create a function that doubles the result of the lambda expression, you would write:</p><pre>fun doubleTheResult(x:Int, y:Int, f:(Int, Int)-&gt;Int): Int {<br>    return f(x,y) * 2<br>}</pre><p>You can call this function as follows:</p><p>val result = doubleTheResult(3, 4, sumFunction)</p><p><strong>There are so many features which kotlin provides and makes writing code easier, better –</strong></p><p>Below is the link where it describes the comparison between java vs kotlin</p><p><strong>1) </strong><a href="https://kotlinlang.org/docs/reference/comparison-to-java.html"><strong>https://kotlinlang.org/docs/reference/comparison-to-java.html</strong></a></p><p><strong>We can say :</strong></p><p>Kotlin = (Java + extra update new feature for development)</p><p>Nothing in life is perfect so neither is kotlin . So below are the some issues people face while using kotlin :</p><p>1) The data class feature is very useful to auto generate java bean boilerplate but it imposes some limitations — such classes cannot inherit from anything, nor be inherited from. This in turn makes the “sealed class” feature rather less useful, as you can’t have a sealed hierarchy of data classes.</p><p>2) By default, classes are final. You have to mark them as “open” if you want the standard Java behavior.</p><p>3) No static analyzers for Kotlin yet.</p><p>I will end this blog with writing ‘Hello World’ function as this is the first program may be we try whenever we go for new language:</p><pre>fun main(args: Array&lt;String&gt;) {<br>    println(&quot;Hello World!&quot;)<br>}</pre><p>And to know more about kotlin : -</p><p><strong>Kotlin Reference:</strong></p><p><a href="https://kotlinlang.org/docs/reference/"></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5aa37533bdd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>