<?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: António Macave</title>
    <description>The latest articles on DEV Community by António Macave (@antoniomacave).</description>
    <link>https://dev.to/antoniomacave</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%2F1137698%2F8261178c-b34a-47c2-ba46-178d6631866b.png</url>
      <title>DEV Community: António Macave</title>
      <link>https://dev.to/antoniomacave</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/antoniomacave"/>
    <language>en</language>
    <item>
      <title>Benefits of Separating the Database and Other Services from the Web Application</title>
      <dc:creator>António Macave</dc:creator>
      <pubDate>Fri, 10 Jan 2025 16:28:24 +0000</pubDate>
      <link>https://dev.to/antoniomacave/benefits-of-separating-the-database-and-other-services-from-the-web-application-39fp</link>
      <guid>https://dev.to/antoniomacave/benefits-of-separating-the-database-and-other-services-from-the-web-application-39fp</guid>
      <description>&lt;p&gt;Separating critical components, such as the database, queue services (e.g., RabbitMQ, Apache Kafka), and cache services (e.g., Redis), into physically distinct servers is a practice that offers several advantages, particularly in &lt;strong&gt;performance, scalability, and security&lt;/strong&gt;. This practice also aligns with the 4th principle (Backing Services) of the 12-Factor App &lt;a href="https://12factor.net/backing-services" rel="noopener noreferrer"&gt;https://12factor.net/backing-services&lt;/a&gt;, which emphasizes the separation of responsibilities and the construction of applications with independent services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;&lt;br&gt;
Separating these components eliminates resource contention within the same machine. By dedicating specific servers to each service, resources like CPU, RAM, and storage are optimized for the exclusive use of one service. For example, we know that the database consumes significant CPU and memory resources, so allocating more resources to it can be an efficient strategy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;&lt;br&gt;
This approach creates an additional layer of security, aligned with the Defense in Depth strategy. When all services are on the same server, exploiting a vulnerability in one service can affect others, leading to cross-contamination risks. The physical separation of services provides isolation, limiting the impact of a potential security breach.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;&lt;br&gt;
Scalability is one of the main advantages of this practice. By separating services, each can be scaled independently without affecting the others. For example, if the web application experiences a traffic surge, we can add more memory and CPU to the application server without impacting other services, such as the database.&lt;/p&gt;

&lt;p&gt;This approach also aligns with the 4th principle of the 12-Factor App, which advocates for the separation of responsibilities between different components of the application. By adopting this practice, we ensure a more flexible and resilient architecture, allowing services to be scaled and managed independently, which is essential to face the challenges of modern applications.&lt;/p&gt;

</description>
      <category>performance</category>
      <category>microservices</category>
      <category>security</category>
      <category>database</category>
    </item>
    <item>
      <title>How to generate a random password in Java</title>
      <dc:creator>António Macave</dc:creator>
      <pubDate>Tue, 15 Aug 2023 18:55:44 +0000</pubDate>
      <link>https://dev.to/antoniomacave/how-to-generate-a-random-password-in-java-32c</link>
      <guid>https://dev.to/antoniomacave/how-to-generate-a-random-password-in-java-32c</guid>
      <description>&lt;p&gt;Hi folks!&lt;br&gt;
I hope you all are fine! Today, I want to show you how to generate a random password.&lt;br&gt;
First of all, we need to create the class and define the valid characters for our password.&lt;/p&gt;

&lt;p&gt;Well, lets consider characters 0 to 9, A to Z, capital and lower cases.&lt;br&gt;
We can call the class &lt;strong&gt;PasswordGenerator&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 PasswordGenerator {
    public static void main(String[] args) {
        String validChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
        char[] chars = validChars.split(",");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, lets create the method that will generate the password. And this, is going to return a String. And we can call it with an int parameter, and lets call it &lt;strong&gt;length&lt;/strong&gt;.&lt;br&gt;
This method will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static String generatePassword(int length) {
 //code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, inside this method, lets write the real code that generates it for us!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static String generatePassword(int passLength) {

        //Setting the valid charaters for the generated password
        String validChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";

        //Creating an array by splitting the above String by the comma
        String[] chars = validChars.split(",");

        //Create the String that will store each charater that will be chosen
        StringBuilder password = new StringBuilder();

        //This object will be the random that will "bounce" between the chars array.
        //Don't forget to import the Random class from util package (java.util.Random).
        Random r = new Random();

        //This loop will make the Random object (r) bounce between the array many times
        //The quantity of times is called "passLength"
        for (int i = 0; i &amp;lt; passLength; i++){
            password.append(chars[r.nextInt(chars.length)]);
        }

        return password.toString();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, we have to call this method inside the main method. Lets do it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {
        //In this example, we generate a 20 lengthened password
        //But you can set the length you want
        System.out.println(generatePassword(20));

    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, heres is the full code:&lt;br&gt;
&lt;/p&gt;

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


public class PasswordGenerator {

    public static void main(String[] args) {
        //In this example, we generate a 20 lengthened password
        //But you can set the length you want
        System.out.println(generatePassword(20));

    }

    public static String generatePassword(int length) {

        String validChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
        String[] chars = validChars.split(",");

        StringBuilder password = new StringBuilder();

        Random r = new Random();

        for (int i = 0; i &amp;lt; length; i++){
            password.append(chars[r.nextInt(chars.length)]);
        }

        return password.toString();
    }


}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets compile the code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aCrGv4F2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y61lllssh3y387qd12eq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aCrGv4F2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y61lllssh3y387qd12eq.png" alt="Image description" width="666" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0I55eeHV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmmar2k8uxxlrpsbb4q0.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0I55eeHV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bmmar2k8uxxlrpsbb4q0.JPG" alt="Image description" width="666" height="275"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great! No errors!&lt;/p&gt;

&lt;p&gt;Lets execute.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8C9Yb-L4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a0gl5e727ou1lecf06d1.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8C9Yb-L4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a0gl5e727ou1lecf06d1.JPG" alt="Image description" width="572" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets execute again!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--StkZ3SfO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjki3ursxubzpveb9xzh.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--StkZ3SfO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hjki3ursxubzpveb9xzh.JPG" alt="Image description" width="604" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You see? Different results!&lt;/p&gt;

&lt;p&gt;We did it!&lt;/p&gt;

</description>
      <category>java</category>
      <category>random</category>
    </item>
  </channel>
</rss>
