<?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: GAURAV KUMAR</title>
    <description>The latest articles on DEV Community by GAURAV KUMAR (@sgvugaurav).</description>
    <link>https://dev.to/sgvugaurav</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%2F1050403%2F0efcb58b-bf0a-4b8b-aabc-3cd62ca7639a.jpeg</url>
      <title>DEV Community: GAURAV KUMAR</title>
      <link>https://dev.to/sgvugaurav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sgvugaurav"/>
    <language>en</language>
    <item>
      <title>Make a grid element span to the full width of the parent</title>
      <dc:creator>GAURAV KUMAR</dc:creator>
      <pubDate>Thu, 27 Jun 2024 05:05:58 +0000</pubDate>
      <link>https://dev.to/sgvugaurav/make-a-grid-element-span-to-the-full-width-of-the-parent-3ecc</link>
      <guid>https://dev.to/sgvugaurav/make-a-grid-element-span-to-the-full-width-of-the-parent-3ecc</guid>
      <description>&lt;p&gt;No buildup. Let's get to the point.&lt;/p&gt;

&lt;p&gt;You have a grid container, and it has some child elements divided into as many columns as you want. For now, let's say the grid container has seven elements, and those elements are divided into three columns. You want the seventh element to take up the full width of the parent.&lt;/p&gt;

&lt;p&gt;Here's the code snippet.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.seven&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;grid-column&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="p"&gt;/&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checkout a full example here: &lt;a href="https://codepen.io/ccgaejza-the-selector/pen/dyELmRE"&gt;https://codepen.io/ccgaejza-the-selector/pen/dyELmRE&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>grid</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Get The Underlying OS on which the program is running in Java</title>
      <dc:creator>GAURAV KUMAR</dc:creator>
      <pubDate>Tue, 15 Aug 2023 10:18:19 +0000</pubDate>
      <link>https://dev.to/sgvugaurav/get-the-underlying-os-on-which-the-program-is-running-in-java-26ol</link>
      <guid>https://dev.to/sgvugaurav/get-the-underlying-os-on-which-the-program-is-running-in-java-26ol</guid>
      <description>&lt;p&gt;You may want to know the operating system on which your Java program is running because you want to&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Implement platform-specific behavior →&lt;/strong&gt; Let’s say you need to construct a file path in your program. But the ways in which file paths are constructed on Windows and Unix-based systems are different. Knowing the OS on which the program is running may help you implement a robust solution that works on different systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use a platform-specific library →&lt;/strong&gt; There are some libraries that work only on a particular OS. So, you want to know whether you can use one library in your program.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access System Properties →&lt;/strong&gt; There are some system properties that have different values on different operating systems. Such as the default temporary directory or the user home directory. Knowing the OS may help you access these values correctly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you have any of the above-mentioned use cases or any other use cases, but you want to know the OS on which your programming is running, you are in the right place.&lt;/p&gt;

&lt;p&gt;Hi! I’m Gaurav Kumar, and you’re welcome to &lt;strong&gt;"Re-Inventing the Wheel"&lt;/strong&gt;. Now, without further ado, let's see the code that will tell us about the OS on which it’s running.&lt;/p&gt;

&lt;p&gt;Below is the code snippet to know the underlying OS on which it’s running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getProperty&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"os.name"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OS: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The string inside the &lt;strong&gt;&lt;code&gt;getProperty()&lt;/code&gt;&lt;/strong&gt; method is case-sensitive. Make sure that each letter used is in lowercase; otherwise, it returns &lt;code&gt;**null**&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other ways to determine the OS
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Using &lt;strong&gt;&lt;code&gt;System.getenv&lt;/code&gt;&lt;/strong&gt; method&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getenv&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OS"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OS: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This code works fine on Windows. However, this code is not portable as the &lt;strong&gt;&lt;em&gt;OS&lt;/em&gt;&lt;/strong&gt; environment variable is not present by default on many other operating systems, such as &lt;strong&gt;Linux and Mac OS&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using &lt;strong&gt;&lt;code&gt;Runtime.exe&lt;/code&gt;&lt;/strong&gt; method&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Process&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Runtime&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getRuntime&lt;/span&gt;&lt;span class="o"&gt;().&lt;/span&gt;&lt;span class="na"&gt;exec&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"uname -s"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nc"&gt;BufferedReader&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BufferedReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;InputStreamReader&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getInputStream&lt;/span&gt;&lt;span class="o"&gt;()));&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reader&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;readLine&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Operating system: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This code executes the &lt;strong&gt;&lt;code&gt;uname -s&lt;/code&gt;&lt;/strong&gt; command, which returns the name of the operating system on Unix-based systems. However, this approach is not portable, as the &lt;strong&gt;&lt;code&gt;uname&lt;/code&gt;&lt;/strong&gt; command may not be available on all operating systems.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;The most reliable way to know the OS on which a program is running is to use &lt;strong&gt;&lt;code&gt;System.getProperty&lt;/code&gt;&lt;/strong&gt; method that works on all the operating systems.&lt;/p&gt;

&lt;p&gt;At the end, I would like to take this opportunity to thank you for reading this article until the end.&lt;/p&gt;

&lt;p&gt;Happy Coding 😀!&lt;/p&gt;

&lt;p&gt;See you soon!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Get URL pointed Resource Information in Java</title>
      <dc:creator>GAURAV KUMAR</dc:creator>
      <pubDate>Sat, 12 Aug 2023 10:11:41 +0000</pubDate>
      <link>https://dev.to/sgvugaurav/get-url-pointed-resource-information-in-java-2o4i</link>
      <guid>https://dev.to/sgvugaurav/get-url-pointed-resource-information-in-java-2o4i</guid>
      <description>&lt;p&gt;In this post we are going to know how to make HTTP requests in java. We'll see two ways - 1. Before Java 11 and 2. After Java 11.&lt;/p&gt;

&lt;p&gt;Let us first see how we could make HTTP requests before Java 11. Here we are going to retrieve various metadata information of a file pointed by and URL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package org.gaurav;

import java.io.IOException;
import java.net.*;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        String url1 = "https://resources.docs.salesforce.com/latest/latest/en-us/sfdc/pdf/salesforce_useful_validation_formulas.pdf";
        String url2 = "https://fastly.picsum.photos/id/112/600/600.jpg?hmac=hakYJ0LrbvOQ1fnbvBGE1ThGxufcyCWKNAfXrctqyWQ";
        String url3 = "https://picsum.photos/200/300";

        System.out.println("First URL Information");
        printHeaders(url1);

        System.out.println();
        System.out.println("Second URL Information");
        printHeaders(url2);

        System.out.println();
        System.out.println("Third URL Information");
        printHeaders(url3);
    }

    public static void printHeaders(String fileUrl) {
        try {
            URL url = new URI(fileUrl).toURL();
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            Map&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt; headers = connection.getHeaderFields();

            for (Map.Entry&amp;lt;String, java.util.List&amp;lt;String&amp;gt;&amp;gt; entry : headers.entrySet()) {
                System.out.println(entry.getKey() + ": " + entry.getValue());
            }

            connection.disconnect();
        } catch (IOException | URISyntaxException e) {
            e.printStackTrace();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the above code to see the output.&lt;/p&gt;

&lt;p&gt;Now, let us see how we can do the same thing using &lt;strong&gt;&lt;em&gt;Http Client API&lt;/em&gt;&lt;/strong&gt; introduced in Java 11.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package org.gaurav;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        String url1 = "https://resources.docs.salesforce.com/latest/latest/en-us/sfdc/pdf/salesforce_useful_validation_formulas.pdf";
        String url2 = "https://fastly.picsum.photos/id/112/600/600.jpg?hmac=hakYJ0LrbvOQ1fnbvBGE1ThGxufcyCWKNAfXrctqyWQ";
        String url3 = "https://picsum.photos/200/300";

        System.out.println("First URL Information");
        printHeaders(url1);

        System.out.println();
        System.out.println("Second URL Information");
        printHeaders(url2);

        System.out.println();
        System.out.println("Third URL Information");
        printHeaders(url3);
    }

    public static void printHeaders(String fileUrl) {
        HttpClient httpClient = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(fileUrl))
                .build();

        try {
            HttpResponse&amp;lt;Void&amp;gt; response = httpClient.send(request, HttpResponse.BodyHandlers.discarding());
            Map&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt; headers = response.headers().map();
            for (Map.Entry&amp;lt;String, List&amp;lt;String&amp;gt;&amp;gt; entry : headers.entrySet()) {
                System.out.println(entry.getKey() + ": " + entry.getValue());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let us discuss some reasons why should we use the newer one?&lt;/p&gt;

&lt;p&gt;Here are a few reasons why these newer alternatives are preferred:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flexibility and Ease of Use:&lt;/strong&gt; Libraries like Apache HttpClient and java.net.http.HttpClient provide more intuitive APIs for making HTTP requests and handling responses. They offer higher-level abstractions and better support for modern HTTP features.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: The newer libraries are designed with modern performance considerations in mind, including better connection pooling and asynchronous capabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Standardization&lt;/strong&gt;: The java.net.http.HttpClient is part of the Java SE platform starting from Java 11, which means it's a standardized part of the Java ecosystem.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Functional Programming:&lt;/strong&gt; The new libraries often leverage functional programming features to provide more concise and expressive code when dealing with asynchronous operations.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; While HttpURLConnection can still be used for basic scenarios, newer libraries like Apache HttpClient and java.net.http.HttpClient offer better performance, improved features, and a more intuitive API for making HTTP requests and working with responses. It's a good idea to consider these alternatives when working with HTTP in modern Java applications.&lt;/p&gt;

</description>
      <category>java</category>
      <category>networking</category>
      <category>programming</category>
      <category>development</category>
    </item>
    <item>
      <title>How to get required fields of an SObject in Apex</title>
      <dc:creator>GAURAV KUMAR</dc:creator>
      <pubDate>Wed, 22 Mar 2023 15:56:59 +0000</pubDate>
      <link>https://dev.to/sgvugaurav/how-to-get-required-fields-of-an-sobject-in-apex-k96</link>
      <guid>https://dev.to/sgvugaurav/how-to-get-required-fields-of-an-sobject-in-apex-k96</guid>
      <description>&lt;p&gt;Following is the code that can save you time from search on the web- "How to find all the required fields of an SObject in Apex?"&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 DynamicApex {
    public FieldWrapper getFields(String objName) {
        try {
            FieldWrapper wr = new FieldWrapper();
            for (Schema.SObjectField f : Schema.getGlobalDescribe().get(objName).getDescribe().fields.getMap().values()) {
                Schema.DescribeFieldResult r = f.getDescribe();
                if (!r.isNillable() &amp;amp;&amp;amp; r.isCreateable() &amp;amp;&amp;amp; !r.isDefaultedOnCreate()) {
                    wr.requiredFields.add(r.getName());
                } else {
                    wr.otherFields.add(r.getName());
                }
            }
            return wr;
        } catch (Exception e) {
            throw new TypeException(e.getMessage());
        }
    }

    public class FieldWrapper {
        public List&amp;lt;String&amp;gt; requiredFields;
        public List&amp;lt;String&amp;gt; otherFields;

        FieldWrapper() {
            this.requiredFields = new List&amp;lt;String&amp;gt;();
            this.otherFields = new List&amp;lt;String&amp;gt;();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>apex</category>
      <category>salesforce</category>
      <category>programming</category>
      <category>dynamicapex</category>
    </item>
  </channel>
</rss>
