<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bharath S R</title>
    <description>The latest articles on DEV Community by Bharath S R (@bharath_vasishtha).</description>
    <link>https://dev.to/bharath_vasishtha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1566934%2Fe5461a2f-211c-4b80-b23a-e1848c5f7d8b.png</url>
      <title>DEV Community: Bharath S R</title>
      <link>https://dev.to/bharath_vasishtha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bharath_vasishtha"/>
    <language>en</language>
    <item>
      <title>🔋 10 Hidden Android Battery-Saving Tricks You Probably Don’t Know About</title>
      <dc:creator>Bharath S R</dc:creator>
      <pubDate>Fri, 14 Nov 2025 11:03:35 +0000</pubDate>
      <link>https://dev.to/bharath_vasishtha/10-hidden-android-battery-saving-tricks-you-probably-dont-know-about-16oe</link>
      <guid>https://dev.to/bharath_vasishtha/10-hidden-android-battery-saving-tricks-you-probably-dont-know-about-16oe</guid>
      <description>&lt;p&gt;Boost battery life without uninstalling apps or turning your phone into a brick.&lt;/p&gt;

&lt;p&gt;Most Android phones come with powerful hardware and bright displays, but battery life often suffers because of background activity, hidden settings, and unnecessary system processes. The good news? Android has a lot of lesser-known battery-saving features that can dramatically extend your usage—if you know where to look.&lt;/p&gt;

&lt;p&gt;In this post, we’ll cover 10 hidden tricks that can add hours to your battery life.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;1. Restrict Background Battery Usage&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Many apps continue running even when you’re not using them, quietly eating up battery.&lt;/p&gt;

&lt;p&gt;How to enable:&lt;/p&gt;

&lt;p&gt;Go to Settings → Battery → Battery usage&lt;/p&gt;

&lt;p&gt;Tap a high-drain app&lt;/p&gt;

&lt;p&gt;Select Restricted or Optimize&lt;/p&gt;

&lt;p&gt;This prevents apps from waking up unnecessarily.&lt;/p&gt;

&lt;p&gt;Best for: Social apps, shopping apps, food delivery apps, and games.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;2. Turn On Adaptive Battery&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Android’s built-in AI learns your app habits. Apps you rarely open get limited access to your battery.&lt;/p&gt;

&lt;p&gt;How to enable:&lt;/p&gt;

&lt;p&gt;Settings → Battery → Adaptive Battery&lt;/p&gt;

&lt;p&gt;This alone can increase battery life by up to 10–20% over time.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;3. Disable Wi-Fi &amp;amp; Bluetooth Scanning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even when you toggle Wi-Fi or Bluetooth OFF, your phone may still scan for networks and devices in the background.&lt;/p&gt;

&lt;p&gt;How to disable:&lt;/p&gt;

&lt;p&gt;Settings → Location → Location services&lt;/p&gt;

&lt;p&gt;Turn off Wi-Fi scanning&lt;/p&gt;

&lt;p&gt;Turn off Bluetooth scanning&lt;/p&gt;

&lt;p&gt;It stops unnecessary background activity—especially useful outdoors.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;4. Turn Off “Mobile Data Always Active”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your phone keeps mobile data active even when you’re connected to Wi-Fi, draining battery through constant signal switching.&lt;/p&gt;

&lt;p&gt;How to disable:&lt;/p&gt;

&lt;p&gt;Open Developer Options&lt;/p&gt;

&lt;p&gt;Search for Mobile data always active&lt;/p&gt;

&lt;p&gt;Turn it OFF&lt;/p&gt;

&lt;p&gt;Note: You must enable Developer Options first (tap Build Number 7 times).&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;5. Limit Background Processes (Advanced Trick)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This reduces how many apps Android keeps alive in memory.&lt;/p&gt;

&lt;p&gt;How to enable:&lt;/p&gt;

&lt;p&gt;Developer Options → Background process limit&lt;/p&gt;

&lt;p&gt;Choose “At most 2 processes” for maximum savings&lt;/p&gt;

&lt;p&gt;Or leave at “Standard” for normal performance&lt;/p&gt;

&lt;p&gt;This trick stops rogue apps from silently starting again.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;6. Disable Auto-Start for Certain Apps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Brands like Xiaomi, Vivo, Oppo, and OnePlus allow apps to automatically launch themselves at startup.&lt;/p&gt;

&lt;p&gt;How to disable:&lt;/p&gt;

&lt;p&gt;Settings → Apps → Auto-start / Auto-launch&lt;/p&gt;

&lt;p&gt;Turn OFF apps you don’t need running 24/7&lt;/p&gt;

&lt;p&gt;Great for cutting down on background clutter.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;7. Reduce Screen Refresh Rate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A 120Hz or 144Hz display looks smooth—but drains a lot of battery.&lt;/p&gt;

&lt;p&gt;How to change:&lt;/p&gt;

&lt;p&gt;Settings → Display → Motion smoothness / Refresh rate&lt;/p&gt;

&lt;p&gt;Switch to 60Hz when battery-saving is a priority&lt;/p&gt;

&lt;p&gt;This can add HOURS of extra screen time on AMOLED displays.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;8. Use Ultra Battery Saving Mode in Emergencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most Android phones have a hidden “ultra power-saver” mode that disables background syncing and unnecessary features.&lt;/p&gt;

&lt;p&gt;How to enable:&lt;/p&gt;

&lt;p&gt;Settings → Battery → Power Saving Mode&lt;/p&gt;

&lt;p&gt;Look for “Ultra,” “Extreme,” or “Super” power saving&lt;/p&gt;

&lt;p&gt;This mode can stretch 10% battery to last several hours.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;9. Reduce Vibration &amp;amp; Haptic Feedback&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vibration motor = power-hungry hardware.&lt;/p&gt;

&lt;p&gt;How to reduce:&lt;/p&gt;

&lt;p&gt;Settings → Sound &amp;amp; vibration&lt;/p&gt;

&lt;p&gt;Reduce intensity or turn off:&lt;/p&gt;

&lt;p&gt;Keyboard vibration&lt;/p&gt;

&lt;p&gt;Touch vibration&lt;/p&gt;

&lt;p&gt;Notification vibration&lt;/p&gt;

&lt;p&gt;You’ll still get the essentials while saving battery.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;10. Disable “Hey Google” Voice Detection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Your microphone is always listening for the hotword, constantly draining resources.&lt;/p&gt;

&lt;p&gt;How to disable:&lt;/p&gt;

&lt;p&gt;Settings → Google → Search → Voice → Voice Match&lt;/p&gt;

&lt;p&gt;Turn off “Hey Google”&lt;/p&gt;

&lt;p&gt;You can still activate Google Assistant manually.&lt;/p&gt;




&lt;p&gt;🔋 Final Thoughts&lt;/p&gt;

&lt;p&gt;These 10 hidden Android battery-saving tricks aren’t the typical “turn down your brightness” advice—these are under-the-hood optimizations that actually work.&lt;/p&gt;

&lt;p&gt;By tweaking these settings, you can:&lt;br&gt;
✔ Add extra hours of screen time&lt;br&gt;
✔ Reduce background drain&lt;br&gt;
✔ Improve overall performance&lt;/p&gt;

</description>
      <category>android</category>
      <category>battery</category>
      <category>mobile</category>
    </item>
    <item>
      <title>There’s an AI for That: A Practical Guide to Smarter Work</title>
      <dc:creator>Bharath S R</dc:creator>
      <pubDate>Tue, 23 Sep 2025 04:43:24 +0000</pubDate>
      <link>https://dev.to/bharath_vasishtha/theres-an-ai-for-that-a-practical-guide-to-smarter-work-18gb</link>
      <guid>https://dev.to/bharath_vasishtha/theres-an-ai-for-that-a-practical-guide-to-smarter-work-18gb</guid>
      <description>&lt;p&gt;Artificial Intelligence (AI) is no longer confined to research labs or big tech companies. Today, it’s shaping how we write, design, learn, and even make business decisions. With thousands of tools emerging every year, the phrase “there’s an AI for that” is becoming a reality.&lt;/p&gt;

&lt;p&gt;But how do we separate the hype from the truly useful? Let’s break it down.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Where AI is Already Adding Value
&lt;/h3&gt;

&lt;p&gt;Here are five categories where AI tools are making a tangible impact:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Content &amp;amp; Communication&lt;/strong&gt; → Writing assistants, meeting note summarizers, and translation tools.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Productivity&lt;/strong&gt; → AI schedulers, email sorters, and task automation apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Design &amp;amp; Creativity&lt;/strong&gt; → Image generators, video editors, and presentation builders.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Business Intelligence&lt;/strong&gt; → Market research bots, financial analytics, and customer service chatbots.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Personal Growth&lt;/strong&gt; → Learning companions, fitness and nutrition trackers, and mental wellness apps.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  2. Benefits of Using AI Tools
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Speed&lt;/strong&gt; → Automates repetitive tasks in seconds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt; → Handles data and workflows that are hard for humans to manage alone.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accessibility&lt;/strong&gt; → No coding required—most tools are plug-and-play.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. Challenges and Limitations
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Accuracy &amp;amp; Bias&lt;/strong&gt; → AI can produce convincing but incorrect results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Over-reliance&lt;/strong&gt; → Risk of depending on tools without critical thinking.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Privacy Concerns&lt;/strong&gt; → Sensitive data may not always be handled responsibly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tips : Always validate outputs and check how a tool handles your data.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Framework for Choosing the Right AI Tool
&lt;/h3&gt;

&lt;p&gt;When exploring new AI tools, use this simple checklist:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Problem-fit&lt;/strong&gt; → What task am I trying to simplify?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ease of Use&lt;/strong&gt; → Can I or my team adopt it quickly?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integration&lt;/strong&gt; → Does it work with tools we already use?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Value vs. Cost&lt;/strong&gt; → Is the time/money saved worth the price?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Safety&lt;/strong&gt; → How is my information stored and protected?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  5. The Road Ahead
&lt;/h3&gt;

&lt;p&gt;The next wave of AI will be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Domain-specific (healthcare AI, legal AI, education AI).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;More collaborative, working with humans instead of replacing them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better regulated, with clearer standards on ethics and transparency.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Key Takeaway
&lt;/h3&gt;

&lt;p&gt;AI is not here to replace us—it’s here to augment us. The professionals who thrive will be the ones who know how to harness these tools effectively while bringing in human judgment, empathy, and creativity.&lt;/p&gt;

&lt;p&gt;Link - &lt;a href="https://theresanaiforthat.com/" rel="noopener noreferrer"&gt;https://theresanaiforthat.com/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;💡 &lt;strong&gt;Final thought&lt;/strong&gt;: The next time you hit a roadblock in your work, pause and ask yourself: “Is there an AI for that?” Chances are, the answer is yes.&lt;/p&gt;

&lt;p&gt;💡 &lt;strong&gt;Question for you&lt;/strong&gt;: Which AI tool has had the biggest positive impact on your daily work so far?&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Java Stream APIs: A Guide for Developers</title>
      <dc:creator>Bharath S R</dc:creator>
      <pubDate>Fri, 24 Jan 2025 06:05:56 +0000</pubDate>
      <link>https://dev.to/bharath_vasishtha/understanding-java-stream-apis-a-guide-for-developers-2ok6</link>
      <guid>https://dev.to/bharath_vasishtha/understanding-java-stream-apis-a-guide-for-developers-2ok6</guid>
      <description>&lt;p&gt;Java Stream APIs, introduced in Java 8, revolutionized the way developers process collections of data. Streams provide a functional programming approach, enabling concise, expressive, and readable code for operations like filtering, mapping, and reducing data. In this blog, we will explore the core concepts of Java Stream APIs, their advantages, and practical examples to help you harness their full potential.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;What Are Streams?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A Stream is a sequence of elements that supports sequential and parallel aggregate operations. Unlike collections, Streams do not store data; they process it on-demand. This makes them powerful for handling large datasets or performing transformations efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key characteristics of Streams include:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No storage&lt;/strong&gt;: Streams do not modify the underlying data structure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Laziness&lt;/strong&gt;: Operations on streams are executed only when a terminal operation is invoked.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Immutability&lt;/strong&gt;: Streams encourage a functional approach, treating data as immutable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Possibility of parallelism&lt;/strong&gt;: Streams can be processed in parallel, leveraging modern multicore architectures.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Components of Java Streams&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stream Creation&lt;/strong&gt;: Streams can be created from various sources like collections, arrays, or even I/O channels. 
For example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// From a List
List&amp;lt;String&amp;gt; names = Arrays.asList("Alice", "Bob", "Charlie");
Stream&amp;lt;String&amp;gt; stream = names.stream();

// From an Array
int[] numbers = {1, 2, 3, 4, 5};
IntStream intStream = Arrays.stream(numbers);

// Using Stream.of()
Stream&amp;lt;String&amp;gt; stringStream = Stream.of("A", "B", "C");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Intermediate Operations&lt;/strong&gt;: These operations transform a stream into another stream. They are lazy and executed only when a terminal operation is performed.
Examples of intermediate operations:

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;filter()&lt;/code&gt;: Filters elements based on a predicate.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;map()&lt;/code&gt;: Transforms elements using a function.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;sorted()&lt;/code&gt;: Sorts the elements.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;distinct()&lt;/code&gt;: Removes duplicate elements.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Integer&amp;gt; numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
numbers.stream()
       .filter(n -&amp;gt; n % 2 == 0) // Keep only even numbers
       .map(n -&amp;gt; n * n)        // Square each number
       .forEach(System.out::println); // Print each result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Terminal Operations&lt;/strong&gt;: These operations produce a result or a side effect and terminate the stream pipeline.
Examples of terminal operations:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;forEach()&lt;/code&gt;: Performs an action for each element.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;collect()&lt;/code&gt;: Converts the stream back into a collection or other structure.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reduce()&lt;/code&gt;: Reduces the elements into a single value using an accumulator.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;count()&lt;/code&gt;: Returns the count of elements.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;String&amp;gt; words = Arrays.asList("apple", "banana", "cherry");
long count = words.stream()
                  .filter(word -&amp;gt; word.startsWith("a"))
                  .count();
System.out.println("Count of words starting with 'a': " + count);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Parallel Streams&lt;/strong&gt;: By simply invoking parallelStream() instead of stream(), you can process data in parallel.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Integer&amp;gt; largeList = IntStream.range(1, 1000).boxed().toList();
largeList.parallelStream()
        .filter(n -&amp;gt; n % 2 == 0)
        .forEach(System.out::println);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Benefits of Java Streams&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Declarative code&lt;/strong&gt;: Streams simplify complex logic with expressive methods.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency&lt;/strong&gt;: Streams use lazy evaluation, processing data only when needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallelism&lt;/strong&gt;: Parallel streams can dramatically improve performance on large datasets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Readability&lt;/strong&gt;: Functional-style operations reduce boilerplate and improve clarity.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Practical Use Cases&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Filtering and Transforming Data&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;String&amp;gt; names = Arrays.asList("Alice", "Bob", "Charlie", "David");
List&amp;lt;String&amp;gt; filteredNames = names.stream()
                                  .filter(name -&amp;gt; name.length() &amp;gt; 3)
                                  .map(String::toUpperCase)
                                  .collect(Collectors.toList());
System.out.println(filteredNames); // Output: [ALICE, CHARLIE, DAVID]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Finding Maximum and Minimum&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;Integer&amp;gt; numbers = Arrays.asList(3, 5, 7, 2, 8);
int max = numbers.stream()
                 .max(Comparator.naturalOrder())
                 .orElseThrow();
System.out.println("Max: " + max); // Output: Max: 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Grouping and Partitioning&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;String&amp;gt; items = Arrays.asList("apple", "banana", "cherry", "apricot", "blueberry");
Map&amp;lt;Boolean, List&amp;lt;String&amp;gt;&amp;gt; partitioned = items.stream()
                                              .collect(Collectors.partitioningBy(item -&amp;gt; item.startsWith("a")));
System.out.println(partitioned);
// Output: {false=[banana, cherry, blueberry], true=[apple, apricot]}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Best Practices&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use Streams for Declarative Programming&lt;/strong&gt;: Avoid using loops for tasks like filtering, mapping, and aggregation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leverage Method References&lt;/strong&gt;: Use concise syntax like Class::method whenever possible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid Side Effects&lt;/strong&gt;: Streams encourage immutability; avoid modifying variables inside stream operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Know When to Use Parallel Streams&lt;/strong&gt;: Parallelism is powerful but context-dependent. Test performance before adopting it.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Java Stream APIs offer a powerful way to process data with functional-style programming. By mastering streams, you can write clean, efficient, and maintainable code. Whether you're filtering data, transforming collections, or leveraging parallelism, streams are an indispensable tool in modern Java development. Start using them today and see the difference they can make in your projects!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>backend</category>
    </item>
    <item>
      <title>Understanding Java Iterators: A Deep Dive</title>
      <dc:creator>Bharath S R</dc:creator>
      <pubDate>Fri, 03 Jan 2025 14:06:09 +0000</pubDate>
      <link>https://dev.to/bharath_vasishtha/understanding-java-iterators-a-deep-dive-18kk</link>
      <guid>https://dev.to/bharath_vasishtha/understanding-java-iterators-a-deep-dive-18kk</guid>
      <description>&lt;p&gt;When working with collections in Java, an Iterator plays a crucial role in traversing and processing elements efficiently. This blog explores the concept, utility, and implementation of iterators in Java, helping you leverage this tool to manage collections effectively.&lt;/p&gt;




&lt;h3&gt;
  
  
  What is an Iterator?
&lt;/h3&gt;

&lt;p&gt;An Iterator is an object that allows sequential access to elements in a collection without exposing its underlying structure. It is part of the &lt;code&gt;java.util&lt;/code&gt; package and is commonly used with collections like &lt;code&gt;List&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, and &lt;code&gt;Map&lt;/code&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Use Iterators?
&lt;/h3&gt;

&lt;p&gt;Iterators provide a consistent way to traverse collections, irrespective of their type. This consistency is particularly important in complex applications where collections can vary widely in implementation but require uniform processing. Key benefits include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Abstraction&lt;/strong&gt;: You don’t need to worry about how the collection is implemented.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read and Remove&lt;/strong&gt;: You can read and optionally remove elements during iteration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fail-fast Behaviour&lt;/strong&gt;: Iterators in Java collections detect concurrent modifications and throw &lt;code&gt;ConcurrentModificationException&lt;/code&gt;, ensuring data integrity.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  How to Use an Iterator
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Iterator&lt;/code&gt; interface provides three primary methods:&lt;br&gt;
1.&lt;code&gt;hasNext()&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Returns &lt;code&gt;true&lt;/code&gt; if there are more elements to iterate over.&lt;/li&gt;
&lt;li&gt;Example :
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Iterator&amp;lt;String&amp;gt; iterator = list.iterator();
while (iterator.hasNext()) {
    System.out.println(iterator.next());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;2.&lt;code&gt;next()&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Returns the next element in the collection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Throws &lt;code&gt;NoSuchElementException&lt;/code&gt; if no elements are left.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3.&lt;code&gt;remove()&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Removes the last element returned by the iterator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iterator.remove();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Iterator vs Enhanced For Loop
&lt;/h3&gt;

&lt;p&gt;Both iterators and enhanced for-loops simplify collection traversal, but iterators provide more control, such as the ability to remove elements. Enhanced for-loops are ideal for read-only access.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Enhanced for-loop
for (String item : list) {
    System.out.println(item);
}

// Using Iterator
Iterator&amp;lt;String&amp;gt; iterator = list.iterator();
while (iterator.hasNext()) {
    String item = iterator.next();
    if (item.equals("remove")) {
        iterator.remove();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Iterators with Different Collections
&lt;/h3&gt;

&lt;p&gt;1.&lt;strong&gt;List Iterators&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Work with ordered collections.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;List&amp;lt;String&amp;gt; list = Arrays.asList("A", "B", "C");
Iterator&amp;lt;String&amp;gt; iterator = list.iterator();
while (iterator.hasNext()) {
    System.out.println(iterator.next());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.&lt;strong&gt;Set Iterators&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;No duplicates; order is not guaranteed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set&amp;lt;String&amp;gt; set = new HashSet&amp;lt;&amp;gt;(Arrays.asList("A", "B", "C"));
Iterator&amp;lt;String&amp;gt; iterator = set.iterator();
while (iterator.hasNext()) {
    System.out.println(iterator.next());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;strong&gt;Map Iterators&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;entrySet()&lt;/code&gt;, &lt;code&gt;keySet()&lt;/code&gt;, or &lt;code&gt;values()&lt;/code&gt; to iterate over entries, keys, or values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Map&amp;lt;String, Integer&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
map.put("A", 1);
map.put("B", 2);

Iterator&amp;lt;Map.Entry&amp;lt;String, Integer&amp;gt;&amp;gt; iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
    Map.Entry&amp;lt;String, Integer&amp;gt; entry = iterator.next();
    System.out.println(entry.getKey() + "=" + entry.getValue());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Limitations of Iterators
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Single-Directional Traversal&lt;/strong&gt;: Iterators can only move forward.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Concurrent Modification&lt;/strong&gt;: Modifying a collection while iterating over it (outside remove()) throws ConcurrentModificationException.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read and Remove Only&lt;/strong&gt;: Iterators do not support adding elements; for this, use ListIterator.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




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

&lt;p&gt;Java iterators are powerful tools for navigating collections, offering simplicity and consistency. While they have limitations, understanding their use cases and advanced features, like ListIterator, can greatly enhance your ability to manipulate collections efficiently.&lt;/p&gt;

</description>
      <category>java</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding Java Strings: A Comprehensive Guide</title>
      <dc:creator>Bharath S R</dc:creator>
      <pubDate>Thu, 19 Dec 2024 04:31:58 +0000</pubDate>
      <link>https://dev.to/bharath_vasishtha/understanding-java-strings-a-comprehensive-guide-3k7m</link>
      <guid>https://dev.to/bharath_vasishtha/understanding-java-strings-a-comprehensive-guide-3k7m</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In the world of programming, strings play a crucial role in representing and manipulating text data. Java, as a versatile programming language, offers robust support for handling strings, making it an essential topic for developers. This blog provides a comprehensive overview of Java Strings, covering their creation, manipulation, and best practices.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;What is a String in Java?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A &lt;code&gt;String&lt;/code&gt; in Java is an immutable sequence of characters. Unlike primitive data types, strings are objects that belong to the &lt;code&gt;java.lang.String&lt;/code&gt; class. Being immutable means once a &lt;code&gt;String&lt;/code&gt; object is created, it cannot be altered. Any modification results in the creation of a new &lt;code&gt;String&lt;/code&gt; object.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Creating Strings&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Java provides two main ways to create strings:&lt;/p&gt;

&lt;p&gt;1.Using String Literals:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String str1 = "Hello, World!";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a string literal is used, it is stored in the String Pool, a special area of memory that optimises memory usage by reusing instances.&lt;/p&gt;

&lt;p&gt;2.Using the &lt;code&gt;new&lt;/code&gt; Keyword:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String str2 = new String("Hello, World!");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach creates a new object in the heap memory, bypassing the String Pool.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;String Methods&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;String&lt;/code&gt; class in Java offers numerous methods for common operations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Length of a String:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int length = str1.length();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Character Extraction:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;char ch = str1.charAt(0); // Gets the first character
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.Substring:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String sub = str1.substring(0, 5); // "Hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4.String Comparison:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;boolean isEqual = str1.equals("Hello, World!");
int result = str1.compareTo("Hello");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5.Case Conversion:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String lower = str1.toLowerCase();
String upper = str1.toUpperCase();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6.Trimming Whitespaces:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String trimmed = str1.trim();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7.Replacing Characters or Substrings:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String replaced = str1.replace("World", "Java");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8.Splitting Strings:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] words = str1.split(", ");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;String Immutability and Performance&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Why Strings are Immutable:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Security: Immutable strings are safer for handling sensitive data like passwords.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performance: String Pool reuses immutable strings, reducing memory overhead.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Thread-Safety: Immutability makes strings inherently thread-safe.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Performance Tip&lt;/strong&gt;: For scenarios involving frequent string modifications, use &lt;code&gt;StringBuilder&lt;/code&gt; or &lt;code&gt;StringBuffer&lt;/code&gt; instead of &lt;code&gt;String&lt;/code&gt; to avoid creating multiple objects.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;StringBuilder sb = new StringBuilder("Hello");
sb.append(", Java!");
System.out.println(sb.toString());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;String Pool in Java&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The String Pool is a special memory area inside the Java Heap. It stores string literals to optimize memory usage. When a string literal is created, the JVM checks the pool for an existing identical string. If found, the reference is reused; otherwise, a new string is added to the pool.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String s1 = "Java";
String s2 = "Java";
System.out.println(s1 == s2); // true (same reference)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String s3 = new String("Java");
System.out.println(s1 == s3); // false (different references)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Strings in Java are versatile and powerful. Understanding their immutability, the String Pool, and best practices ensures efficient and effective string manipulation. Whether you are formatting text, processing user inputs, or working with files, mastering Java strings is fundamental to becoming a proficient Java developer. Thanks for reading !!&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>productivity</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Wrapper Classes in Java</title>
      <dc:creator>Bharath S R</dc:creator>
      <pubDate>Mon, 09 Dec 2024 09:50:40 +0000</pubDate>
      <link>https://dev.to/bharath_vasishtha/wrapper-classes-in-java-4e4f</link>
      <guid>https://dev.to/bharath_vasishtha/wrapper-classes-in-java-4e4f</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Understanding Wrapper Classes in Java&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Java is a versatile programming language that provides features for both object-oriented and procedural programming. One unique aspect of Java is its wrapper classes, which bridge the gap between primitive data types and objects. In this blog, we will dive into what wrapper classes are, why they are essential, and how to use them effectively in your Java programs.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What Are Wrapper Classes?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Wrapper classes in Java are part of the java.lang package. They provide a way to use primitive data types (‘int’, ‘char’, etc.) as objects. This is crucial in scenarios where objects are required, such as when working with Java Collections (e.g., ArrayList, HashMap) or frameworks like Reflection and Serialization.&lt;/p&gt;

&lt;p&gt;Each primitive data type has a corresponding wrapper class:&lt;/p&gt;

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

&lt;h3&gt;
  
  
  &lt;strong&gt;Key Features of Wrapper Classes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1.Auto-boxing and Unboxing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Java simplifies working with wrapper classes by supporting automatic conversion between primitives and their corresponding wrapper objects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Autoboxing&lt;/strong&gt;: Automatic conversion of a primitive type to its wrapper class object&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unboxing&lt;/strong&gt;: Automatic conversion of a wrapper class object to its primitive type&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int num = 10;
Integer obj = num; // Autoboxing

Integer obj2 = 20;
int num2 = obj2; // Unboxing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Utility Methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Wrapper classes provide several methods to perform operations like type conversion and validation. Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Integer.parseInt(String s)&lt;/code&gt;: Converts a string to an int&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Double.valueOf(String s)&lt;/code&gt;: Converts a string to a Double object&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Character.isDigit(char ch)&lt;/code&gt;: Checks if a character is a digit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Boolean.parseBoolean(String s)&lt;/code&gt;: Parses a string into a boolean value&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Immutability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Wrapper class objects are immutable, meaning their values cannot be changed once created. This ensures thread safety and consistency in Java programs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Nullability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Unlike primitive types, wrapper objects can hold null values. This feature is useful when working with databases or when a variable's value needs to be optional.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Why Are Wrapper Classes Important?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1.Compatibility with Collections API&lt;/strong&gt;: Java Collections like ArrayList, HashMap, and others store only objects. Wrapper classes enable primitives to be stored in these collections.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ArrayList&amp;lt;Integer&amp;gt; numbers = new ArrayList&amp;lt;&amp;gt;();
numbers.add(5); // Autoboxing
numbers.add(10);
System.out.println(numbers);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Utility and Conversion&lt;/strong&gt;: Wrapper classes offer methods to convert between strings and primitives or validate input.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String str = "123";
int num = Integer.parseInt(str); // Convert String to int
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.Framework Compatibility&lt;/strong&gt;: Reflection, Serialization, and other frameworks require objects, not primitives. Wrapper classes make primitives compatible in such scenarios.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Common Use Cases&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Auto-boxing and Unboxing Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class WrapperExample {
    public static void main(String[] args) {
        Integer obj = 100; // Autoboxing
        int num = obj;    // Unboxing

        System.out.println("Wrapper Object: " + obj);
        System.out.println("Primitive Value: " + num);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Converting String to Primitive and Vice Versa&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class StringConversion {
    public static void main(String[] args) {
        String str = "456";

        // Convert String to int
        int number = Integer.parseInt(str);

        // Convert int to String
        String newStr = Integer.toString(number);

        System.out.println("Integer value: " + number);
        System.out.println("String value: " + newStr);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Validating Input Data&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class InputValidation {
    public static void main(String[] args) {
        char ch = '5';

        if (Character.isDigit(ch)) {
            System.out.println(ch + " is a digit.");
        } else {
            System.out.println(ch + " is not a digit.");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Things to Keep in Mind&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Performance Overhead&lt;/strong&gt;: Autoboxing and unboxing can introduce performance overhead when used in loops or frequently executed code&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. NullPointerException&lt;/strong&gt;: Accessing a null wrapper object can lead to NullPointerException during unboxing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Memory Usage&lt;/strong&gt;: Wrapper objects consume more memory compared to primitives. Use primitives where object behavior is not required.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Wrapper classes in Java are an essential tool that allows developers to seamlessly integrate primitive types into object-oriented frameworks and collections. By understanding their features, use cases, and limitations, you can write efficient and error-free Java code.&lt;/p&gt;

&lt;p&gt;Whether you're working on a complex application or just learning Java, knowing when and how to use wrapper classes is a skill every developer should master!&lt;/p&gt;

</description>
      <category>java</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Exception Handling in Java</title>
      <dc:creator>Bharath S R</dc:creator>
      <pubDate>Thu, 05 Dec 2024 10:46:49 +0000</pubDate>
      <link>https://dev.to/bharath_vasishtha/exception-handling-in-java-564o</link>
      <guid>https://dev.to/bharath_vasishtha/exception-handling-in-java-564o</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Java exceptions are events that disrupt the normal flow of a program during runtime. They are objects representing errors or unusual conditions that the program should handle to prevent crashing or unexpected behaviour.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Types of Java Exceptions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1.Checked Exceptions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;These are exceptions that are checked at compile time&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The program must handle these exceptions using a &lt;code&gt;try-catch&lt;/code&gt; block or declare them using the &lt;code&gt;throws&lt;/code&gt; keyword.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Examples: &lt;code&gt;IOException&lt;/code&gt;, &lt;code&gt;SQLException&lt;/code&gt;, &lt;code&gt;FileNotFoundException&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.Unchecked Exceptions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;These occur during runtime and are not checked at compile time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They usually result from programming errors, such as logic mistakes or improper use of APIs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Examples: &lt;code&gt;NullPointerException&lt;/code&gt;, &lt;code&gt;ArrayIndexOutOfBoundsException&lt;/code&gt;, &lt;code&gt;ArithmeticException&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3.Errors&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Represent serious problems that applications should not try to catch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Examples: &lt;code&gt;OutOfMemoryError&lt;/code&gt;, &lt;code&gt;StackOverflowError&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Exception Handling in Java&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Java uses the following keywords for exception handling:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;try&lt;/code&gt;: Code that might throw an exception is enclosed in a try block.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;catch&lt;/code&gt;: Handles specific exceptions thrown by the try block.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;finally&lt;/code&gt;: Block that is always executed after try and catch, regardless of whether an exception occurred.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;throw&lt;/code&gt;: Used to explicitly throw an exception.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;throws&lt;/code&gt;: Declares exceptions that a method might throw.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Syntax Example&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.io.*;

public class ExceptionExample {
    public static void main(String[] args) {
        try {
            // Code that may throw an exception
            FileInputStream file = new FileInputStream("test.txt");
        } catch (FileNotFoundException e) {
            // Handling the exception
            System.out.println("File not found: " + e.getMessage());
        } finally {
            // Always executed
            System.out.println("Execution completed.");
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Commonly Used Exception Classes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;IOException&lt;/code&gt;: Input-output operations failure.&lt;br&gt;
&lt;code&gt;SQLException&lt;/code&gt;: Database access errors.&lt;br&gt;
&lt;code&gt;ClassNotFoundException&lt;/code&gt;: Class not found during runtime.&lt;br&gt;
&lt;code&gt;ArithmeticException&lt;/code&gt;: Invalid arithmetic operations (e.g., division by zero).&lt;br&gt;
&lt;code&gt;NullPointerException&lt;/code&gt;: Attempt to use an object reference that is null.&lt;br&gt;
&lt;code&gt;IllegalArgumentException&lt;/code&gt;: Method has been passed an inappropriate argument.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Custom Exceptions&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You can create custom exceptions by extending the &lt;code&gt;Exception&lt;/code&gt; or &lt;code&gt;RuntimeException&lt;/code&gt; class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MyCustomException extends Exception {
    public MyCustomException(String message) {
        super(message);
    }
}

public class CustomExceptionExample {
    public static void main(String[] args) {
        try {
            throw new MyCustomException("Custom error occurred");
        } catch (MyCustomException e) {
            System.out.println(e.getMessage());
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Java exceptions are critical for handling errors and maintaining application stability. They are categorized into checked exceptions (like &lt;code&gt;IOException&lt;/code&gt;) that are handled at compile-time, unchecked exceptions (like &lt;code&gt;NullPointerException&lt;/code&gt;) that occur during runtime, and errors (like &lt;code&gt;OutOfMemoryError&lt;/code&gt;) indicating serious issues.&lt;/p&gt;

&lt;p&gt;Java's robust exception-handling mechanism includes keywords like &lt;code&gt;try&lt;/code&gt;, &lt;code&gt;catch&lt;/code&gt;, &lt;code&gt;finally&lt;/code&gt;, &lt;code&gt;throw&lt;/code&gt;, and &lt;code&gt;throws&lt;/code&gt;, allowing developers to manage errors gracefully. Custom exceptions can also be created to address application-specific issues. By effectively leveraging Java's exception handling, developers can build resilient and user-friendly applications. Happy Coding!!&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Lombok</title>
      <dc:creator>Bharath S R</dc:creator>
      <pubDate>Wed, 04 Dec 2024 10:17:25 +0000</pubDate>
      <link>https://dev.to/bharath_vasishtha/lombok-2o8i</link>
      <guid>https://dev.to/bharath_vasishtha/lombok-2o8i</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Lombok is a Java library designed to reduce boilerplate code in Java applications. It achieves this by providing annotations that automate repetitive tasks like getters, setters, constructors, equals, hashCode, and more. This helps developers write clean and concise code while maintaining functionality.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Key Features of Lombok&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.Annotations for Boilerplate Reduction&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@Getter and @Setter&lt;/code&gt;: Automatically generates getter and setter methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@ToString&lt;/code&gt;: Creates a toString method for the class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@EqualsAndHashCode&lt;/code&gt;: Generates equals and hashCode methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@NoArgsConstructor&lt;/code&gt;, &lt;code&gt;@AllArgsConstructor&lt;/code&gt;, &lt;code&gt;@RequiredArgsConstructor&lt;/code&gt;: Automates constructor creation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2.Builder Pattern Support&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Builder&lt;/code&gt;: Implements the builder pattern for object creation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3.Immutability&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Value&lt;/code&gt;: Creates immutable classes (like a &lt;strong&gt;final&lt;/strong&gt; class with &lt;strong&gt;private&lt;/strong&gt; fields, a constructor, getters, and &lt;strong&gt;toString&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4.Logging Annotations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Slf4j&lt;/code&gt;, &lt;code&gt;@Log&lt;/code&gt;, etc.: Add loggers for common logging frameworks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Example Usage&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import lombok.Data;

@Data
public class User {
    private String firstName;
    private String lastName;
    private int age;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This single annotation (&lt;code&gt;@Data&lt;/code&gt;) will generate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;getName, setName, getAge, setAge methods &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;toString method &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;equals and hashCode methods&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A default constructor&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Advantages&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Reduces boilerplate code significantly&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improves code readability and maintainability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Speeds up development by automating repetitive tasks&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Drawbacks&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;May obscure logic for those unfamiliar with Lombok&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generated code is not visible in the IDE, which might complicate debugging&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dependency on an external library&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to Add Lombok to Your Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.Maven&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;org.projectlombok&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;lombok&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;1.18.30&amp;lt;/version&amp;gt;
    &amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.Gradle&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;implementation 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3.IDE Support&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Install the Lombok plugin in your IDE (IntelliJ IDEA, Eclipse, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable annotation processing in your IDE settings&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In conclusion, Lombok is a powerful tool that streamlines Java development by eliminating repetitive boilerplate code, allowing developers to focus on the core functionality of their applications. While it requires some initial familiarity and setup, its productivity benefits far outweigh the learning curve. By adopting Lombok, you can achieve cleaner, more maintainable code and accelerate your development process, making it an essential library for modern Java projects.Happy Coding !!&lt;/p&gt;

</description>
      <category>lombok</category>
      <category>java</category>
      <category>javalombok</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
