<?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: Felipe Azevedo</title>
    <description>The latest articles on DEV Community by Felipe Azevedo (@felipeazsantos).</description>
    <link>https://dev.to/felipeazsantos</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%2F1807677%2Fc2939e78-7ef3-4e4d-964c-18df84e83184.jpg</url>
      <title>DEV Community: Felipe Azevedo</title>
      <link>https://dev.to/felipeazsantos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/felipeazsantos"/>
    <language>en</language>
    <item>
      <title>How the JVM Executes Your Code: From Bytecode to Native Code</title>
      <dc:creator>Felipe Azevedo</dc:creator>
      <pubDate>Tue, 11 Feb 2025 15:58:30 +0000</pubDate>
      <link>https://dev.to/felipeazsantos/how-the-jvm-executes-your-code-from-bytecode-to-native-code-d79</link>
      <guid>https://dev.to/felipeazsantos/how-the-jvm-executes-your-code-from-bytecode-to-native-code-d79</guid>
      <description>&lt;p&gt;If you program in Java, you've probably heard that "Java is slow." But is it really? The JVM is a true optimization machine, and if you understand how it works, you can make the most of its power. In this article, we'll explore how your code goes from something readable by humans to a whirlwind of binary instructions running at full speed on your CPU.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. From Source to Bytecode: The First Transformation
&lt;/h2&gt;

&lt;p&gt;It all starts with your beautiful, well-indented code (or maybe not so much). When you compile a &lt;code&gt;.java&lt;/code&gt; file with &lt;code&gt;javac&lt;/code&gt;, it doesn't turn into a binary ready to run on your operating system. Instead, the compiler generates &lt;strong&gt;bytecode&lt;/strong&gt;, a set of intermediate instructions that the JVM understands.&lt;/p&gt;

&lt;p&gt;This means your code can run on any system with a JVM installed. It's like a universal pass to run Java anywhere.&lt;/p&gt;

&lt;p&gt;Basic example of Java code:&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="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloWorld&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&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;"Hello, JVM!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;javac HelloWorld.java
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This generates a &lt;code&gt;HelloWorld.class&lt;/code&gt; file, which contains bytecode.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Bytecode Interpretation by the JVM
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;JVM Interpreter&lt;/strong&gt; takes that bytecode and executes it instruction by instruction. It works like a simultaneous translator between your code and the CPU. This ensures that Java runs on any platform, but it can be a bit... slow.&lt;/p&gt;

&lt;p&gt;To do its job, the JVM uses an &lt;strong&gt;operand stack&lt;/strong&gt;, where it pushes and pops values as needed. Each method call gets a &lt;strong&gt;stack frame&lt;/strong&gt;, ensuring everything is isolated and organized. This stack is essential for correct program execution, storing local variables, temporary values, and references to objects.&lt;/p&gt;

&lt;p&gt;In addition, the JVM has several &lt;strong&gt;memory areas&lt;/strong&gt; that help with execution, like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Heap&lt;/strong&gt;: Where dynamically created objects are stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Metaspace&lt;/strong&gt;: Where information about classes is stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stack&lt;/strong&gt;: Where method calls and local variables are stored.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why Pure Interpretation Can Be Inefficient?
&lt;/h3&gt;

&lt;p&gt;Interpreting line by line is flexible, but it can be slow because each instruction has to be analyzed and executed individually. Imagine you needed to add two numbers millions of times; doing that through the interpreter would take much longer than executing raw machine code.&lt;/p&gt;

&lt;p&gt;That's why the JVM doesn't stick to pure interpretation. It has a trick up its sleeve called the &lt;strong&gt;Just-In-Time (JIT) Compiler&lt;/strong&gt;, which we'll look at next.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Just-In-Time (JIT) Compiler
&lt;/h2&gt;

&lt;p&gt;Instead of interpreting each line every time the program runs, the JVM realizes that certain parts of the code are used all the time. These "hotspots" are then compiled &lt;strong&gt;just in time&lt;/strong&gt; into pure machine code, eliminating the need for interpretation.&lt;/p&gt;

&lt;p&gt;This is the magic of the &lt;strong&gt;JIT Compiler&lt;/strong&gt;. It dynamically converts bytecode into native code, vastly improving performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  JIT Strategies
&lt;/h3&gt;

&lt;p&gt;The JVM has different strategies for Just-In-Time compilation, each optimized for a specific scenario:&lt;/p&gt;

&lt;h4&gt;
  
  
  Client (C1):
&lt;/h4&gt;

&lt;p&gt;C1 focuses on fast compilation, ideal for short-lived applications. It excels at reducing initial latency and delivering acceptable performance quickly without doing complex optimizations. Its main feature is the ability to compile methods efficiently without compromising runtime. This model is perfect for scenarios where response speed is more important than long-term performance, like in desktop applications where quick startup is critical.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server (C2):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;C2 is designed for aggressive optimizations, aiming to improve long-term performance. Its main advantage is generating highly optimized code after analyzing the program's execution patterns. The C2 compilation process involves gathering execution statistics, which allows for more efficient code generation. This type of compilation is ideal for servers and applications that run continuously, where the benefits of advanced optimizations can be fully leveraged over time, maximizing performance for long-running systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Graal JIT:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Graal JIT stands out for its high performance and flexibility, supporting multiple languages. Its modern architecture outperforms C2 in some situations, and because it's written in Java, it's highly adaptable to different contexts. It uses advanced optimization and code generation techniques to maximize performance, offering significant gains, especially in more demanding scenarios. The Graal JIT is ideal for applications that need the best possible performance, such as machine learning workloads, microservices, and cloud-native applications, where efficiency and scalability are crucial.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tiered Compilation: The Best of Both Worlds
&lt;/h3&gt;

&lt;p&gt;The JVM uses a scheme called &lt;strong&gt;"Tiered Compilation"&lt;/strong&gt;, which combines the benefits of the fast C1 compiler and the optimized C2 compiler.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Level 0&lt;/strong&gt;: Code is 100% interpreted, with no compilation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 1 (C1 without optimizations)&lt;/strong&gt;: Code starts being compiled quickly to improve initial performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 2 (C1 with execution profiles)&lt;/strong&gt;: The JVM begins collecting data about how the code is being used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Level 3 (C2 optimized)&lt;/strong&gt;: Critical parts of the code are recompiled with aggressive optimizations for maximum efficiency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this scheme, the JVM can give a &lt;strong&gt;quick response time without sacrificing long-term performance&lt;/strong&gt;. This is especially useful for applications that need to respond quickly but also run for a long time.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Advanced JVM Optimizations
&lt;/h2&gt;

&lt;p&gt;The JVM doesn't just compile code in real-time; it also performs optimizations such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inlining&lt;/strong&gt;: If a method is small and called often, the JVM can copy it directly to the place where it's invoked, eliminating the cost of the method call.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Escape Analysis&lt;/strong&gt;: If the JVM sees that an object never leaves a method's scope, it can allocate it on the stack instead of the heap, improving performance and reducing the Garbage Collector's workload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dead Code Elimination&lt;/strong&gt;: If a piece of code is never executed, the JVM simply removes it from the compiled version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Loop Unrolling&lt;/strong&gt;: Instead of running a loop multiple times, the JVM can transform a short loop into a sequence of direct operations, reducing the number of condition checks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branch Prediction Optimization&lt;/strong&gt;: The JVM reorganizes code to better align with the processor's flow prediction, reducing penalties for branch prediction failures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These optimizations make the JVM seem like magic, turning readable code into something highly efficient without the programmer needing to lift a finger. Pretty impressive, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As you can see, the JVM is much more than just a runtime environment for Java. It has an extremely sophisticated optimization process. From interpreting bytecode to Just-In-Time compilation and advanced optimizations, the JVM is constantly working to ensure that your code runs as efficiently as possible.&lt;/p&gt;

&lt;p&gt;So, the next time someone says "Java is slow," you can just smile and reply, "The JVM is a performance machine, and those who understand how it works know how to make the most of it." 🚀&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to the Spring Framework: What It Is, Difference from Spring Boot, and Its Main Modules</title>
      <dc:creator>Felipe Azevedo</dc:creator>
      <pubDate>Mon, 03 Feb 2025 14:25:58 +0000</pubDate>
      <link>https://dev.to/felipeazsantos/introduction-to-the-spring-framework-what-it-is-difference-from-spring-boot-and-its-main-modules-2fc</link>
      <guid>https://dev.to/felipeazsantos/introduction-to-the-spring-framework-what-it-is-difference-from-spring-boot-and-its-main-modules-2fc</guid>
      <description>&lt;p&gt;The &lt;strong&gt;Spring Framework&lt;/strong&gt; is one of the most popular platforms for Java application development. It provides a comprehensive infrastructure for building robust, scalable, and modular systems. Over the years, it has become a de facto standard in the corporate Java ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is the Spring Framework?
&lt;/h2&gt;

&lt;p&gt;The Spring Framework is an open-source application framework for Java that supports development based on dependency injection, aspect-oriented programming, and an extensible set of modules for various software development needs.&lt;/p&gt;

&lt;p&gt;Its main benefits include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Injection (DI)&lt;/strong&gt;: Reduces coupling between components, making the code more testable and flexible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Aspect-Oriented Programming (AOP)&lt;/strong&gt;: Enables separation of concerns, such as logging and security, without impacting the core logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transaction Support&lt;/strong&gt;: Simplifies transaction management in Java applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration with Various Technologies&lt;/strong&gt;: Can be used with JDBC, JPA, Hibernate, JMS, REST, and more.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Difference Between Spring Framework and Spring Boot
&lt;/h2&gt;

&lt;p&gt;Although often confused, &lt;strong&gt;Spring Framework&lt;/strong&gt; and &lt;strong&gt;Spring Boot&lt;/strong&gt; are different concepts within the Spring ecosystem.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Spring Framework&lt;/th&gt;
&lt;th&gt;Spring Boot&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Configuration&lt;/td&gt;
&lt;td&gt;Requires manual configuration (XML or Java)&lt;/td&gt;
&lt;td&gt;Automatic configuration&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Application Startup&lt;/td&gt;
&lt;td&gt;Slower due to manual setup&lt;/td&gt;
&lt;td&gt;Fast with "convention over configuration"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dependencies&lt;/td&gt;
&lt;td&gt;Requires manual dependency management&lt;/td&gt;
&lt;td&gt;Automatically manages dependencies via "starters"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Web Container&lt;/td&gt;
&lt;td&gt;Can use servers like Tomcat, Jetty, or Undertow&lt;/td&gt;
&lt;td&gt;Embeds a web server for easier execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ideal Use Case&lt;/td&gt;
&lt;td&gt;Complex enterprise applications&lt;/td&gt;
&lt;td&gt;Microservices and standalone applications&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Spring Boot&lt;/strong&gt; is an extension of the Spring Framework that simplifies development, reducing the need for manual configuration and enabling faster development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Main Modules of the Spring Framework
&lt;/h2&gt;

&lt;p&gt;The Spring Framework consists of various modules that provide specific functionalities. The main ones include:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Spring Core
&lt;/h3&gt;

&lt;p&gt;The fundamental module of Spring, which includes &lt;strong&gt;Dependency Injection&lt;/strong&gt; and the &lt;strong&gt;IoC (Inversion of Control) container&lt;/strong&gt;. It allows the creation of loosely coupled applications by providing a managed lifecycle for components. IoC enables objects to be created and managed automatically by the framework, eliminating the need to manually instantiate dependencies, which improves maintainability and testability. This module addresses the problem of high coupling between classes, making the system more flexible and modular.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Spring AOP (Aspect-Oriented Programming)
&lt;/h3&gt;

&lt;p&gt;Provides support for aspect-oriented programming, allowing the addition of cross-cutting concerns such as logging, security, and monitoring without modifying the core business logic. This helps in separating concerns and improves software maintainability. Spring AOP solves problems like repetitive code across multiple system areas (e.g., transaction control and auditing), ensuring a cleaner and more modular implementation.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Spring Data
&lt;/h3&gt;

&lt;p&gt;Simplifies database access by providing integration with technologies such as JDBC, JPA, and Hibernate. &lt;strong&gt;Spring Data JPA&lt;/strong&gt;, for example, eliminates the need to write manual SQL queries, enabling the automatic creation of repositories based on interfaces. It addresses challenges such as managing database connections and transactions while reducing boilerplate code in database interactions.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Spring Web
&lt;/h3&gt;

&lt;p&gt;Supports web application development, including &lt;strong&gt;Spring MVC&lt;/strong&gt;, a powerful framework based on the Model-View-Controller pattern. It enables the creation of REST APIs and dynamic web applications with ease. Spring Web solves challenges like HTTP request routing, data serialization/deserialization, and integration with frontend libraries, facilitating the development of robust and scalable applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Spring Security
&lt;/h3&gt;

&lt;p&gt;Responsible for providing authentication and authorization mechanisms for applications. It integrates with OAuth2, JWT, and databases for secure access control. Allows customization of security rules using annotations and custom filters. Spring Security solves issues such as common vulnerabilities (e.g., SQL injection, CSRF, brute force attacks), ensuring a high level of protection without requiring developers to manually implement all security details.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Spring Batch
&lt;/h3&gt;

&lt;p&gt;Used for batch processing of large volumes of data, such as file imports and scheduled task execution. It manages execution flows, transactions, and failure recovery. Spring Batch solves problems related to handling large processing loads, scalability, and failure recovery, ensuring that complex tasks are executed efficiently and reliably.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Spring Cloud
&lt;/h3&gt;

&lt;p&gt;A set of tools for developing distributed systems and microservices, including configuration management, service discovery, load balancing, and resilience with circuit breakers. Spring Cloud solves problems such as managing configurations across multiple services, efficient communication between microservices, and fault tolerance in distributed systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Spring Integration
&lt;/h3&gt;

&lt;p&gt;Facilitates application integration through messaging and events, providing support for queues, pub-sub, and other distributed architectures like Apache Kafka and RabbitMQ. Spring Integration addresses challenges like asynchronous communication between services, decoupling systems, and scalability in high-performance environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Spring Boot (Framework Extension)
&lt;/h3&gt;

&lt;p&gt;Although not a module of the Spring Framework, &lt;strong&gt;Spring Boot&lt;/strong&gt; is an evolution that makes development faster by providing default configurations and embedded servers. Spring Boot solves problems such as the complexity of manual Spring configuration, simplifying development and allowing developers to focus on business logic rather than infrastructure details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Spring Framework&lt;/strong&gt; remains one of the top choices for Java application development, offering flexibility and productivity. With its modular architecture, developers can select only the components necessary for their projects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spring Boot&lt;/strong&gt;, in turn, facilitates Spring adoption by reducing configuration complexity and enabling fast startup.&lt;/p&gt;

&lt;p&gt;Whether developing large corporate systems or lightweight microservices, the Spring Framework offers powerful tools to meet diverse market demands.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
