<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Eduardo Berton on Medium]]></title>
        <description><![CDATA[Stories by Eduardo Berton on Medium]]></description>
        <link>https://medium.com/@duberton?source=rss-c86082245f13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*y0-FKx-AOcah2t4BFKJP8w.png</url>
            <title>Stories by Eduardo Berton on Medium</title>
            <link>https://medium.com/@duberton?source=rss-c86082245f13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 03:39:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@duberton/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a complete AWS back-end environment: a step-by-step guide covering API Gateway, VPC, ECS…]]></title>
            <link>https://medium.com/@duberton/building-a-complete-aws-back-end-environment-a-step-by-step-guide-covering-api-gateway-vpc-ecs-5bf881708612?source=rss-c86082245f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bf881708612</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[back-end-development]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[api-gateway]]></category>
            <dc:creator><![CDATA[Eduardo Berton]]></dc:creator>
            <pubDate>Sat, 11 Nov 2023 11:51:01 GMT</pubDate>
            <atom:updated>2023-11-14T19:34:05.500Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Building a complete AWS back-end environment: a step-by-step guide covering API Gateway, VPC, ECS Fargate and RDS</strong></h3><p>With its cutting-edge cloud-based services, AWS stands at the forefront of innovation, offering a comprehensive suite that can dramatically simplify the process of developing and deploying back-end APIs. In this publication, we’ll take a practical approach, demonstrating how to expose an API through an API Gateway, safeguard it within a VPC, orchestrate it on an ECS service, and ultimately store its data in an RDS database. As we conclude the publication we’re going to see a fully functional application ready to process incoming requests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EKaBvdzvGB25bSFw" /><figcaption>Photo by <a href="https://unsplash.com/@quinoal?utm_source=medium&amp;utm_medium=referral">Quino Al</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Table of contents</h3><ol><li>What you will learn</li><li>Base project</li><li>Prerequisites</li><li>Resource creation sequence</li><li>Hands-on</li></ol><ul><li>5.1. Bootstrap resources</li><li>5.2. VPC</li><li>5.3. Network Load Balancer</li><li>5.4. ECS</li><li>5.5. RDS</li><li>5.6. API Gateway from an API Specification</li><li>5.7. Testing the API Gateway &amp; application</li></ul><p>6. Summary</p><h3>1. What you will learn</h3><p>This publication is designed to offer a practical, hands-on experience by delving into a few select AWS services and their underlying components. The write-up will guide you through an exploration of the specifications of these AWS services, accompanied by sample Terraform code. A brief overview of each of the core resources we are going to cover:</p><ul><li>VPC: logical network isolation for AWS resources.</li><li>RDS: AWS managed service for relational databases. Handles the complexities of provisioning, maintenance and scaling of a database.</li><li>ECS Fargate: serverless compute engine. Abstracts resource provisioning, facilitating the deployment of containerized applications.</li><li>Load Balancer: a service that evenly distributes traffic across multiple application instances.</li><li>API Gateway: service for API management. It offers features like authentication, monitoring, rate limiting, scalability and so on.</li></ul><p>Ultimately, all the AWS resources referenced above will expose a back-end API, developed with Kotlin using the Spring framework. It’s worth noting that a detailed, step-by-step guide for creating the back-end API code itself is not provided. The existing code for the API is simply means to an end, which is the successful deployment of the AWS resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TliU6IevzH_pwmPiTw-w6A.png" /></figure><h4>If a TL;DR to the step-by-step command execution is what you’re after, refer to the following link: <a href="https://github.com/duberton/aws-api-gateway-vpc-ecs-rds">https://github.com/duberton/aws-api-gateway-vpc-ecs-rds</a>. The README file is what you’re looking for.</h4><h3>2. Base project</h3><p>The base project utilized for all the experimentation can be visualized and git cloned over here: <a href="https://github.com/duberton/aws-api-gateway-vpc-ecs-rds">https://github.com/duberton/aws-api-gateway-vpc-ecs-rds</a></p><p>Directory structure overview:</p><pre>- infrastructure: Terraform code<br>  - bootstrap: ECR, IAM, Secrets Manager<br>  - db: RDS<br>  - app: NLB, ECS<br>  - gateway: API Gateway<br>- openapi: OpenAPI specification<br>- src: Kotlin&#39;s API code</pre><h3>3. Prerequisites</h3><ul><li><strong>A AWS account: </strong>while using a root account may present security issues, it makes up for the setbacks of fine-tuning IAM users/roles for specific resources. If you choose to move forward with a root account, it’s highly advisable to configure an MFA method.</li><li><strong>AWS CLI:</strong> To configure the CLI, run <em>aws configure. </em>It prompts to enter the access key and secret key as well as both default region and default output.</li><li><strong>Terraform</strong></li><li><strong>Docker</strong></li><li><strong>Git</strong></li></ul><h3>4. Resource creation sequence</h3><p>Creation sequence reasoning:</p><ol><li><strong>VPC:</strong> foundational network isolation component. Forms the network infrastructure needed for the following resources</li><li><strong>RDS:</strong> requires a VPC and serves as the data store for the application</li><li><strong>Load Balancer:</strong> requires a VPC and routes traffic to the ECS service and provides a DNS for the API Gateway VPC Link.</li><li><strong>ECS: </strong>demands a Load Balancer and the RDS endpoint. Provides computational capacity to the application</li><li><strong>API Gateway:</strong> requires a LB DNS and acts as the public internet facing resource</li></ol><h3>5. Hands-on</h3><p><strong><em>To gain a thorough understanding of the hands-on section, you should consult both the README file and this publication simultaneously: </em></strong><a href="https://github.com/duberton/aws-api-gateway-vpc-ecs-rds/blob/main/README.md"><strong><em>https://github.com/duberton/aws-api-gateway-vpc-ecs-rds/blob/main/README.md</em></strong></a></p><h4>5.1. Bootstrap resources</h4><p>Before proceeding to the core resources, it’s essential to have a few foundational resources, such as a container registry and identity/role, all set up. These include:</p><ul><li><strong>ECR: </strong>a container registry so we can push the back-end API application image</li><li><strong>IAM: </strong>to ensure successful API interactions with other AWS services, access permissions must be granted to both the ECS agent (execution role) and ECS containers (task role).</li><li><strong>Secrets Manager: </strong>to have a secure and centralized repository for storing secrets such as credentials and API Keys</li></ul><p><em>Link to the code that creates the resources above: </em><a href="https://github.com/duberton/aws-api-gateway-hands-on/tree/main/infrastructure/bootstrap/modules/common"><em>https://github.com/duberton/aws-api-gateway-hands-on/tree/main/infrastructure/bootstrap/modules/common</em></a></p><h4>5.2. VPC</h4><p>Moving to the first core resource: the VPC. We’ll leverage a VPC Terraform module that not only creates a VPC but also abstracts the creation of a set of inner components. We’ll delve into the details of most of them shortly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9df07202aac26d447e0373fea271e556/href">https://medium.com/media/9df07202aac26d447e0373fea271e556/href</a></iframe><p>Do not underestimate the succinct nature of the 15 lines of code presented above. They have the capacity to yield a substantial number of implicit resources within your AWS Console:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e2908f1349c79bdb7f394cc294d3022/href">https://medium.com/media/0e2908f1349c79bdb7f394cc294d3022/href</a></iframe><p>Back to the VPC creation resource: it features a CIDR block of 10.99.0.0/24, allocating 256 possible host addresses. Also, it creates multiple other resources:</p><ul><li><strong>Internet Gateway:</strong> resources that need to reach public internet do so via an Internet Gateway.</li><li><strong>Public subnets:</strong> provisioned in 3 different AZs, each one having a CIDR block prefix of /28, thus, supporting up to 14 usable IPs. <strong><em>A public subnet is determined by having an association with an Internet Gateway. The Internet Gateway acts as the bridge between the VPC and the public internet. This association is achieved by a resource called Route Table.</em></strong></li><li><strong>NAT Gateway:</strong> NAT Gateway is primarily used for enabling outbound internet connectivity for instances in private subnets while preventing incoming traffic initiated from the Internet from reaching those instances.</li><li><strong>Private subnets:</strong> provisioned in 3 different AZs, each one having a CIDR block prefix of /28, thus, supporting 14 usable IPs. <strong><em>A private subnet lacks direct inbound internet connectivity. That is achieved by linking such subnets to a route table that routes to a Network Address Translation Gateway (NAT Gateway)</em>.</strong></li><li><strong>Elastic IP:</strong> Elastic IP is responsible to allocate a public static IP. It is usually allocated to a NAT Gateway so private resources can benefit from a consistent and predictable source IP when reaching a target destination on the public internet.</li><li><strong>Route Table: </strong>the route table is instrumental in directing traffic within a subnet. When a subnet is associated to a route with the target set as an Internet Gateway, it becomes a public subnet. Conversely, a private subnet is identified by its association with a route targeting a NAT Gateway.</li></ul><h4>5.3. RDS</h4><p>With a VPC in place, it’s time to address data storage. That’s where a RDS database comes into play. In this scenario, we’ll create a RDS PostgreSQL instance by utilizing another concise Terraform module to create such resource.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9e4d453c40efc9b06fc6446f1499963/href">https://medium.com/media/b9e4d453c40efc9b06fc6446f1499963/href</a></iframe><p>Certain fields are rather self-explanatory, such as identifiers, credentials, engine information, instance size, storage, snapshots and so on. Moving beyond these, let’s delve into some of the more critical aspects:</p><ul><li><strong>Security group: </strong>strict inbound SG that only allows direct traffic to come from the application itself, that is, the ECS Security Group.</li><li><strong>Subnet IDs: </strong>Not a public accessible RDS instance so it gets the private subnet IDs.</li><li><strong>Parameter groups:</strong> allows the configuration of fine-tuning settings like memory, number of connections, logging level and so forth. In this case, no custom parameter group.</li><li><strong>Option groups: </strong>configures additional features for the database engine like audit events, statistics, extensions and etc.</li></ul><h4>5.4. Network Load Balancer</h4><p>Next, we’ll enhance application availability by setting up an Load Balancer. A Network Load Balancer is specifically chosen for its seamless integration with the API Gateway REST API VPC Link functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fd260b83e471c6e9a696eda6719965d/href">https://medium.com/media/5fd260b83e471c6e9a696eda6719965d/href</a></iframe><p>Again, employing a succinct Terraform module that consolidates the creation of various crucial resources into a single one:</p><ul><li><strong>NLB</strong></li><li><strong>Target Group</strong></li><li><strong>Load Balancer Listener</strong></li></ul><p>As a load balancer operates within the context of a VPC, we create the linkage connecting it to the VPC, its private subnets (consistent to its internal type), and a security group. The security group follows strict inbound and outbound rules by only allowing ingress traffic to come from and to the port 80 which is the port that the LB listens on and forwards to. Despite the LB listening on port 80, incoming requests will come through the API Gateway HTTPS protocol, where SSL termination occurs. Following this, the API Gateway forwards the requests to the designated backend endpoint (the NLB) over the VPC Link, utilizing the HTTP port.</p><p>The target group takes care of configuring how a LB, given a http listener, will hit the application instances. This includes specifying the protocol, container port, target type (e.g., ‘ip’ exclusively for ECS Fargate), and health check settings.</p><h4>5.5. ECS</h4><p>Amazon ECS with Fargate is a service that simplifies deploying and managing containers with no underlying infrastructure. So, first, we create a 100% Fargate capacity provider cluster:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94e5ec5e427287126567098c90c8af86/href">https://medium.com/media/94e5ec5e427287126567098c90c8af86/href</a></iframe><p>Then we map out a ECS service. The service is a component that takes cares of accommodating tasks. We’ll get into a detailed overview below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05584831ae2cda55e7ba1626cfaaf07b/href">https://medium.com/media/05584831ae2cda55e7ba1626cfaaf07b/href</a></iframe><ul><li><strong>Cluster:</strong> reference to the cluster resource created above</li><li><strong>Task definition:</strong> reference to the task definition (which will be created in the next section)</li><li><strong>Desired count:</strong> number of replicas of the task</li><li><strong>Capacity provider strategy:</strong> specifies the provider strategy compute resources that the tasks will run on</li><li><strong>Network configuration:</strong> Sets the subnets as well as the security group<br> — Here we again see a strict set of ingress/egress rules<br> — Ingress allowing exclusively port 8080, the container port<br> — Egress tailored to allow communication with the RDS port database private subnets. Additionally, we enable access to a default CIDR block on ports https/http due to internet connectivity demands for services like secret manager, which we reach via a public endpoint</li><li><strong>Deployment maximum and minimum percent strategy:<br> — </strong>Given a desired count of tasks, the minimum percent amount of existing tasks, that, during a deployment, should be running<br> — Given a desired count of tasks, the maximum percent amount of tasks, that during a deployment, the service can go up to<br> — For instance, defining a minimum of 50% and a maximum of 200% with a desired count of 8. During a deployment, it would keep at least 4 existing tasks up and up to 16 tasks in total (both existing and new tasks)</li><li><strong>Load balancer target group: </strong>The load balancer target group that will be in front of the service</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a04899a9caa524a6b62f6c4d4dec860f/href">https://medium.com/media/a04899a9caa524a6b62f6c4d4dec860f/href</a></iframe><p>Now, the task definition not only specifies the containers to be executed but also outlines the configuration for these containers within an ECS task.</p><ul><li><strong>Container definitions</strong> represent an array of containers, enabling the configuration of a task with one or more containers.</li><li><strong>Image:</strong> points to the <em>repository/image:tag</em> of the container image</li><li><strong>Environment:</strong> plain text environment variables key-value pairs suitable for non-sensitive data</li><li><strong>Secrets:</strong> secure access to sensitive data such as secrets stored in secure services like Secrets Manager or System Manager Parameter Store while still maintaining the data unrevealed and secure. Exposes the key as an environment variable to the container.</li><li><strong>Essential:</strong> Boolean value that defines whether or not the container is essential. If the task is composed of more than a single container and a essential container fails a health check probe then the rest of the non-essential containers are stopped</li><li><strong>Port mappings:</strong> defines the port that the container exposes</li><li><strong>Log configurations:</strong> determines the place where logs are stored, in our case, <em>awslogs</em> translates to a CloudWatch log group</li><li><strong>Execution role:</strong> it is a configuration that dictates the policies attached to the role that the ECS agent will adhere to during task execution, for example, the permission to pull a image from ECR or to create a log group.</li><li><strong>Task role:</strong> configures the role that will contain the policies that grant permissions to the execution of the container itself. So, lets say your application communicates with DynamoDB, this is the role that accommodates such policies.</li><li><em>At the root level </em>of the task definition, CPU and memory settings dictate the overall resources allocated for the entire task, encompassing all its containers. In contrast, at the container definition level, these parameters specify the resources allocated to each individual container within the task.</li></ul><h4>5.6. API Gateway</h4><p>So, the time has come to create the API Gateway responsible for exposing the back-end application. This task will require five key resources, which we’ll delve into in more detail below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/579c3e7439e534600be83a774511cd99/href">https://medium.com/media/579c3e7439e534600be83a774511cd99/href</a></iframe><p>This serves as the primary top-level component to which all other components are attached to. In this instance, our API specification is defined in a YAML file, which is then rendered into the body and forms the API specs itself within the resource.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7be4af0b99cc482ee4c625d83c023be4/href">https://medium.com/media/7be4af0b99cc482ee4c625d83c023be4/href</a></iframe><p>Component that performs the deployment of the API. References the REST API.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c83864b19ff73954524958487b94884/href">https://medium.com/media/0c83864b19ff73954524958487b94884/href</a></iframe><p>Enables the creation of API stages. Tied to a deployment resource and typically associated with a specific application environment or stage within the application’s lifecycle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db3fb1ffe3cd7cef3878db8d9e3a55ee/href">https://medium.com/media/db3fb1ffe3cd7cef3878db8d9e3a55ee/href</a></iframe><p>References the OpenAPI specification file, which serves as the blueprint for defining routes, methods, schemas and various other components within the API Gateway configuration. Furthermore, variables are dynamically passed to the template file setting the previously created NLB DNS and the VPC Link ID.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aa44d4b61143c547840278a126af3fac/href">https://medium.com/media/aa44d4b61143c547840278a126af3fac/href</a></iframe><p>The VPC Link plays an important role in enabling the API Gateway to route incoming requests to the NLB.</p><p>So that’s it. The resource creation process has been successfully completed.</p><h4>5.7. Testing the API Gateway &amp; application</h4><p>Now, lets test the whole environment created.</p><p>The base project repository includes a folder named ‘postman,’ housing a collection that allows us to immediately test the back-end API. Import it to Postman.</p><p>Open up the AWS Console and go to the API Gateway service, specifically to the ‘Stages’ to grab the DNS generated for our API:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8cW7P4Awljsnr82x13WnA.png" /></figure><figure><img alt="View of the Resources section" src="https://cdn-images-1.medium.com/max/572/1*QBJqBRsdZxRwedwRRaqlPA.png" /></figure><p>Here we see the DNS that can be used to invoke the API. By putting it into Postman and performing calls on the 4 available routes we’re able to see it fully working.</p><h3>6. Summary</h3><p>In a nutshell, we took a closer look at AWS VPC, RDS, ECS, and API Gateway to understand some of the nitty-gritty details. This helped us build a backend setup for applications from start to finish. By paying attention to the specific features of each service, this guide gives you the know-how to create a really good backend setup on AWS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bf881708612" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java 14 major features — A brief guide]]></title>
            <link>https://medium.com/@duberton/java-14-major-features-a-brief-guide-e0608f845d82?source=rss-c86082245f13------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0608f845d82</guid>
            <category><![CDATA[java-14]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[jdk-14]]></category>
            <category><![CDATA[releases]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Eduardo Berton]]></dc:creator>
            <pubDate>Sun, 29 Mar 2020 15:17:36 GMT</pubDate>
            <atom:updated>2020-04-04T13:00:52.316Z</atom:updated>
            <content:encoded><![CDATA[<h3>Java 14 major features — A brief guide</h3><p><strong>Java</strong> has come a long way since it’s inception 24 years ago. It’s almost reaching version 15. Considering the current release cycle (a release every 6 months), Java 15 should be available for every developer by mid-September of 2020. But, let’s put the future aside for now and let’s focus on what’s already available in front of us: <strong>Java 14.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ot4byZYX36QAhFLW" /><figcaption>Photo by <a href="https://unsplash.com/@picoftasty?utm_source=medium&amp;utm_medium=referral">Mae Mu</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Java Development Kit </strong>got a new release under its belt a few days ago. <strong>Java 14</strong> was officially released on March 17 of 2020. Several interesting features were added, thus, making it a must-see to all the Java developers around the globe.</p><p>In this article, we’re gonna expose the new features by giving a brief description accompanied by code snippets. It is by no means an in-depth technical analysis of every feature that has been released with Java 14. If you’re looking for that, I’d suggest you do some research in the JDK Enhancement Proposals (JEP’s) documents. Having said that, these are the features that are going to be covered:</p><ul><li>Record classes (preview)</li><li>Text blocks (preview)</li><li>Pattern matching for instanceof (preview)</li><li>Switch expressions</li><li>Enhancements during a NullPointerException logging stack</li><li>Packaging tool (incubator)</li></ul><h4>GitHub repository</h4><p>The code samples used throughout this article are available at:</p><pre><a href="https://github.com/duberton/java-14-major-features">https://github.com/duberton/java-14-major-features</a></pre><h4>Java SE Development Kit 14</h4><p>OS-specific JDK14 packages can be found to be downloaded at:</p><pre><a href="https://www.oracle.com/java/technologies/javase-jdk14-downloads.html">https://www.oracle.com/java/technologies/javase-jdk14-downloads.html</a></pre><h4>Enabling preview features during runtime</h4><p>To get all the features marked with the <strong>preview</strong> flag working, it’s mandatory to tell that to the JVM by passing the following argument: — enable-preview. In case you’re executing the code within IntelliJ, it already sets that up.</p><h3>1. Record classes</h3><p>A Record class is Java’s answer to <a href="https://kotlinlang.org/docs/reference/data-classes.html">Kotlin’s data class</a>. The main motivation behind it is to give a solution for all those moments where developers end up spending unpleasant times writing classes whose single responsibility is to pass data/state on to other classes. So, let’s showcase both the declaration and the usage of such class:</p><p><strong>Declaration:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1c9f80e2d8efd11a345d36664361b79/href">https://medium.com/media/a1c9f80e2d8efd11a345d36664361b79/href</a></iframe><p><strong>Usage:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a921b3d3bd3eebffd0838b57a792fcd/href">https://medium.com/media/1a921b3d3bd3eebffd0838b57a792fcd/href</a></iframe><p>During the declaration of a record class we get for free the following items:</p><ul><li>Immutable private fields for every Object/primitive that has been declared</li><li>Getters</li><li>A public constructor with a signature that matches the fields declared in the record class</li><li>equals, hashCode: where a record is equal to another if they are of the same type and have the same declared state</li><li>toString: a toString() that includes every field that has been declared in the state description</li></ul><p>It also comes with the following specifications:</p><ul><li>It can’t extend a class or be extended</li><li>It’s not possible to declare new instance fields within the body</li><li>It can’t be abstract</li><li>It allows static fields and instance methods</li><li>It can implement interfaces</li><li>It can either be top-level or nested as well as generic</li></ul><h3>2. Text blocks (preview)</h3><p>Text blocks offer more clarity during multiline strings expressions. Java 13 gave birth to it and now Java 14 enhances it further. The following samples showcase some of the inner workings of Text blocks:</p><p><strong>Without text blocks:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a0af35db6b74671317383b32ad19fc6/href">https://medium.com/media/4a0af35db6b74671317383b32ad19fc6/href</a></iframe><p><strong>With text blocks:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/47159599fa2a30dfe13ab4b6a0ebb630/href">https://medium.com/media/47159599fa2a30dfe13ab4b6a0ebb630/href</a></iframe><p>As we can see, Text blocks are activated whenever there are three double quotes plus the addition of a line break. The same rule does not apply to the end of text blocks, though: you can put the three double quotes in the same line or a new line.</p><p>There might be a situation where the developer doesn’t want white spaces to be stripped after some trailing word and that’s when \s comes into play:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d66fe3c3e254eb53357a2f94e7a140a7/href">https://medium.com/media/d66fe3c3e254eb53357a2f94e7a140a7/href</a></iframe><h3>3. Pattern matching for instanceof (preview)</h3><p>Pattern matching permits a leaner usage of the instanceof operator:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54c2a232e90c088c18ddea0f643d1ded/href">https://medium.com/media/54c2a232e90c088c18ddea0f643d1ded/href</a></iframe><p>After the section that evaluates the predicate of the instance type, it binds the result to a new variable in the enclosing scope, therefore, eliminating the need to manually perform the cast, which is something that would have been done by the developers almost every single time.</p><p>Now, it’s worth addressing a scenario that may be seen as tricky around the binding of the variable — it only occurs when the condition has been evaluated as true:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a77f589e6a72a17c3f7105f83718bc8/href">https://medium.com/media/3a77f589e6a72a17c3f7105f83718bc8/href</a></iframe><h3>4. Switch expressions</h3><p>Both <strong>Java 12/13</strong> extended switch’s capabilities by introducing on it the ability to return expressions. This feature was initially in preview mode but now with the release of <strong>Java 14</strong>, it has become permanent.</p><p>So, let’s dive a little bit deeper into this new cool feature. Let’s start by saying it’s still possible to use either form: traditional switch <strong>label</strong>: or switch <strong>label -&gt; . </strong>With that said, let’s focus on some of its specifications:</p><ul><li>An expression declared in the <strong>switch</strong> <strong>label -&gt; </strong>evaluates to a single value and is promptly returned</li><li>switch expressions eliminates the need for break statements, therefore, there’s no fall-through while working with it. In fact, it’s not even allowed to put break statements within the block.</li><li>switch expressions allows multiple case labels in a single line, each one separated by a comma.</li><li>cases for switch expressions must be exhaustive, that is, there should be a case for every possible value that the type presents or a default clause should be in place to match the cases that won’t be covered</li><li>yield statements allow the case label to return an expression from a switch block</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52e24cb172ba8a6600ced82ab4d02d9b/href">https://medium.com/media/52e24cb172ba8a6600ced82ab4d02d9b/href</a></iframe><h3>5. Enhancements at NullPointerException logging stack trace</h3><p>Have you ever faced that infamous situation where a NullPointerException was thrown and the only thing you’ve got in the logs was the line number, then you jumped right into your IDE and pressed the ‘Go to line’ shortcut only to find out that the line has a long chain of calls where any of these calls could be pointing to a null reference? Of course, you have :P</p><p>Java 14 is here to help you unravel this kind of scenario faster than before by outputting more detailed information.</p><p><em>For now, it’s not enabled by default, so, there’s a flag to explicitly tell the JVM that you want this behavior, most likely due to the fact that it might end up affecting applications that rely on the parsing of stack traces:</em></p><pre>-XX:+ShowCodeDetailsInExceptionMessages</pre><p>Code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bde92207cd12839d96112b853c5d8fd/href">https://medium.com/media/4bde92207cd12839d96112b853c5d8fd/href</a></iframe><p>The output of the NPE:</p><pre>Exception in thread &quot;main&quot; java.lang.NullPointerException: Cannot invoke &quot;String.chars()&quot; because the return value of &quot;com.duberton.record.Member.name()&quot; is null<br> at com.duberton.npe.NullPointerLoggingEnhancement.lambda$main$0(NullPointerLoggingEnhancement.java:11)<br> at java.base/java.lang.Iterable.forEach(Iterable.java:75)<br> at com.duberton.npe.NullPointerLoggingEnhancement.main(NullPointerLoggingEnhancement.java:11)</pre><p>Cool, ham?</p><h3>6. Packaging tool (incubator)</h3><p><strong>incubator</strong> is a pretty handy command-line tool that comes with Java 14. It enables the developers to build platform-specific packages that are easily distributable.</p><p>Rather than pass jar files around with a bunch of instructions on how to execute it, the developer can just pass, let’s say, a.deb self-contained package file, making the job on the other end much easier.</p><p>Let’s exercise <strong>incubator</strong> in a <strong>Linux</strong> box a little bit. Go to the root directory of the project that was made available at the beginning of the article and then compile it with maven.</p><p>Building the application:</p><pre>mvn clean install</pre><p>Packaging the entire application in a single deb file:</p><pre>jpackage --name java-14-switch-expression --description &#39;Java 14 switch expression&#39;  --app-version 1.0 --input target/ --main-jar java-14-major-features-1.0-SNAPSHOT.jar --main-class com.duberton.switchexpression.SwitchExpression</pre><p>Installing it:</p><pre>sudo dpkg -i java-14-switch-expression_1.0-1_amd64.deb</pre><p>Installed location:</p><pre>/opt/java-14-switch-expression</pre><p>tree -L 3 output:</p><pre>.<br>├── bin<br>│   └── java-14-switch-expression<br>├── lib<br>│   ├── app<br>│   │   ├── classes<br>│   │   ├── java-14-major-features-1.0-SNAPSHOT.jar<br>│   │   ├── java-14-switch-expression.cfg<br>│   │   ├── maven-archiver<br>│   │   └── maven-status<br>│   ├── java-14-switch-expression.png<br>│   ├── libapplauncher.so<br>│   └── runtime<br>│       ├── conf<br>│       ├── legal<br>│       ├── lib<br>│       └── release<br>└── share<br>    └── doc<br>        └── copyright</pre><p>As we can see, lots of files. Amidst these bunch of files, the one that matters the most is the entry point to execute our application:./bin/java-14-switch-expression .</p><h3>Conclusion</h3><p>Java 14 brings a lot of great stuff into the table. I guess I haven’t been this excited about a Java release since Java 8.</p><p>From the reduction of boilerplate by introducing <strong>records</strong>, then the new <strong>switch expressions</strong> and the <strong>pattern matching</strong>, making the code way more idiomatic, until the ability to pack applications up and distribute them with ease with <strong>jpackage</strong>. These are all great additions.</p><p>I hope you enjoyed reading it as much as I enjoyed writing it! Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0608f845d82" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>