<?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: patricianicole</title>
    <description>The latest articles on DEV Community by patricianicole (@pat_the99).</description>
    <link>https://dev.to/pat_the99</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%2F628161%2F33eecef5-31e1-473f-9d4d-2afafb3c02e1.jpeg</url>
      <title>DEV Community: patricianicole</title>
      <link>https://dev.to/pat_the99</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pat_the99"/>
    <language>en</language>
    <item>
      <title>Introduction to Java Enterprise Edition</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Sun, 27 Mar 2022 03:35:03 +0000</pubDate>
      <link>https://dev.to/pat_the99/introduction-to-java-enterprise-edition-1ne2</link>
      <guid>https://dev.to/pat_the99/introduction-to-java-enterprise-edition-1ne2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Java Enterprise Edition (Java EE) is a collection of abstract specifications that together form a complete solution for commonly faced challenges during software development.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Words that are typically heard while studying Java EE includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Application Server&lt;/strong&gt; : It is a &lt;strong&gt;concrete&lt;/strong&gt; implementation of the Java EE abstract specifications. Examples include &lt;em&gt;Payara Server (Glassfish)&lt;/em&gt;, &lt;em&gt;IBM OpenLiberty&lt;/em&gt;, and &lt;em&gt;JBoss Wildfly&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Java Specification Request (JSR)&lt;/strong&gt; : It is a formal request to the Java community process for addition and enhancements to technologies. It is a body that standardizes APIs on the Java Technology platform and is used to group APIs into silos, e.g. JAX-RS (Java API for RESTful Web Services). For every JSR, there is always a default reference implementation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reference Implementation&lt;/strong&gt; : It is the concrete realization/implementation of an abstract JSR. For instance, the reference implementation for JAX-RS is called &lt;em&gt;Jersey&lt;/em&gt;. Java EE in itself is a JSR. Thus, an application server is a collection of the various reference implementations for the Java EE JSR. Java EE is JSR 366, and one of its reference implementation is Glassfish 5.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Jakarta EE&lt;/strong&gt; : It is Java EE going forward. Oracle moved the Java platform to be hosted by the &lt;a href="https://jakarta.ee" rel="noopener noreferrer"&gt;Eclipse Foundation&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Java EE Basics
&lt;/h2&gt;

&lt;p&gt;There are three key APIs in Java EE.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Java Persistence API (JPA) . It is responsible for storing and retrieving information from relational databases, which can be extended to handle NoSQL databases. It is the data layer of an application.&lt;/li&gt;
&lt;li&gt;Context and Dependency Injection (CDI API) . It is a standardized way to create highly decoupled applications. It manages various interactions of different components to allow loose decoupling. &lt;/li&gt;
&lt;li&gt;Java API for RESTful Web Services (JAX-RS) . It exposes resources over HTTP protocol as webservices.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Context and Dependency Injection API
&lt;/h3&gt;

&lt;p&gt;Dependency Injection is a specific form of inversion control (software strategy where individual components have their dependencies supplied to them). This externalizes dependency in the application to create loosely coupled components.&lt;/p&gt;

&lt;h4&gt;
  
  
  CDI Features
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Injection (Typesafe)&lt;/strong&gt; : Allows declaration of dependency on types, so that the compiler catches error during runtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lifecycle contexts&lt;/strong&gt; : The ability to bind the lifecycle and interaction of stateful components to well-defined but extensible lifecycle components.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interceptors&lt;/strong&gt; : This allows interception of requests to access a certain method.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Events&lt;/strong&gt; : A way to develop highly decoupled applications. Events can be fired while observers listen for the fired events. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Service Provider Interface (SPI)&lt;/strong&gt; : A set of hooks and API and interfaces that can be used as extensions, e.g. Apache libraries. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some concepts under the CDI API,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CDI Bean Discovery&lt;/strong&gt; : A mechanism where the dependency injection runtime analyzes and discovers beans for it to manage default bean discovery mode, i.e. beans that are annotated, e.g &lt;em&gt;@Annotated&lt;/em&gt;. There are three types of bean discovery mode, ALL (includes those beans that are not annotated), ANNOTATED, and NONE. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CDI Container&lt;/strong&gt; : A factory in which Java classes comes in and goes out with their functionality and features. It is an application that manages beans.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bean and Contextual Instance&lt;/strong&gt; : A bean is a template which a developer creates. A contextual instance is an instance of a bean created by the CDI container and is managed by it. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Java Persistence API
&lt;/h3&gt;

&lt;p&gt;JPA is used to map objects to relational database tables. The Java Persistence API meets the ORM manifesto tenets.&lt;/p&gt;

&lt;h4&gt;
  
  
  ORM Manifesto (Object Relational Mapping Manifesto)
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Objects not Tables&lt;/em&gt; : Developers write objects not table.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Convenience, Not Ignorance&lt;/em&gt; : An ORM should be convenient. Developers should at least have minimum knowledge on relational databases. ORM is not a way to mask ignorance but convenience.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Unobtrusive not transparent&lt;/em&gt; : An ORM should make it so that developers are able to control what is in the database and have complete control on what is being persisted.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Legacy Data, New Objects&lt;/em&gt; : Expect ORM to allow creation of new objects from legacy data, i.e. reverse engineer legacy database to Java objects.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Just Enough, not too much&lt;/em&gt; : Expect ORM to give us all the tools to solve generally encountered problems due to impedance mismatch (term used to refer to problems that occur due to difference between database model and programming language). An ORM should not be excessively heavy weight.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Local but mobile&lt;/em&gt; : The data is local but there should be an ability that enables the persistent state of the application to travel to different parts of the application.&lt;/li&gt;
&lt;li&gt; &lt;em&gt;Standard API, pluggable implementation&lt;/em&gt; : Rely on a standard API but can be swapped implementations if needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some important concepts under JPA,&lt;/p&gt;

&lt;h4&gt;
  
  
  JPA Entity
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The most unit component of JPA entities is a plain old java object (POJO). Every entity must have a unique identifier.&lt;/li&gt;
&lt;li&gt;There are commonly used annotations on JPA entities such as &lt;em&gt;@MappedSuperClass&lt;/em&gt; annotation which enables the use of superclasses containing the common fields of entities. &lt;em&gt;@AttributeOverride&lt;/em&gt; annotation is used to override entities od the superclass. &lt;em&gt;&lt;a class="mentioned-user" href="https://dev.to/column"&gt;@column&lt;/a&gt;&lt;/em&gt; is used to customize database mappings. &lt;em&gt;@Transient&lt;/em&gt; annotation can be used for fields in the entity class that should not be mapped to the database.&lt;/li&gt;
&lt;li&gt;Access type : The process by which the persistence provider accesses states in the entity. Field access happens when the provider accesses class fields directly through reflection. Property access happens when the java bean property methods are used to access states, i.e. use of getter and setter methods. To use property access, the getter method must be annotated with &lt;em&gt;@ Id&lt;/em&gt;. Mixed access type uses both field and property access in the same entity class using &lt;a class="mentioned-user" href="https://dev.to/access"&gt;@access&lt;/a&gt; annotation.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Java API for RESTful Web services
&lt;/h3&gt;

&lt;h4&gt;
  
  
  REST Architecture Constraints
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Client and server is independent of each other.&lt;/li&gt;
&lt;li&gt;Stateless : Every single request that comes to the server is a self-contained unique request. The server does not make any assumption from the previous request.&lt;/li&gt;
&lt;li&gt;Cacheable : The system should support caching at different levels to improve performance and scalability.&lt;/li&gt;
&lt;li&gt;Uniform Interface : Means that the client should have general uniform interface for accessing resources on the server and also for interacting with the resources on the server.&lt;/li&gt;
&lt;li&gt;Layered System : The server can be implemented in different layers in a way such that a client need not to worry about a layer system, e.g. a server that supports load balancing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some common concepts related to JAX-RS&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP GET method : A request for a resource or resources. A GET request method is idempotent, meaning that making the same request to a method over and over again should not and must not change the state of a resource or data on the server.&lt;/li&gt;
&lt;li&gt;HTTP POST method : A POST request is used to create new resources on the server. It causes a change on the dataset in the server. The POST normally has a body where payload or whatever we want to create on the server is posted or attached.&lt;/li&gt;
&lt;li&gt;HTTP PUT method : This is used semantically to update resources on the server.&lt;/li&gt;
&lt;li&gt;HTTP DELETE method : It is used to delete resources on the server.&lt;/li&gt;
&lt;li&gt;Content types: There are several content types that can be consumed and is produced by request methods, (1) XML, (2) CSV, (3) EXCEL (4) TEXT (5) JSON.&lt;/li&gt;
&lt;li&gt;JAX-RS has a concept of message body writer. They are API constructs used to convert the Java types to relevant type the client expects. &lt;em&gt;@Produces&lt;/em&gt; annotation can be used to specify the type to which the Java object response is converted. &lt;/li&gt;
&lt;li&gt;The &lt;em&gt;@Consumes&lt;/em&gt; annotation tells the JAX-RS runtime the type of content a given resource method consumes. The JAX-RS runtime will then convert the JSON content passed as a payload to a Java object of type similar to the method parameter.&lt;/li&gt;
&lt;li&gt;JAX-RS Exception Mapper : API construct used to map exceptions to HTTP responses. The &lt;em&gt;@ Provider&lt;/em&gt; annotation is used to register an exception mapper to the JAX-RS runtime programmatically. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is just a very basic introduction to Java EE. Each key API needs more delving to be able to create web application using Java EE.&lt;/p&gt;

&lt;p&gt;Thank you for reading!!&lt;/p&gt;

</description>
      <category>java</category>
      <category>javaee</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>My First Hacktoberfest : Feasting on issues for the badge</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Sun, 24 Oct 2021 14:51:06 +0000</pubDate>
      <link>https://dev.to/pat_the99/my-first-hacktoberfest-feasting-on-issues-for-the-badge-34i8</link>
      <guid>https://dev.to/pat_the99/my-first-hacktoberfest-feasting-on-issues-for-the-badge-34i8</guid>
      <description>&lt;p&gt;Hi I am Pat, and this year is my first &lt;code&gt;#hacktoberfest&lt;/code&gt;. From the title, I sound like a &lt;code&gt;#hacktoberfest&lt;/code&gt; villain, don't I?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SPOILER ALERT&lt;/em&gt;: I am not :).&lt;/p&gt;

&lt;p&gt;This year, I started getting active on github and the DEV community because of my learning goals. With that, I also learned about a lot of dev events, one of which, &lt;code&gt;#hacktoberfest&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I decided to enter out of curiosity, exploring a lot of projects with the &lt;code&gt;good first issue&lt;/code&gt; tag to get the hang of it. Finding issues was easy, the problem was, I got a bit late and almost all of them are dibbed/taken already. It was fine. The bad part was some contributors were commenting on threads, messaging the maintainers to accept the PRs. Sometimes requesting these maintainers to add the &lt;code&gt;#hacktoberfest&lt;/code&gt; tag for the request to be counted in their &lt;code&gt;#hacktoberfest&lt;/code&gt; participation tally.  It kind of feels off because it seems to me that the desire to contribute stemmed from the acquisition of a badge after the event and not the genuine desire of contributing to the open source community.&lt;/p&gt;

&lt;p&gt;I reflected on this first &lt;code&gt;#hacktoberfest&lt;/code&gt; experience and realized that if I want to successfully complete the event, I have to be actively exploring the open source community not just during October. Finding issues is very easy to do, but familiarizing with how an open source project work, reading the contributor guidelines carefully, setting up local development, analyzing the open issue, etc. take time. Completing issues that are not menial requires preparation.&lt;/p&gt;

&lt;p&gt;If I have one suggestion for myself next year, that is, explore fun/interesting open-source projects in advance, start contributing, familiarize with the contributor's guidelines and the open issues. And I feel like hacktoberfest will be completed in a breeze that way. &lt;/p&gt;

&lt;p&gt;I can say I failed my first &lt;code&gt;hacktoberfest&lt;/code&gt;, but I think the experience served me well.&lt;br&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%2Fzdzryupd767neemcu3nc.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%2Fzdzryupd767neemcu3nc.PNG" alt="Hacktoberfest profile" width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Happy hacking!
&lt;/h2&gt;

</description>
    </item>
    <item>
      <title>Java Interfaces</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Tue, 24 Aug 2021 01:26:46 +0000</pubDate>
      <link>https://dev.to/pat_the99/java-interfaces-306o</link>
      <guid>https://dev.to/pat_the99/java-interfaces-306o</guid>
      <description>&lt;h2&gt;
  
  
  📌 Interfaces in Java
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;An interface is a reference type, similar to a class that can contain &lt;strong&gt;only&lt;/strong&gt; constants, method signatures, default methods, static methods and nested types. &lt;/li&gt;
&lt;li&gt;Interfaces cannot be instantiated - they can only be implemented by classes and extended by other interfaces.&lt;/li&gt;
&lt;li&gt;Note that an interface can extend any number of interfaces. The interface declaration can include a comma-separated list of all the interfaces that it extends.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Interface Body
&lt;/h3&gt;

&lt;p&gt;The interface body can contain &lt;strong&gt;abstract methods, default methods and static methods&lt;/strong&gt;. All of these methods in an interface are &lt;strong&gt;implicitly&lt;/strong&gt; &lt;code&gt;public&lt;/code&gt;, &lt;code&gt;static&lt;/code&gt;, and &lt;code&gt;final&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Implementing an Interface
&lt;/h4&gt;

&lt;p&gt;A class can implement more than one interface. The &lt;code&gt;implements&lt;/code&gt; keyword is followed by a comma-separated list of the interfaces implemented by the class.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using an Interface as a Type
&lt;/h3&gt;

&lt;p&gt;When a new interface is defined, a new reference data type is defined. The interface names can be used anywhere a data type can be used. If a variable is assigned an interface type, any object assigned to it must be an instance of a class that implements the interface.&lt;/p&gt;

&lt;h3&gt;
  
  
  Evolving Interfaces
&lt;/h3&gt;

&lt;p&gt;To avoid the scenario where implementing classes need to change because of the additions to the implemented interface:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new interface that extends to the changed interface. In this way, implementing classes only need to change what interface to implement, whether the child or the parent. Now users of the code can choose to continue to use the old interface or to upgrade to the new interface.&lt;/li&gt;
&lt;li&gt;Alternatively, new methods can be defined as default methods. Since implementations are provided for default methods,  users who have classes that implement interfaces enhanced with default or static methods do not have to modify or recompile them to accomodate the additional methods.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Default Methods
&lt;/h3&gt;

&lt;p&gt;Default methods enable one to add new functionality to the interfaces of the library to ensure binary compatibility with code written for older versions of that interfaces.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A default method in an interface is defined with the &lt;code&gt;default&lt;/code&gt; keyword at the beginning of the method signature. All method declarations in an interface, including default methods are implicityly public so the &lt;code&gt;public&lt;/code&gt; modifier can be omitted.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Extending Interfaces that Contain Default Methods
&lt;/h4&gt;

&lt;p&gt;When an interface with a default method is extended, &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There is no need to mention the default method at all, which lets the extended interface inherit the default method&lt;/li&gt;
&lt;li&gt;The default method can be redeclared which makes it abstract&lt;/li&gt;
&lt;li&gt;The default method can be redefined by overriding it&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Static Methods
&lt;/h3&gt;

&lt;p&gt;A static method can also be defined in an interface. It is a method that is associated with the class in which it is defined rather than with any object. Every instance of the class shares its static methods. Now this helps in organizing helper methods.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integrating Default Methods into Existing Libraries
&lt;/h3&gt;

&lt;p&gt;Default methods enable the addition of new functionality to existing interfaces and ensure binary compatibilty with code written for older versions of those interfaces. In particular, default methods enable the addition of methods that accept lambda expressions as parameters to existing interfaces.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;An interface declaration can contain method signatures, default methods, static methods and constant definitions. The only methods that have implementations are default and static methods&lt;/li&gt;
&lt;li&gt;A class that implements an interface must implement all the mothods declared in the interface.&lt;/li&gt;
&lt;li&gt;An interface name can be used anywhere a type can be used.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cheers to continued learning 🍻!&lt;/p&gt;

&lt;h3&gt;
  
  
  RESOURCES
&lt;/h3&gt;

&lt;p&gt;[1] &lt;a href="https://docs.oracle.com/javase/tutorial/java/concepts/interface.html" rel="noopener noreferrer"&gt;Java Doc, What is an Interface&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>codenewbie</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Library Project 📖</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Tue, 17 Aug 2021 01:30:30 +0000</pubDate>
      <link>https://dev.to/pat_the99/library-project-54md</link>
      <guid>https://dev.to/pat_the99/library-project-54md</guid>
      <description>&lt;h4&gt;Entry for The Odin Project's library exercise under the full javascript path&lt;/h4&gt;

&lt;h5&gt;Live preview can be found &lt;a href="https://fatrixienicolieopetina.github.io/book-library/" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/h5&gt;

&lt;p&gt;One can add a book in the library with its title, author, a brief review of the book and a pseudo-name of who added the book. &lt;/p&gt; 

&lt;h2&gt;WIL/Thoughts 🤔&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt; 
    &lt;h3&gt;Firebase&lt;/h3&gt;
    &lt;p&gt;
      I was looking for a free online database and found firebase. The site allows user to add books and saves them in the firestore.
      It is similar to a mongo database, where for each project, there is a number of collections and for each collection, there are documents.
      In this project, I am saving each book as a document.
    &lt;/p&gt;
    &lt;p&gt;
       There are also a lot of ways in which firebase can be added in an application, one through CDN and another through npm/yarn.
       I opted to use CDN for this exercise. Why? I do not have any particular reason, to be honest, it felt more convenient 😆. 
    &lt;/p&gt;
    &lt;p&gt;I also checked the documentation to check how to connect my site to the project in the firebase, and that went well.&lt;/p&gt;
  &lt;/li&gt;
  
  &lt;li&gt; 
    &lt;h3&gt;TailWindCss&lt;/h3&gt;
    &lt;p&gt;
      I wanted to try some CSS frameworks outside from what I have already used like bootstrap and material. It does not feel different from the two. 
    &lt;/p&gt;
  &lt;/li&gt;
 
  &lt;li&gt; 
    &lt;h3&gt;JS Revealing Module Pattern (RMP)&lt;/h3&gt;
    &lt;p&gt;
      I tried this pattern to practice closures in JS. RMP defines functions in closure areas and only use variables on access. I think this is a nice way of doing encapsulation, without all the boiler plate of OOP languages. 
    &lt;/p&gt;
  &lt;/li&gt;
  
&lt;/ul&gt;

&lt;p&gt;This is the 3rd entry of the series. They are very simple, tweaked exercises for the refresher topics in &lt;a href="https://www.theodinproject.com/paths/full-stack-javascript" rel="noopener noreferrer"&gt;The Odin Project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Github repository of the project can be found &lt;a href="https://github.com/fatrixienicolieopetina/book-library/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As always, cheers to continued learning 🍻!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>To-Do List ✍️</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Tue, 10 Aug 2021 01:31:27 +0000</pubDate>
      <link>https://dev.to/pat_the99/to-do-list-16l4</link>
      <guid>https://dev.to/pat_the99/to-do-list-16l4</guid>
      <description>&lt;h4&gt;
  
  
  Live preview and can be found &lt;a href="https://fatrixienicolieopetina.github.io/todo-list/" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/h4&gt;

&lt;h3&gt;
  
  
  About 👨‍🏫
&lt;/h3&gt;

&lt;p&gt;The todo list have projects or separate lists of todos. When a user first opens the app, there is some sort of ‘default’ project called 'Home' to which all of the todos are put. Users can create new projects and choose which project their todos go into. &lt;strong&gt;localStorage&lt;/strong&gt; is used to save user’s projects and todos between sessions.&lt;/p&gt;

&lt;h3&gt;
  
  
  WIL/Thoughts 🤔
&lt;/h3&gt;

&lt;p&gt;Tried revisiting and reading about SOLID principles to properly write a maintable code. &lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Single Responsibility Principle&lt;/strong&gt; . Design classes/functions in a way that it is only doing ONE thing.&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Open/Closed Principle&lt;/strong&gt; - For me , this is very difficult to apply. You really have to think carefully about each class design, its associations, relationships etc.&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Liskov Substitution Principle&lt;/strong&gt; - It is like saying that a child can act as a proxy to the parent (my definition for simplicity 😆). I believe this is almost always enforced in OOP languages like Java.&lt;/p&gt;

&lt;p&gt;📌  &lt;strong&gt;Interface Segregation Principle&lt;/strong&gt; - In simple terms, interfaces should not force implementing classes to implement methods they do not need. That is why we have functional interfaces, interfaces with only one abstract method. This special type of interface enforces ISP.&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Dependency Inversion Principle&lt;/strong&gt; - At first, I had trouble understanding what the second rule of this principle meant.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;High-level modules should not depend on low-level modules.  Both should depend on abstractions. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is achievable by using constructs such as interfaces to facilitate loose coupling between modules. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Abstractions should not depend upon details.  Details should depend upon abstractions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I did not quite understand what it meant at first. After searching through the web, this 👇 is the best answer I found.&lt;/p&gt;

&lt;p&gt;🥇 &lt;em&gt;It means that if the details change they should not affect the abstraction. The abstraction is the way clients view an object. Exactly what goes on inside the object is not important. Lets take a car for example, the pedals and steering wheel and gear lever are abstractions of what happens inside the engine. They do not depend on the details though because if someone changes my old engine for a new one I should still be able to drive the car without knowing that the engine changed.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The details on the other hand MUST conform to what the abstraction says. I would not want to implement an engine that suddenly causes the brakes to double the speed of the car. I can re-implement brakes any way I want as long as externally they behave the same way.&lt;/p&gt;

&lt;p&gt;And those are my WIL(What I Learned) thoughts for a very, very simple to-do project.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Check out the code of the exercise in this &lt;a href="https://github.com/fatrixienicolieopetina/todo-list" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;em&gt;This project is taken from the &lt;a href="https://www.theodinproject.com/paths/full-stack-javascript/courses/javascript/lessons/todo-list" rel="noopener noreferrer"&gt;The Odin Project&lt;/a&gt; todo list exercise.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As always cheers to continued learning 🍷!&lt;/p&gt;

</description>
      <category>watercooler</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>What's the Weather? 🌦️</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Tue, 03 Aug 2021 01:01:23 +0000</pubDate>
      <link>https://dev.to/pat_the99/what-s-the-weather-1i</link>
      <guid>https://dev.to/pat_the99/what-s-the-weather-1i</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This is a JavaScript exercise I worked on under &lt;a href="https://www.theodinproject.com/paths/full-stack-javascript/courses/javascript/lessons/weather-app" rel="noopener noreferrer"&gt;The Odin Project&lt;/a&gt; to get familiar with the basics of promises, callbacks and a little about async/await. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The live preview of this assignment can be found &lt;a href="https://fatrixienicolieopetina.github.io/weather-app/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. It is a weather forecast site using a weather API. The look of the page can change based on the description of the weather. The &lt;a href="https://developers.giphy.com/docs/api/" rel="noopener noreferrer"&gt;Giphy API&lt;/a&gt; is used to find weather related gifs and display them. &lt;/p&gt;

&lt;h3&gt;
  
  
  WIL/Thoughts 🤔
&lt;/h3&gt;

&lt;p&gt;The most important thing I learned in this exercise is the basics of asynchronous JS, specifically callbacks and promises. I wrote my basic understanding of it in a different &lt;a href="https://dev.to/pat_the99/basics-of-callbacks-and-promises-in-javascript-4cj7"&gt;dev.to post&lt;/a&gt;. I also got acquainted with async and await but I am still to get comfortable of using these keywords.&lt;/p&gt;

&lt;p&gt;📌 async&lt;/p&gt;

&lt;p&gt;This tells the JS engine that the function is asynchronous. Functions with the &lt;code&gt;async&lt;/code&gt; keyword automatically returns a promise. It is said that async is just a syntactical sugar for promises 😆 . &lt;/p&gt;

&lt;p&gt;📌 await&lt;/p&gt;

&lt;p&gt;This keyword can only be used inside a function prefixed with &lt;code&gt;async&lt;/code&gt;. When used, it tells JS to wait for the value of the asynchronous function called. In promises, the &lt;code&gt;then&lt;/code&gt; method is called on the function object returning a promise. By using &lt;code&gt;await&lt;/code&gt;, you just need to assign the return object of an async function and treat the result just like any other variable.&lt;/p&gt;

&lt;p&gt;📌 Cross-Origin Resource Sharing&lt;/p&gt;

&lt;p&gt;When I tried working with the open-weather and giphy API, I encountered an error related to CORS. WIL was, browsers, by default do not allow HTTP requests to outside resources. Cross-origin requests are requests sent to another domain/protocol/port and they require special headers from the remote side. This is for security purposes. We would not want a script from a hacker site to access our twitter credentials (XD as to what I understood so far).  The CORS request header would contain an Origin. If the server accepts the request, a special header &lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt; would be added in the response. The response would also contain the allowed origin(the requester URL) or probably a star, denoting all. The CORS request also have two types, safe and unsafe. Safe requests can be sent on the fly while unsafe requests need some &lt;code&gt;"preflight"&lt;/code&gt; to check if the server permits the request.&lt;/p&gt;

&lt;p&gt;As always, cheers to lifelong learning 🍷.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>showdev</category>
      <category>watercooler</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>JavaScript Hoisting</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Tue, 27 Jul 2021 01:06:33 +0000</pubDate>
      <link>https://dev.to/pat_the99/javascript-hoisting-450l</link>
      <guid>https://dev.to/pat_the99/javascript-hoisting-450l</guid>
      <description>&lt;h2&gt;
  
  
  [JS#5 WIL 🤔 Post]
&lt;/h2&gt;

&lt;p&gt;JavaScript hoisting refers to the process where the compiler allocates memory for variable and function declarations &lt;strong&gt;prior&lt;/strong&gt; to execution of code [&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting" rel="noopener noreferrer"&gt;1&lt;/a&gt;]. That means that declarations are moved to the top of their scope before code execution regardless of whether its scope is global or local. &lt;/p&gt;

&lt;h3&gt;
  
  
  Table Of Contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Javascript Hoisting&lt;/li&gt;
&lt;li&gt;Javascript Context Execution: Creation and Execution Phase&lt;/li&gt;
&lt;li&gt;Default Values: &lt;code&gt;undefined&lt;/code&gt; and &lt;code&gt;ReferenceError&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; hoisting and Temporal Dead Zone (TDZ)&lt;/li&gt;
&lt;li&gt;Variable Hoisting&lt;/li&gt;
&lt;li&gt;Function Hoisting&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  📌 Javascript Hoisting &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Conceptually speaking, &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;hoisting is the compiler splitting variable declaration and initialization and moving only the declarations to the top of the code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Thus, variables can appear in code before they are even defined. However, the variable initialization will only happen until that line of code is executed.&lt;/p&gt;

&lt;p&gt;The code snippets below show hoisting in action. The first snippet shows how the code is expected to be written: &lt;strong&gt;declare the function first and use/invoke it after.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printIamHoisted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;printIamHoisted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Am I hoisted??&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the snippet below, the method is invoked first, and the function declaration is written next. However, both of them have the same output - they print the string &lt;code&gt;Am I hoisted?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;printIamHoisted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Am I hoisted?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printIamHoisted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&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;So even though the function is called before it is written, the code still works. This happens because of how context execution works in Javascript.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌 Javascript Context Execution &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;When a Javascript engine executes code, it creates execution context. Each context has two phases: &lt;strong&gt;creation&lt;/strong&gt; and &lt;strong&gt;execution&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  📌 Creation Phase
&lt;/h4&gt;

&lt;p&gt;When a script executes, the JS engine creates a &lt;strong&gt;Global Execution Context&lt;/strong&gt;. In this phase, it performs the following tasks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a global object &lt;code&gt;window&lt;/code&gt; in the web browser&lt;/li&gt;
&lt;li&gt;Create a &lt;code&gt;this&lt;/code&gt; object binding which pertains to the global object&lt;/li&gt;
&lt;li&gt;Setup memory for storing variables and function references&lt;/li&gt;
&lt;li&gt;Store the declarations in memory within the global execution context with &lt;code&gt;undefined&lt;/code&gt; initial value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lookin back at this snippet,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;printIamHoisted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am hoisted!!!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;printIamHoisted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str&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;the global execution context at this phase, would somehow look like this &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%2F4t3uitokcxtbs7qil5x8.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%2F4t3uitokcxtbs7qil5x8.png" alt="Creation Phase" width="333" height="401"&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  📌 Execution Phase
&lt;/h4&gt;

&lt;p&gt;At this phase, the JS engine executes the code line by line. But by virtue of hoisting, the function is declared regardless of line order, so there is no problem calling/invoking the method prior the declaration.&lt;/p&gt;

&lt;p&gt;For every function call, the JS engine creates a new &lt;strong&gt;Function Execution Context&lt;/strong&gt;. This context is similar to &lt;strong&gt;global execution context&lt;/strong&gt;, but instead of creating the global object, it creates the &lt;code&gt;arguments&lt;/code&gt; object that contains references to all the parameters passed to the function. The context during this phase would look somewhat like : &lt;br&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%2Fpx04iqhq9b2qtr72i4sl.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%2Fpx04iqhq9b2qtr72i4sl.png" alt="Execution Phase" width="331" height="595"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  📌 Only the declarations (function and variable) are hoisted
&lt;/h3&gt;

&lt;p&gt;JS only hoists declarations, &lt;strong&gt;not initializations&lt;/strong&gt;. If a variable is used but it is only declared and initialized after, the value when it is used will be the default value on initialization. &lt;/p&gt;
&lt;h4&gt;
  
  
  📌 Default Values: &lt;code&gt;undefined&lt;/code&gt; and &lt;code&gt;ReferenceError&lt;/code&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;For variables declared with the &lt;code&gt;var&lt;/code&gt; keyword, the default value would be &lt;code&gt;undefined&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hoistedVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Returns 'undefined' from hoisted var declaration (not 6)&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;hoistedVar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Declaration&lt;/span&gt;
&lt;span class="nx"&gt;hoistedVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Initialization&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Logging the &lt;code&gt;hoistedVar&lt;/code&gt; variable before it is initialized would print &lt;code&gt;undefined&lt;/code&gt;. If however, the declaration of the variable is removed, i.e.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;hoistedVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Throw ReferenceError Exception&lt;/span&gt;
&lt;span class="nx"&gt;hoistedVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Initialization&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;a &lt;code&gt;ReferenceError&lt;/code&gt; exception would be thrown because no hoisting happened.&lt;/p&gt;

&lt;h4&gt;
  
  
  📌 &lt;code&gt;let&lt;/code&gt; hoisting: Temporal Dead Zone (TDZ)&lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Variables declared with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are also hoisted. However, unlike variables declared with &lt;code&gt;var&lt;/code&gt;, they are not initialized to a default value of &lt;code&gt;undefined&lt;/code&gt;. Until the line in which they are initialized is executed, any code that access them, will throw an exception. These variables are said to be in a "temporal dead zone" (TDZ) from the start of the block until the initialization has completed. Accessing unintialized &lt;code&gt;let&lt;/code&gt; variables would result to a &lt;code&gt;ReferenceError&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// TDZ starts at beginning of scope&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;varVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;varVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;letVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// End of TDZ (for letVariable)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The term "temporal" is used because the zone depends on the execution order (referring to time - &lt;em&gt;temporal&lt;/em&gt;) rather than the order in which the code is written (position). However, the code snippet below will work because even though &lt;code&gt;sampleFunc&lt;/code&gt; uses the &lt;code&gt;letVariable&lt;/code&gt; before it is declared, the function is &lt;strong&gt;called&lt;/strong&gt; outside of the TDZ.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// TDZ starts at beginning of scope&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sampleFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;letVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// OK&lt;/span&gt;

    &lt;span class="c1"&gt;// Within the TDZ letVariable access throws `ReferenceError`&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;letVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;97&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// End of TDZ (for letVariable)&lt;/span&gt;
    &lt;span class="nf"&gt;sampleFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Called outside TDZ!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  📌 Variable Hoisting &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Remember that all function and variable declarations are hoisted to the &lt;strong&gt;TOP&lt;/strong&gt; of the scope. Declarations are processed &lt;strong&gt;before&lt;/strong&gt; any code is executed. With this, undeclared variables do not exist until the code assignment is executed. Variable assignment to an undeclared variable implicitly creates it as a &lt;strong&gt;global&lt;/strong&gt; variable when the assignment is executed. That means that any undeclared variable (but assigned) is a global variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;globalVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;functionScopedVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;78&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;globalVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 34&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;functionScopedVar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// throws a ReferenceError&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This is why it is always good to declare variables regardless of whether they are of function or global scope.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  📌 ES5 Strict Mode
&lt;/h4&gt;

&lt;p&gt;Introduced in EcmaScript 5, strict mode is a way to opt in to a restricted variant of JS. Strict mode make several changes to normal JS semantics&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Eliminates silent errors by throwing them&lt;/li&gt;
&lt;li&gt;Prohibits syntax that might be defined in future version of ES&lt;/li&gt;
&lt;li&gt;Fix mistakes that make JS engines perform optimizations&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;With regards to hoisting, using strict mode will not tolerate the use of variables before they are declared. &lt;/p&gt;

&lt;h3&gt;
  
  
  📌 Function Hoisting &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;JS functions can be declarations or expressions. &lt;/p&gt;

&lt;p&gt;Function declarations are hoisted completely to the top. That is why a function can be invoked even before it is declared.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;amIHoisted&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Yes I am."&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;amIHoisted&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yes I am.&lt;/span&gt;&lt;span class="dl"&gt;"&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;Function expressions, are &lt;strong&gt;NOT&lt;/strong&gt; hoisted. This is because of the precedence order of JS functions and variables. The snippet below would throw a &lt;code&gt;TypeError&lt;/code&gt; because the hoisted variable &lt;code&gt;amIHoisted&lt;/code&gt; is treated as a variable, not a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;amIHoisted&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;//Output: "TypeError: expression is not a function&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;amIHoisted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No I am not.&lt;/span&gt;&lt;span class="dl"&gt;"&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;The code execution of the code above would somehow look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;amIHoisted&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// undefined&lt;/span&gt;
&lt;span class="nf"&gt;amIHoisted&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="cm"&gt;/*Function is invoked, but from the interpreter's perspective it is not a function. 
Thus would throw a type error
*/&lt;/span&gt;
&lt;span class="nx"&gt;amIHoisted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No I am not.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="cm"&gt;/*The variable is assigned as a function late. It was already invoked before the assignment.*/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  📌 Hoisting Order of Precedence
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Variable assignment takes precedence over function declaration. 
The type of &lt;code&gt;amIABoolean&lt;/code&gt; would be a &lt;code&gt;boolean&lt;/code&gt; because the variable is assigned to a value &lt;code&gt;true&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;amIABoolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;amIABoolean&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;amIABoolean&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: boolean&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Function declarations take precedent over variable declarations. From the snippet below, the type of &lt;code&gt;amIAFunction&lt;/code&gt; would be a &lt;code&gt;function&lt;/code&gt; because on the first line, the variable is only declared, not assigned. Since function declarations takes precedence, it is resolved to type &lt;code&gt;function&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;amIAFunction&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;amIAFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yes.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;amIAFunction&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: function&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Hoisting in JS  is the compiler splitting variable declaration and initialization and moving only the declarations to the top of the code. So even though the functions and variables are called/used before they are written, the code still works. This happens because of how context execution works in Javascript.&lt;/p&gt;

&lt;p&gt;Note that only declarations are hoisted, &lt;strong&gt;not initializations&lt;/strong&gt;. For variables declared with the &lt;code&gt;var&lt;/code&gt; keyword, the default value would be &lt;code&gt;undefined&lt;/code&gt;. For &lt;code&gt;let&lt;/code&gt; variables, until the line in which they are initialized is executed, any code that access them, will throw an exception. These variables are said to be in a "temporal dead zone" (TDZ) from the start of the block until the initialization has completed. Accessing unintialized &lt;code&gt;let&lt;/code&gt; variables would result to a &lt;code&gt;ReferenceError&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That is it for the basics of JS hoisting, my fifth WIL(&lt;em&gt;What I Learned&lt;/em&gt;) dev post 😄.&lt;/p&gt;

&lt;p&gt;As always, cheers to lifelong learning 🍷! &lt;/p&gt;

&lt;h3&gt;
  
  
  [REFERENCES]
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting" rel="noopener noreferrer"&gt;MDN Web Docs : Hoisting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/understanding-hoisting-in-javascript" rel="noopener noreferrer"&gt;Understanding Hoisting in Javascript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.javascripttutorial.net/javascript-execution-context/" rel="noopener noreferrer"&gt;Javascript Context Execution&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#temporal_dead_zone_tdz" rel="noopener noreferrer"&gt;Temporal Dead Zone&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode" rel="noopener noreferrer"&gt;Strict Mode&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Java Annotations</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Tue, 20 Jul 2021 02:34:02 +0000</pubDate>
      <link>https://dev.to/pat_the99/java-annotations-4dp3</link>
      <guid>https://dev.to/pat_the99/java-annotations-4dp3</guid>
      <description>&lt;h2&gt;
  
  
  📌 Annotation Basics
&lt;/h2&gt;

&lt;p&gt;Annotations, a form of metadata, provide data about a program that is not part of the program itself. It has no direct effect on the operation of the code they annotate.&lt;/p&gt;

&lt;p&gt;Annotations hava a number of uses&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Information for the compiler&lt;/strong&gt;. Annotations can be used by the compiler to detect errors or supress warnings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compile-time and deployment time processing&lt;/strong&gt;. Software tools can process annotation information to generate code, XML files and so forth.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Runtime processing&lt;/strong&gt;. Some annotations are available to be examined at runtime.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 Declaring an Annotation Type
&lt;/h3&gt;

&lt;p&gt;The simplest format of an annotation looks like&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="nd"&gt;@Entity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The @ (sign character) indicates to the compiler that what follows is an annotation. The annotation above has a name &lt;code&gt;Entity&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Annotations can also include elements which can be named or unnamed. For instance,&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="nd"&gt;@Author&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
   &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Benjamin Franklin"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
   &lt;span class="n"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"3/27/2003"&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is only one element named &lt;code&gt;value&lt;/code&gt;, then the name can be omitted, as in:&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="nd"&gt;@SuppressWarnings&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"unchecked"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;myMethod&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;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the annotation has no elements, then the parentheses can be omitted,&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="nd"&gt;@Override&lt;/span&gt;
&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;mySuperMethod&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;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is also possible to use multiple annotations on the same declaration.&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="nd"&gt;@Author&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Jane Doe"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nd"&gt;@EBook&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&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;If the annotations have the same type, then that would be a &lt;code&gt;repeating annotation&lt;/code&gt;.&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="nd"&gt;@Author&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Jane Doe"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nd"&gt;@Author&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John Smith"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyClass&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;The annotation type can be one of the types that are defined in the &lt;code&gt;java.lang&lt;/code&gt; or &lt;code&gt;java.lang.annotation&lt;/code&gt; packages, like &lt;code&gt;@Override&lt;/code&gt; and &lt;code&gt;@SuppressWarnings&lt;/code&gt;, which are predefined Java annotations. It is also possible to define your own annotation type, i.e. custom annotations.&lt;/p&gt;

&lt;h4&gt;
  
  
  Where Can Annotation Be Used
&lt;/h4&gt;

&lt;p&gt;Annotations can be applied to declarations: classes, fields, methods and other program elements. &lt;/p&gt;

&lt;p&gt;As of Java 8, annotations can be applied to the &lt;code&gt;use&lt;/code&gt; of types. This form of annotation is called a type annotation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class instance creation expression
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nd"&gt;@Interned&lt;/span&gt; &lt;span class="nc"&gt;MyObject&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Type Cast
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@NonNull&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;str&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;implements&lt;/code&gt; clause
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UnmodifiableList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt;
        &lt;span class="nd"&gt;@Readonly&lt;/span&gt; &lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nd"&gt;@Readonly&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&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;ul&gt;
&lt;li&gt;Thrown exception declaration
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;monitorTemperature&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt;
        &lt;span class="nd"&gt;@Critical&lt;/span&gt; &lt;span class="nc"&gt;TemperatureException&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;h4&gt;
  
  
  Defining the annotation type
&lt;/h4&gt;

&lt;p&gt;The syntax for doing this is:&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="nd"&gt;@interface&lt;/span&gt; &lt;span class="nc"&gt;ClassPreamble&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;author&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
   &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;date&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
   &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;currentRevision&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;lastModified&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="s"&gt;"N/A"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;lastModifiedBy&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="s"&gt;"N/A"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
   &lt;span class="c1"&gt;// Note use of array&lt;/span&gt;
   &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;reviewers&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;The annotation type definitions looks similar to an interface definition where the keyword &lt;code&gt;interface&lt;/code&gt; is preceded by the @ sign. Annotations are a form of interface. The body of the annotation definition contains &lt;code&gt;annotation type element&lt;/code&gt; declaration, which look a lot like methods. They can also be defined with default values filled in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: To make the information of an annotation appear in Javadoc-generated documentation, it must be annotated with the @Documented annotation.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌 Predefined Annotation Types
&lt;/h3&gt;

&lt;p&gt;A set of annotation types are predefined in the Java SE API.&lt;/p&gt;

&lt;h4&gt;
  
  
  Annotation Types Used by the Java Language
&lt;/h4&gt;

&lt;p&gt;The predefined annotation types defined in &lt;code&gt;java.lang&lt;/code&gt; are : &lt;code&gt;@Deprecated&lt;/code&gt;, &lt;code&gt;@Override&lt;/code&gt;, and &lt;code&gt;@SuppressWarnings&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Deprecated&lt;/code&gt;. This indicates that the marked element is deprecated and should no longer be used. The compuler generates a warning whenever a program uses a method, class, or field with this annotation. When an element is deprecated it should also be documented using the Javadoc &lt;code&gt;@deprecated&lt;/code&gt; tag.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Javadoc comment follows&lt;/span&gt;
    &lt;span class="cm"&gt;/**
     * @deprecated
     * explanation of why it was deprecated
     */&lt;/span&gt;
    &lt;span class="nd"&gt;@Deprecated&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;deprecatedMethod&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;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@Override&lt;/code&gt;. This informs the compiler that the element is meant to override an element declared in superclass. While it is not required to use this annotation when overriding a method, it helps to prevent errors. If a method marked with &lt;code&gt;@Override&lt;/code&gt; fails to correclty override a method in one of its superclasses, the compiler generates an error.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;@SupressWarnings&lt;/code&gt;. This tells the compiler to suppress specific warnings that it would otherwise generate. For instance,&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// use a deprecated method and tell &lt;/span&gt;
   &lt;span class="c1"&gt;// compiler not to generate a warning&lt;/span&gt;
   &lt;span class="nd"&gt;@SuppressWarnings&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"deprecation"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;useDeprecatedMethod&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// deprecation warning&lt;/span&gt;
        &lt;span class="c1"&gt;// - suppressed&lt;/span&gt;
        &lt;span class="n"&gt;objectOne&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;deprecatedMethod&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;Every compiler warning belongs to a category. The Java language specification lists two categories: &lt;code&gt;deprecation&lt;/code&gt; and &lt;code&gt;unchecked&lt;/code&gt;. Unchecked warnings occur when interfacing with legacy code written before the advent of generics.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@SafeVarargs&lt;/code&gt; . When applied to a method or constructor, this asserts that the code does not perform potentially unsafe operations on its &lt;code&gt;varargs&lt;/code&gt; parameter. When this annotation is used, unchecked warnings related to &lt;code&gt;varargs&lt;/code&gt; are suppressed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@FunctionalInterface&lt;/code&gt;. Introduced in Java 8, this indicates that the type declaration is intended to be a functional interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Annotations that Apply to Other Annotations
&lt;/h4&gt;

&lt;p&gt;Annotations that apply to other annotations are called meta-annotations. There are several meta-annotations defined in &lt;code&gt;java.lang.annotation&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@Retention&lt;/code&gt;. This specifies how the marked annotation is stored. 

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;RetentionPolicy.SOURCE&lt;/code&gt;. The marked annotation is retained only in the source level and is ignored by the compiler.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RetentionPolicy.CLASS&lt;/code&gt;. The marked annotation is retained by the compiler at compile time, but is ignored by JVM.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RetentionPolicy.RUNTIME&lt;/code&gt;. The marked annotation is retained by the JVM so it can be used by the runtime environment.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;@Documented&lt;/code&gt;. This indicates that whenever the specified annotation is used, those elements should be documented using the Javadoc tool (By default, annotations are not inclueded in the Javadoc). &lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;code&gt;@Target&lt;/code&gt;. This annotation marks another annotation to restrict what kind of Java elements the annotation can be applied to. A target annotation specifies one of the ff. element.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ElementType.ANNOTATION_TYPE&lt;/code&gt;. This can be applied to an annotation type.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ElementType.CONSTRUCTOR&lt;/code&gt;. This can be applied to a constructor.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ElementType.FIELD&lt;/code&gt;. This can be applied to a field or property.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ElementType.LOCAL_VARIABLE&lt;/code&gt;. This can be applied to a local variable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ElementType.METHOD&lt;/code&gt;. This can be applied to a method level annotation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ElementType.PACKAGE&lt;/code&gt;. This can be applied to a package declaration.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ElementType.PARAMETER&lt;/code&gt;. THis can be applied to the parameters of a method.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ElementType.TYPE&lt;/code&gt;. This can be applied to any element of a class.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;code&gt;@Inherited&lt;/code&gt;. This indicates that the annotation type can be inherited from the superclass (not true by default). When the user queries the annotation type and the class has no annotation for this type, the class' superclass is queried for the annotation type. This can only be applied to class declarations.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;code&gt;@Repeatable&lt;/code&gt;. Introduced in Java 8, this indicates that the marked annotation can be applied more than once to the same declaration or type use. &lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  📌 Type Annotations and Pluggable Type Systems
&lt;/h3&gt;

&lt;p&gt;Before Java 8, annotations can only be applied to declarations. After Java 8's release, annotations can also be applied to any &lt;strong&gt;type use&lt;/strong&gt;. This meant that annotations can be used anywhere where type is used., e.g. instance creation expressions &lt;em&gt;&lt;code&gt;(new)&lt;/code&gt;&lt;/em&gt;, casts, &lt;code&gt;implements&lt;/code&gt; clauses and &lt;code&gt;throws&lt;/code&gt; clauses. This form of annotation is called &lt;code&gt;type annotation&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Type Annotations were created to support improved analysis of Java programs way of ensuring stronger type checking. The Java SE 8 release does not provide a type checking framework, but it allows developers to write (or download) a type checking framework that is implemented as one or more &lt;strong&gt;pluggable modules&lt;/strong&gt; that are used in conjunction with the compiler.&lt;/p&gt;

&lt;p&gt;For instance, a custom plug-in check can be used to ensure that a certain variable is never assigned &lt;code&gt;null&lt;/code&gt;.&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="nd"&gt;@NonNull&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When this code is compiled including the &lt;code&gt;NonNull&lt;/code&gt; module, the compiler prints a warning if it detects a potential problem, allowing developers to modify the code to avoid the error. After the code is corrected, this particular error will not occur when the program runs.&lt;/p&gt;

&lt;p&gt;With the judicious use of type annotations and presence of pluggable type checkers, the code can be stronger and less prone to error.&lt;/p&gt;

&lt;p&gt;There are a lot of existing libraries for type checking modules. For example the Checker Framework created by University of Washington. This framework includes a NonNull module, as well as regular expression module and a mutex lock module. See &lt;a href="https://checkerframework.org/" rel="noopener noreferrer"&gt;this&lt;/a&gt; for more information.&lt;/p&gt;

&lt;h3&gt;
  
  
  📌 Repeating Annotations
&lt;/h3&gt;

&lt;p&gt;As of Java 8 release, repeating annotations are introduced which enables developers to use the same annotation to a declaration or type use.&lt;/p&gt;

&lt;h4&gt;
  
  
  Steps in Creating a Repeatable Annotation
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Declaring Repeating Annotations&lt;/strong&gt;
The annotation type must be marked with the &lt;code&gt;@Repeatable&lt;/code&gt; metannotation. For instance
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Repeatable&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Schedules&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="nd"&gt;@interface&lt;/span&gt; &lt;span class="nc"&gt;Schedule&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;dayOfMonth&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="s"&gt;"first"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The value of the @Repeatable meta-annotation, in parentheses, is the type of the container annotation that the Java compiler generates to store repeating annotations. In this example, the containing annotation type is Schedules, so repeating @Schedule annotations is stored in an @Schedules annotation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applying the same annotation to a declaration without first declaring it to be repeatable results in a compile-time error.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Declare the Containing Annotation Type&lt;/strong&gt;
The containing annotation type must have a value element with an array type. The component type of the array type must be the repeatable annotation type. The declaration for the Schedules containing annotation type is the following:
&lt;/li&gt;
&lt;/ol&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="nd"&gt;@interface&lt;/span&gt; &lt;span class="nc"&gt;Schedules&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Schedule&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="nf"&gt;value&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;h5&gt;
  
  
  Retrieving Annotations
&lt;/h5&gt;

&lt;p&gt;There are several methods available in the Reflection API that can be used to retrieve annotations. The behavior of the methods that return a single annotation, such as &lt;code&gt;AnnotatedElement.getAnnotation(Class&amp;lt;T&amp;gt;)&lt;/code&gt;, are unchanged in that they only return a single annotation if one annotation of the requested type is present. If more than one annotation of the requested type is present, you can obtain them by first getting their container annotation. In this way, legacy code continues to work. Other methods were introduced in Java SE 8 that scan through the container annotation to return multiple annotations at once, such as &lt;code&gt;AnnotatedElement.getAnnotationsByType(Class&amp;lt;T&amp;gt;)&lt;/code&gt;. &lt;/p&gt;

&lt;h5&gt;
  
  
  Design Considerations
&lt;/h5&gt;

&lt;p&gt;When designing an annotation type, the cardinality of annotations of that type must be considered. It is now possible to use an annotation zero times, once, or, if the annotation's type is marked as &lt;code&gt;@Repeatable&lt;/code&gt;, more than once. It is also possible to restrict where an annotation type can be used by using the &lt;code&gt;@Target&lt;/code&gt; meta-annotation. It is important to design annotation types carefully to ensure that the person using the annotation finds it to be as flexible and powerful as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;As always, cheers to lifelong learning!! 🍷&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  REFERENCES
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://docs.oracle.com/javase/tutorial/java/annotations/index.html" rel="noopener noreferrer"&gt;Java Documentation: Annotations&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Java Nested Classes and Lambda Expressions</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Sun, 11 Jul 2021 09:35:48 +0000</pubDate>
      <link>https://dev.to/pat_the99/java-nested-classes-and-lambda-expressions-18o6</link>
      <guid>https://dev.to/pat_the99/java-nested-classes-and-lambda-expressions-18o6</guid>
      <description>&lt;h2&gt;
  
  
  [Java WIL🤔 Post #2]
&lt;/h2&gt;

&lt;p&gt;Java has a very rich set of features that gives developers a lot of options to choose their implementation from, two of them, &lt;strong&gt;nested classes&lt;/strong&gt; and &lt;strong&gt;lambda expressions&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;I was reading a certain part of a code base and realized that I have not really fully understood the differences between the types of nested classes. The section below is heavily based from the Java Documentation for Nested Classes, so in-depth explanations can be checked &lt;a href="https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Nested Classes&lt;/li&gt;
&lt;li&gt;Why Use Nested Classes&lt;/li&gt;
&lt;li&gt;Inner Classes&lt;/li&gt;
&lt;li&gt;Static Nested Classes&lt;/li&gt;
&lt;li&gt;Shadowing in Nested Classes&lt;/li&gt;
&lt;li&gt;Serialization of Nested Classes&lt;/li&gt;
&lt;li&gt;Local and Anonymous Classes&lt;/li&gt;
&lt;li&gt;Lambda Expressions&lt;/li&gt;
&lt;li&gt;Functional Interface&lt;/li&gt;
&lt;li&gt;Target Typing In Lambdas&lt;/li&gt;
&lt;li&gt;Method References&lt;/li&gt;
&lt;li&gt;When to Use Nested Classes, Local Classes, Anonymous Classes and Lambda Expressions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  📌 Nested Classes  &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A nested class is a class within another class, i.e. a member of its enclosing class. It is divided into two categories: &lt;strong&gt;non-static&lt;/strong&gt; and &lt;strong&gt;static&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Non-static nested classes are called &lt;strong&gt;&lt;em&gt;inner classes&lt;/em&gt;&lt;/strong&gt;. They have access to other members of the enclosing class, even if they are declared private. &lt;/li&gt;
&lt;li&gt;Nested classes that are declared static are called &lt;strong&gt;&lt;em&gt;static nested classes&lt;/em&gt;&lt;/strong&gt;. They DO NOT have access to other members of the enclosing class. &lt;/li&gt;
&lt;li&gt;As a member of the outer class, a nested class can be declared &lt;code&gt;private&lt;/code&gt;, &lt;code&gt;public&lt;/code&gt;, &lt;code&gt;protected&lt;/code&gt; or &lt;code&gt;package-private&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Note that outer classes can only be declared &lt;code&gt;public&lt;/code&gt; or &lt;code&gt;package-private&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 Why Use Nested Classes &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;It is a way of logically grouping classes that are only used in one place.&lt;/li&gt;
&lt;li&gt;It increases encapsulation.&lt;/li&gt;
&lt;li&gt;It can lead to more readable and maintainable code. &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 Inner Classes &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;An inner class is associated with an instance of its enclosing class and has direct access to that object's methods and fields. &lt;/li&gt;
&lt;li&gt;As an inner class is associated with an instance, &lt;strong&gt;IT CANNOT DEFINE ANY STATIC MEMBERS ITSELF.&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Objects that are instances of an inner class exist within an instance of the outer class. Thus an instance of an inner class can only exist within an instance of the outer class and has direct access to the methods and fields of the enclosing instance.&lt;/li&gt;
&lt;li&gt;To instantiate an inner class, the outer class must first be instantiated. &lt;/li&gt;
&lt;li&gt;There are two special kinds of inner classes: &lt;strong&gt;local classes&lt;/strong&gt; and &lt;strong&gt;anonymous classes&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ol&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;OuterClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;InnerClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// class content here&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;h3&gt;
  
  
  📌 Static Nested Classes &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;As with class methods, a static nested class is associated with its outer class. &lt;/li&gt;
&lt;li&gt;A static nested class cannot refer directly to instance variables or methods defined in its enclosing class. It can use them only through an object reference.&lt;/li&gt;
&lt;li&gt;A static nested class interacts with the instance members of its outer class and other classes just like any other top level class. &lt;strong&gt;Thus a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&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;OuterClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StaticNestedClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
       &lt;span class="c1"&gt;// class contents here&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;h4&gt;
  
  
  📌 Shadowing in Nested Classes &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;If a declaration of a type in a particular scope has the same name as another declaration in the enclosing scope, then the declaration shadows the declaration of the enclosing scope.&lt;/li&gt;
&lt;li&gt;The shadowed declaration cannot be referenced by its name alone. Note, you can actually do this : &lt;code&gt;ShadowTest.this.x&lt;/code&gt;.  &lt;a href="https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html" rel="noopener noreferrer"&gt;Go to shadowing section of this link&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Refer to member variables that enclose larger scopes by the class name to which they belong. For example, the ff. statement accesses the member variable of the class &lt;code&gt;ShadowTest&lt;/code&gt; from the method.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&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;"ShadowTest.this.x = "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;ShadowTest&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  📌 Serialization &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Serialization of inner classes, including local and anonymous classes is &lt;strong&gt;strongly discouraged&lt;/strong&gt;. When the Java compiler compiles certain constructs such as inner classes, it creates &lt;strong&gt;&lt;em&gt;synthetic constructs&lt;/em&gt;&lt;/strong&gt;; these are classes, methods, fields and other constructs that do not have a corresponding construct in the source code. Synthetic constructs enable Java compilers to implement new Java language features without changes to the JVM. However, they may vary among different implementations.&lt;/li&gt;
&lt;li&gt;Might have compatibility issues if an inner class is serialized and then deserialize it with a different JRE implementation.&lt;/li&gt;
&lt;li&gt;Read more at the Serialization section of this &lt;a href="https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html" rel="noopener noreferrer"&gt;link&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 Local and Anonymous Classes &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;There are two types of inner classes : local and anonymous. An inner class within the body of a method is called a &lt;strong&gt;local class&lt;/strong&gt;. An &lt;strong&gt;inner class&lt;/strong&gt; can also be declared inside the body of a method without naming them, i.e. an &lt;strong&gt;anonymous class&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The same modifiers used for other members of the outer class can be used for an inner class. For instance the access modifiers &lt;code&gt;private&lt;/code&gt;, &lt;code&gt;public&lt;/code&gt;, &lt;code&gt;package-private&lt;/code&gt; &lt;code&gt;protected&lt;/code&gt; can be used in an inner class just like how they are used for the instance fields of the outer class.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  📌 &lt;a href="https://docs.oracle.com/javase/tutorial/java/javaOO/localclasses.html" rel="noopener noreferrer"&gt;More on Local Classes&lt;/a&gt;
&lt;/h4&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;SomeClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;someMethod&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SomeLocalClass&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// class contents here&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;ol&gt;
&lt;li&gt;Local classes are classes defined in a block, which is a group of zero or more statements. &lt;/li&gt;
&lt;li&gt;Local classes can be defined inside any block, i.e. in a method body, a for loop or an if clause.&lt;/li&gt;
&lt;li&gt;A local class has access to the members of its enclosing class. It also has access to local variables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IMPORTANT: A local class can only access local variables that are declared final.&lt;/strong&gt; When a local class accesses a local variable or parameter of the enclosing block, it &lt;strong&gt;&lt;em&gt;captures&lt;/em&gt;&lt;/strong&gt; the variable or parameter.&lt;/li&gt;
&lt;li&gt;Starting Java 8, a local class can access local variables and parameters of the enclosing block that are final or effectively final. A variable or parameter whose value is never changed after it is initialized is &lt;strong&gt;effectively final&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Starting also in Java SE 8, if you declare the local class in a method, it can access the method's parameters.&lt;/li&gt;
&lt;li&gt;Local classes are similar to inner classes because they cannot define or declare any static members.&lt;/li&gt;
&lt;li&gt;Local classes in static methods, can only refer static members of the enclosing classes.&lt;/li&gt;
&lt;li&gt;Local classes are non-static because they have access to instance members of the enclosing block. Consequently they cannot contain most kinds of static declarations.&lt;/li&gt;
&lt;li&gt;An interface cannot be declared inside a block. Interfaces are inherently static.&lt;/li&gt;
&lt;li&gt;Static initializers or member interfaces cannot be declared inside a local class. &lt;/li&gt;
&lt;li&gt;A local class can have static members provided that they are constant variables. A &lt;em&gt;constant variable&lt;/em&gt; is a variable of primitive type or type String that is declared final and initialized with a compile-time constant expression. A compile time constant expression is typically a string or an arithmetic expression that can be evaluated at compile time.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 Anonymous Classes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;    &lt;span class="nc"&gt;SomeAnonyMousClass&lt;/span&gt; &lt;span class="n"&gt;anonClass&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;SomeAnonyMousClass&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="c1"&gt;// instance field declarations&lt;/span&gt;
        &lt;span class="c1"&gt;// methods &lt;/span&gt;
        &lt;span class="c1"&gt;// should contain no constructor&lt;/span&gt;
    &lt;span class="o"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Anonymous classes makes the code more concise. It enables declaration and instantiation of class at the same time. They are similar to local classes except that they do not have a name.&lt;/li&gt;
&lt;li&gt;While local classes are class declaration, &lt;strong&gt;anonymous classes are expressions&lt;/strong&gt;, which means that the class is defined in another expression. &lt;/li&gt;
&lt;li&gt;The syntax of an anonymous class expression is like the invocation of a constructor, except that there is a class definition contained in the code block.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;HelloWorld&lt;/span&gt; &lt;span class="n"&gt;helloWorld&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;HelloWorld&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// code here&lt;/span&gt;
&lt;span class="o"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The anonymous class expression consists of the following: &lt;code&gt;new&lt;/code&gt; operator, the name of an interface to implement or a class to extend, parentheses that contain the arguments to a constructor, just like a normal class instance creation expression and a body, which is a class declaration body.&lt;/li&gt;
&lt;li&gt;Because an anonymous class definition is an expression, it must be part of a statement. This explains why there is a semicolon after the closing brace.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  📌 Accessing Local Variables of the Enclosing Scope and Declaring and Accessing Members of the Anonymous Class
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Like local classes, anonymous classes can capture variables; they have the same access to local variables of the enclosing scope.&lt;/li&gt;
&lt;li&gt;An anonymous class has access to the members of its enclosing class.&lt;/li&gt;
&lt;li&gt;An anonymous class cannot access local variables in its enclosing scope that are not declared as final or effectively final.&lt;/li&gt;
&lt;li&gt;Like a nested class, a declaration of a type in an anonymous class shadows any other declarations in the enclosing scope that have the same name.&lt;/li&gt;
&lt;li&gt;Anonymous classes also have the same restrictions as local classes with respect to their members: static initializers or member interfaces cannot be declared; an anonymous class can have static members provided that they are constant variables. &lt;/li&gt;
&lt;li&gt;Note, the ff can be declared in anonymous class
a. Fields
b. extra methods
c. instance initializers
d. local classes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IMPORTANT: You cannot declare constructors in an anonymous class.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Anonymous classes are ideal for implementing an interface that contains two or more methods.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To summarize the hierarchy stated above, the image below shows the types of nested classes.&lt;br&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%2Fdre0iay2eowqgnwhtj9i.jpg" 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%2Fdre0iay2eowqgnwhtj9i.jpg" alt="Types of Nested Classes" width="584" height="306"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  📌 &lt;a href="https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html" rel="noopener noreferrer"&gt;Lambda Expressions&lt;/a&gt; &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Lambda Expressions enables developers to treat functionality as a method argument, or code as a data.&lt;/li&gt;
&lt;li&gt;For classes with only one method, an anonymous class, much more a named class is a bit excessive and cumbersome. Lambdas express instances of single-method classes more compactly.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  📌 Syntax of Lambda Expressions
&lt;/h4&gt;

&lt;p&gt;A lambda expression consists of the ff.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A comma-separated list of formal parameters enclosed in parentheses. The data type of the parameters in the lambda expression can be omitted. Moreover, the parentheses can be omitted if there is only one parameter.&lt;/li&gt;
&lt;li&gt;The arrow token &lt;code&gt;-&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The body which consists of a single expression or a statement block. The return statement can also be used, however, keep in mind that a return statement is not an expression in lambdas, so they must be enclosed in braces. Lambdas can be treated as anonymous methods - methods without names.
For instance,
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;-&amp;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;getAge&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&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;getAge&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  📌 Functional Interface &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;A &lt;strong&gt;&lt;em&gt;functional interface&lt;/em&gt;&lt;/strong&gt; is any interface that contains only one &lt;strong&gt;abstract method&lt;/strong&gt;. It may contain one or more default methods or static methods. Because it only contains one abstract method, the name can be omitted when implementing it. By doing this instead of using an anonymous class expression, a lambda expression is used. The JDK defines several standard functional interfaces which can be found in the package &lt;code&gt;java.util.function&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  📌 Accessing Local Variables of the Enclosing Scope in Lambda Expressions
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Like local and anonymous classes, lambdas can capture variables; they have the same access to local variables of the enclosing scope. However, unlike local and anonymous classes, &lt;strong&gt;lambdas do not have shadowing issues&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;Lambdas are &lt;strong&gt;lexically scoped&lt;/strong&gt;. This means that they do not inherit any names from a supertype or introduce a new level of scoping. Declarations in lambdas are interpreted just as they are in the enclosing environment.&lt;/li&gt;
&lt;li&gt;If the parameter passed to a lambda is declared in the enclosing scope, then the compiler generates an error, &lt;code&gt;Lambda expression's parameter {} cannot redeclare another local variable defined in an enclosing scope&lt;/code&gt;. This is because lambda expressions do not introduce a new level of scoping. Consequently, lambdas can directly access fields, methods and local variables of the enclosing scope. &lt;/li&gt;
&lt;li&gt;Like local and anonymous classes, a lambda expression can only access local variables and parameters of the enclosing block that are &lt;strong&gt;final&lt;/strong&gt; or &lt;strong&gt;effectively final&lt;/strong&gt; (value should not be changed after initialization).&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  📌 Target Typing in Lambdas &lt;a&gt;
&lt;/a&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;So how can the type of a lambda expression be determined, e.g. the type of p in the example below?&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;-&amp;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;getAge&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the Java runtime invokes the method where the lambda is passed, it is expecting a specific datatype, so the lambda expression is of this type.The data type that these methods expect is called the &lt;strong&gt;target type&lt;/strong&gt;. To determine the type of a lambda expression, the Java compiler uses the target type of the context or situation in which the lambda expression was found. Thus, &lt;strong&gt;&lt;em&gt;lambda expressions can only be used in situation in which the Java compiler can determine the target type&lt;/em&gt;&lt;/strong&gt;, i.e. in :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;variable declarations&lt;/li&gt;
&lt;li&gt;assignments&lt;/li&gt;
&lt;li&gt;return statements&lt;/li&gt;
&lt;li&gt;array initializers&lt;/li&gt;
&lt;li&gt;method or constructor arguments&lt;/li&gt;
&lt;li&gt;lambda expression bodies&lt;/li&gt;
&lt;li&gt;conditional expressions&lt;/li&gt;
&lt;li&gt;cast expressions&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  📌 Target Types and Method Arguments
&lt;/h5&gt;

&lt;p&gt;For method arguments, the Java compiler determines the target type with two other language features &lt;strong&gt;overload resolution&lt;/strong&gt; and &lt;strong&gt;type argument interface&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For instance, if the functional interfaces &lt;code&gt;java.lang.Runnable&lt;/code&gt; and &lt;code&gt;java.util.Callable&amp;lt;V&amp;gt;&lt;/code&gt; are implemented and overloaded by a certain class like this,&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="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Callable&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;call&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;Which method will be invoked by the statement below?&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;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;invoke&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="s"&gt;"done"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method with argument &lt;code&gt;Callable&amp;lt;V&amp;gt;&lt;/code&gt; will be invoked because the lambda returns a value, in this case the string &lt;code&gt;done&lt;/code&gt;. Note that the method &lt;code&gt;invoke(Runnable)&lt;/code&gt; does not return a value.&lt;/p&gt;

&lt;h4&gt;
  
  
  📌 Serialization of Lambdas
&lt;/h4&gt;

&lt;p&gt;A lambda can be serialized if its target type and its captured arguments are serializable. However, like inner classes, 🛑 &lt;strong&gt;the serialization of lambdas are strongly discouraged&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  📌 Method References &lt;a&gt;&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;Lambdas can be used to create anonymous methods. However, there are times when it does nothing but call an existing method. In these cases, it is often clearer to refer to the existing method by name, called &lt;strong&gt;method referencing&lt;/strong&gt;. They are compact, easy-to-read lambdas for methods that already have a name.&lt;br&gt;
For instance this can be done in sorting an array of Person objects by age.&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;Arrays&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;sort&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;personListAsArray&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;Person:&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;compareByAge&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The method reference &lt;code&gt;Person::compareByAge&lt;/code&gt; is semantically the same as the lambda expression where &lt;code&gt;compareByAge&lt;/code&gt; is a static method of the Person class.&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="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;person2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;compareByAge&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;person1&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Kinds of Method References
&lt;/h5&gt;

&lt;p&gt;There are four types of method referencing&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Kind&lt;/th&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Reference to a static method&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ContainingClass::staticMethodName&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Person::compareByAge&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reference to an instance method of a particular object&lt;/td&gt;
&lt;td&gt;&lt;code&gt;containingObject::instanceMethodName&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;person1::compareByName&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reference to an instance method of an arbitrary object of a particular type&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ContainingType::methodName&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;String::concat&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reference to a constructor&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ClassName::new&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;HashSet::new&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  📌 When to Use Nested Classes, Local Classes, Anonymous Classes and Lambda Expressions &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Nested Classes enable the logical grouping of classes that are only used in one place, increase the use of encapsulation, create more readable and maintainable code. Local classes, anonymous classes and lambda expressions also share the same advantages but they are usually used for more specific situations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local Class&lt;/strong&gt; . Used if creating more than one instance of a class is needed, access its constructor and/or introduce a new, named type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anonymous Class&lt;/strong&gt; . Used if declared fields or additional methods are needed&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Lambda Expressions&lt;/strong&gt; . &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used for encapsulating a single unit of behavior that is passed to the other parts of the code. &lt;/li&gt;
&lt;li&gt;Used if a simple instance of a functional interface is needed and some other criteria like constructor, named type, fields or additional methods are not needed&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Nested Class&lt;/strong&gt; . Used for reasons similar to those of local classes, i.e. it is necessary to make the type more widely available, and access to local variables or method parameters are not needed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inner class should be used if access to an enclosing instance's non-public fields and methods are required. &lt;/li&gt;
&lt;li&gt;Static class should be used if there is no instance field that needs to be accessed from the class.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Getting used and familiar with nested classes and advanced lambdas with generics certainly takes a lot of reading code and practice. We will eventually get there.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As always, cheers to continued growth and learning 🍷!&lt;/p&gt;

&lt;h3&gt;
  
  
  REFERENCES
&lt;/h3&gt;

&lt;p&gt;[1] &lt;a href="https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html" rel="noopener noreferrer"&gt;Java Nested Classes&lt;/a&gt;&lt;br&gt;
[2] &lt;a href="https://www.flowerbrackets.com/nested-classes-in-java/" rel="noopener noreferrer"&gt;Nested Classes in Java&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Basics of Javascript Test Driven Development (TDD) with Jest</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Sun, 04 Jul 2021 06:21:34 +0000</pubDate>
      <link>https://dev.to/pat_the99/basics-of-javascript-test-driven-development-tdd-with-jest-o3c</link>
      <guid>https://dev.to/pat_the99/basics-of-javascript-test-driven-development-tdd-with-jest-o3c</guid>
      <description>&lt;h2&gt;
  
  
  [JS#4 WIL 🤔 Post]
&lt;/h2&gt;

&lt;p&gt;Test Driven Development (TDD)'s main idea is to simply start working on code by writing automated tests &lt;strong&gt;BEFORE&lt;/strong&gt; writing the code that is being tested. There are many test-running systems in Javascript: &lt;em&gt;Jasmine&lt;/em&gt;, &lt;em&gt;Jest&lt;/em&gt;, &lt;em&gt;Tape&lt;/em&gt;, and &lt;em&gt;Mocha&lt;/em&gt; to name a few. They have their special features but the syntax is very similar. The framework chosen should not be an issue because &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;writing tests is less about the syntax but more on the TDD philosophy, &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;so I tried internalizing the concepts using Jest. My main goal while doing the exercise is to know the why's and whats of testing.&lt;/p&gt;

&lt;p&gt;Before diving in, here are some notes I took from this brilliant talk, &lt;a href="https://www.youtube.com/watch?v=URSWYvyc42M" rel="noopener noreferrer"&gt;The Magic of Testing&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Why does most devs hate tests? Because they are slow and fragile and expensive (time).&lt;/li&gt;
&lt;li&gt;It is perfectly valid to delete some tests. &lt;/li&gt;
&lt;li&gt;Unit Test Goals: They must be &lt;strong&gt;thorough&lt;/strong&gt; (we want them to prove logically and completely that the single object under test is behaving correctly) and &lt;strong&gt;stable&lt;/strong&gt; (we dont want to break the test everytime the implementation detail is changed 😟), &lt;strong&gt;fast&lt;/strong&gt; and &lt;strong&gt;few&lt;/strong&gt; (write tests for the most parsimonious expression [mmmmmm 🤔]).&lt;/li&gt;
&lt;li&gt;Do not test private methods. But break this rule if it saves money during development.&lt;/li&gt;
&lt;li&gt;A mock is a test double, it plays the role of some object in your real app. Ensure test double stays in sync with the API.&lt;/li&gt;
&lt;li&gt;Trust collaborators that they will do the right thing. Insist on simplicity.&lt;/li&gt;
&lt;li&gt;Getting better at testing takes time and practice.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;The object under test have three origin of messages :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Incoming&lt;/strong&gt; - messages to the object from outside&lt;br&gt;
   📌 &lt;strong&gt;Self&lt;/strong&gt; - messages sent by the object under test to itself&lt;br&gt;
   📌 &lt;strong&gt;Outgoing&lt;/strong&gt; - messsages sent by the object to the outside.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are two types of messages : &lt;strong&gt;query&lt;/strong&gt; and &lt;strong&gt;command&lt;/strong&gt;. Queries return something or changes nothing. Command types return nothing but changes something.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  📌 Grid of Test Rules
&lt;/h3&gt;

&lt;p&gt;The grid of test results below shows how each type of message can be unit tested.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Message Type&lt;/th&gt;
&lt;th&gt;Query&lt;/th&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Incoming&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Assert result&lt;/strong&gt;&lt;br&gt;Test incoming query messages by making assertions about what they send back.&lt;br&gt;Test the interface and not the implementation.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Test incoming command messages by making assertions about direct public side effects.&lt;/strong&gt;&lt;br&gt;DRY it out. Receiver of incoming message has sole responsibility for asserting the result of direct public side effects.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sent to Self&lt;/td&gt;
&lt;td&gt;Ignore: Do not test private methods.&lt;/td&gt;
&lt;td&gt;Ignore: Do not test private methods.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Outgoing&lt;/td&gt;
&lt;td&gt;Ignore. The receiver of an incoming query is solely responsible for assertions that involve state.&lt;br&gt;If a message has no visible side effects, the sender should not test it&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Expect&lt;/strong&gt; to send outgoing command messages using mocks&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  📌 Advantages of TDD
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Reduces bugs that may be introduced when adding new features or modifying existing features&lt;/li&gt;
&lt;li&gt;Builds a safety net against changes of other programmers that may affect a specific part of the code&lt;/li&gt;
&lt;li&gt;Reduces the cost of change by ensuring that the code will still work with the new changes&lt;/li&gt;
&lt;li&gt;Reduces the need for manual (monkey) checking by testers and developers&lt;/li&gt;
&lt;li&gt;Improves confidence in code&lt;/li&gt;
&lt;li&gt;Reduces the fear of breaking changes during refactors&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  📌 Getting Started with Jest
&lt;/h3&gt;

&lt;p&gt;Jest is a javascript testing framework focusing on simplicity but still ensures the correctness of the Javascript code base. It boasts itself to be &lt;strong&gt;&lt;em&gt;fast and safe&lt;/em&gt;&lt;/strong&gt;, reliably running tests in parallel with unique global state. To make things quick, Jest runs previously failed tests first and re-organizes runs based on how long test files take.&lt;/p&gt;

&lt;p&gt;Moreover, Jest is very well-documented and requires little configuration. It indeed makes javascript testing delightful. It can be installed by using either &lt;code&gt;yarn&lt;/code&gt; or &lt;code&gt;npm&lt;/code&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  📌 Three Modes of TDD
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Obvious implementation&lt;/strong&gt;. You write the test with the implementation since you know how to implement the method to test.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fake it til you make it&lt;/strong&gt;. If you know the problem and solutions, but the way you code them up is not immediately obvious to you, then you can use a trick called "fake it 'til you make it."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Triangulation&lt;/strong&gt; . This is the most conservative way of doing TDD. If you don't even know the solution, you just get to green at all costs , red-green, red-green loop.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  📌 Using Jest Matchers
&lt;/h4&gt;
&lt;h5&gt;
  
  
  Common Matchers
&lt;/h5&gt;

&lt;p&gt;The simplest way to test a value is with exact equality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;adds 1 + 2 to equal 3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&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;The code snippet above returns an "expectation" object. The &lt;code&gt;toBe(3)&lt;/code&gt; portion is the matcher. When Jest runs, it tracks all the failing matchers so it can print nice error messages. The &lt;code&gt;toBe&lt;/code&gt; matcher uses &lt;code&gt;Object.is&lt;/code&gt; to test the equality. &lt;/p&gt;

&lt;h5&gt;
  
  
  Truthiness
&lt;/h5&gt;

&lt;p&gt;In unit tests, the special values &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;null&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt; might be needed to be checked also. Jest contains helpers that lets developers be explicit with what to expect. It is then good to use a matcher that most precisely corresponds to what the code is doing.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;toBeNull&lt;/code&gt; matches only &lt;code&gt;null&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeUndefined&lt;/code&gt; matches only &lt;code&gt;undefined&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeDefined&lt;/code&gt; is the opposite of &lt;code&gt;toBeUndefined&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeTruthy&lt;/code&gt; matches anything that an &lt;code&gt;if&lt;/code&gt; statement treats as true&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBeFalsy&lt;/code&gt; matches anything that an &lt;code&gt;if&lt;/code&gt; statement treats as false&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Numbers
&lt;/h5&gt;

&lt;p&gt;There are also Jest matchers for comparing numbers such as &lt;code&gt;toBeGreaterThan&lt;/code&gt;, &lt;code&gt;toBeGreaterThanOrEqual&lt;/code&gt;, &lt;code&gt;toBeLessThan&lt;/code&gt;, &lt;code&gt;toBeLessThanOrEqual&lt;/code&gt;. For floating point numbers, there are equality matcher like &lt;code&gt;toBeCloseTo&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Strings
&lt;/h5&gt;

&lt;p&gt;Strings can be checked against regular expressions using &lt;code&gt;toMatch&lt;/code&gt;.&lt;/p&gt;

&lt;h5&gt;
  
  
  Arrays and Iterables
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;toContain&lt;/code&gt; can be used to check if a particular item can be found in an array or iterable.&lt;/p&gt;

&lt;h5&gt;
  
  
  Exceptions
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;toThrow&lt;/code&gt; can be used to check if a particular function throws a specific error. It is to be noted that the function being checked needs to be invoked within a wrapping function for the &lt;code&gt;toThrow&lt;/code&gt; exception to work.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are also more advanced Jest matchers used for testing asynchronous code, i.e for callbacks and promises. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  📌 Jest Testing Practice
&lt;/h4&gt;

&lt;p&gt;This is my first time writing javascript unit tests using Jest. It is quite new so I needed some practice 😄. I tried using the &lt;strong&gt;obvious implementation&lt;/strong&gt; and &lt;strong&gt;triangulation&lt;/strong&gt; mode of testing for some of the methods below. The full implementation of the methods and their corresponding tests can be found in my &lt;a href="https://github.com/fatrixienicolieopetina/practice-jest-testing/tree/main/_js" rel="noopener noreferrer"&gt;Jest practice github repository&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;capitalize(string)&lt;/code&gt; takes a string and returns that string with the first character capitalized.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/fatrixienicolieopetina/practice-jest-testing/blob/main/_js/tests/capitalize.test.js" rel="noopener noreferrer"&gt;&lt;code&gt;capitalize.test.js&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;capitalize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../capitalize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should capitalize lowercase string correctly&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;capitalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;capitalize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Capitalize&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should return '' for strings with length 0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;capitalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// other tests here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;reverseString(string)&lt;/code&gt; takes a string and returns it reversed. Below is a snippet of the test I wrote for a normal scenario.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/fatrixienicolieopetina/practice-jest-testing/blob/main/_js/tests/reverse-string.test.js" rel="noopener noreferrer"&gt;&lt;code&gt;reverse-string-test.js&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reverseString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;../reverse-string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should reverse normal strings&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;reverseString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;reverse&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;esrever&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;//other tests here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;A &lt;code&gt;calculator&lt;/code&gt; object that contains the basic operations: &lt;code&gt;add&lt;/code&gt;, &lt;code&gt;subtract&lt;/code&gt;, &lt;code&gt;divide&lt;/code&gt;, and &lt;code&gt;multiply&lt;/code&gt;. The following test snippet below shows that the method will throw an error message if the divisor is zero.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/fatrixienicolieopetina/practice-jest-testing/blob/main/_js/tests/calculator.test.js" rel="noopener noreferrer"&gt;&lt;code&gt;calculator.test.js&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;calculator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../calculator&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//other tests here&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should throw an error if divisor is 0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;divide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toThrow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cannot divide by 0&lt;/span&gt;&lt;span class="dl"&gt;"&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;ul&gt;
&lt;li&gt;
&lt;code&gt;caesar cipher&lt;/code&gt;. A caesar cipher is a substitution cipher where each letter in the text is shifted a certain places number down the alphabet. More info can be read &lt;a href="http://practicalcryptography.com/ciphers/caesar-cipher/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One thing to remember from this part of the exercise is that it is not needed to explicity test the smaller functions, just the public ones. If the larger function works then it must be the case that the helper methods are functioning well.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/fatrixienicolieopetina/practice-jest-testing/blob/main/_js/tests/caesar-cipher.test.js" rel="noopener noreferrer"&gt;&lt;code&gt;caesar-cipher.test.js&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;caesar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../caesar-cipher&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//other tests here&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wraps&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;caesar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Z&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;works with large shift factors&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;caesar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;75&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ebiil, Tloia!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;works with large negative shift factors&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;caesar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;29&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ebiil, Tloia!&lt;/span&gt;&lt;span class="dl"&gt;'&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;ul&gt;
&lt;li&gt;Array Analysis. This function takes an array of numbers and returns an object with the following properties: &lt;code&gt;average&lt;/code&gt;, &lt;code&gt;min&lt;/code&gt;, &lt;code&gt;max&lt;/code&gt;, and &lt;code&gt;length&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/fatrixienicolieopetina/practice-jest-testing/blob/main/_js/tests/array-analyze.test.js" rel="noopener noreferrer"&gt;&lt;code&gt;analyze.test.js&lt;/code&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;analyze&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../analyze&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;analyze&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should return correct average&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;average&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should return correct min&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// other tests here&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check out the github repository of the included snippets in &lt;a href="https://github.com/fatrixienicolieopetina/practice-jest-testing" rel="noopener noreferrer"&gt;here&lt;/a&gt; for a complete picture of the tests.&lt;/p&gt;

&lt;p&gt;The concepts and points above are the very basics of TDD using Jest. There are a lot more to learn, from more advanced matchers, mocking, testing asynchronous parts of the code, and others.  I am still to learn them and that is for another dev post 😆.&lt;/p&gt;

&lt;p&gt;Cheers to continued learning! 🍷&lt;/p&gt;

&lt;h3&gt;
  
  
  [REFERENCES]
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="http://godswillokwara.com/index.php/2016/09/09/the-importance-of-test-driven-development/" rel="noopener noreferrer"&gt;The Importance of TDD&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.theodinproject.com/paths/full-stack-javascript/courses/javascript/lessons/testing-basics" rel="noopener noreferrer"&gt;TOP Testing Basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jestjs.io/docs/getting-started" rel="noopener noreferrer"&gt;Jest Getting Started Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jestjs.io/" rel="noopener noreferrer"&gt;Jest Official Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>webdev</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Core Concepts behind Java OOP</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Tue, 29 Jun 2021 00:43:25 +0000</pubDate>
      <link>https://dev.to/pat_the99/core-concepts-behind-java-oop-2dom</link>
      <guid>https://dev.to/pat_the99/core-concepts-behind-java-oop-2dom</guid>
      <description>&lt;h2&gt;
  
  
  [Java WIL🤔#1]
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;I am reviewing for an Oracle Java Certification exam and decided to run through the documentation of Java's Nuts and Bolts. Check out the github repository for other &lt;a href="https://github.com/fatrixienicolieopetina/java-1z0819" rel="noopener noreferrer"&gt;review bullet points&lt;/a&gt;. Here are my notes for the core concepts behind Java's object-oriented programming (OOP).&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  📌 What are Objects
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;An object is a software bundle of related state and behavior. Software objects are often used to model real-world objects found in everyday life&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Real world observations all translate into the world of object-oriented programming. Real-world objects share two characteristics, they all have &lt;strong&gt;&lt;em&gt;state&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;behavior&lt;/em&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Software objects are conceptually similar to real-world objects; they too, consist of state and related behavior. An object stores its state in &lt;strong&gt;fields&lt;/strong&gt; and exposes its behavior through &lt;strong&gt;methods&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Methods&lt;/strong&gt; operate on an object's internal state and serve as the primary mechanism for object-to-object communication.&lt;/li&gt;
&lt;li&gt;Hiding internal state and requiring all interaction to be performed through an object's method is known as &lt;strong&gt;data ecapsulation&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;By attributing state and providing methods for changing that state, the object remains in control of how the outside world is allowed to use it.&lt;/li&gt;
&lt;li&gt;Building code into individual software objects provide a number of benefits, including:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Modularity&lt;/strong&gt; : The source code for an object can be written and maintained independently of the source code for other projects. Once created, an object can be easily passed around inside the system.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Information Hiding&lt;/strong&gt;. By interacting only with an object's methods, the details of its internal implementaion remain hidden from the outside world.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code reuse&lt;/strong&gt; : If an object already exists (might have been written by another programmer), that can be used in the program. This allows specialists to implement/test/debug complex, task-specific objects, which can then be trusted in your own code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pluggability and Debugging Ease&lt;/strong&gt; . If a particular object turns out to be problematic, it can simply be removed from the application and plug in a different object as a replacement. Similar to fixing a mechanical problem in the real world, if a bolt breaks, it can be replaced, but not the entire machine.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 What are Classes
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A class is a blueprint or prototype from which objects are created.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;In real world, many individual objects have the same kind, i.e. they are built from the same set of blueprints and therefore contains the same components.&lt;/li&gt;
&lt;li&gt;In object-oriented terms, a &lt;code&gt;class&lt;/code&gt; is the blueprint from which individual objects are created.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 What is Inheritance
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Inheritance provides a powerful and natural mechanism for organizing and structuring software.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Different kinds of objects often have a certain amount in common with each other. Yet, each also defines additional features that make them different. &lt;/li&gt;
&lt;li&gt;OOP allows classes to inherit commonly used state and behavior from other classes. &lt;/li&gt;
&lt;li&gt;In Java, each class is allowed to have &lt;strong&gt;one direct superclass&lt;/strong&gt; and each superclass has the potential for an &lt;strong&gt;unlimited number of subclasses&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 What are Interfaces
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Methods form the object's interface with the outside world. &lt;/li&gt;
&lt;li&gt;In its most common form, an interface is a group of related methods with empty bodies.&lt;/li&gt;
&lt;li&gt;Implementing an interface allows a class to become more formal about the behavior it promises to provide. &lt;/li&gt;
&lt;li&gt;Interfaces form a &lt;strong&gt;contract&lt;/strong&gt; between the class and the outside world and this contract is enforced at &lt;strong&gt;build time by the compiler&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;If the class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  📌 What are Packages
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A package is a namespace for organizing classes and interfaces in a logical manner. Placing code into packages makes large software projects easier to manage.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;A package is a namespace that organizes a set of related classes and interfaces. Conceptually they are similar to folders in a computer. &lt;/li&gt;
&lt;li&gt;Because the program might be composed of hundreds and thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages.&lt;/li&gt;
&lt;li&gt;The Java platform provides an enormous class library (a set of packages) suitable for use in applications. This library is known as the &lt;strong&gt;"Application Programming Interface (API)"&lt;/strong&gt;. Its packages represent tasks most commonly associated with general-purpose programming. The &lt;a href="https://docs.oracle.com/javase/8/docs/api/index.html" rel="noopener noreferrer"&gt;Java Platform API Specification&lt;/a&gt; contains the complete listing for all packages, interfaces, classes, fields and methods supplied by the Java SE plaform.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  ❓ Quiz Time
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;  &lt;em&gt;These questions are the review questions in the &lt;a href="https://docs.oracle.com/javase/tutorial/java/concepts/QandE/questions.html" rel="noopener noreferrer"&gt;Java documentation&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
  Real-world objects contain ❓ and ❓.
  &lt;em&gt;Real-world objects contain &lt;strong&gt;states&lt;/strong&gt; and &lt;strong&gt;behaviors&lt;/strong&gt;.&lt;/em&gt; 


  A software object's state is stored in ❓.
  &lt;em&gt;A software object's state is stored in &lt;strong&gt;fields&lt;/strong&gt;.&lt;/em&gt; 


  A software object's behavior is exposed through ❓.
  &lt;em&gt;A software object's behavior is exposed through &lt;strong&gt;methods&lt;/strong&gt;.&lt;/em&gt; 


  Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as ❓.
  &lt;em&gt;Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as &lt;strong&gt;data encapsulation&lt;/strong&gt;.&lt;/em&gt; 


  A blueprint for a software object is called a ❓.
  &lt;em&gt;A blueprint for a software object is called a &lt;strong&gt;class&lt;/strong&gt;.&lt;/em&gt; 


  Common behavior can be defined in a ❓ and inherited into a ❓ using the ❓ keyword.
  &lt;em&gt;Common behavior can be defined in a &lt;strong&gt;superclass&lt;/strong&gt; and inherited into a &lt;strong&gt;subclass&lt;/strong&gt; using the &lt;strong&gt;&lt;code&gt;extends&lt;/code&gt;&lt;/strong&gt; keyword.&lt;/em&gt; 


  A collection of methods with no implementation is called an ❓.
  &lt;em&gt;A collection of methods with no implementation is called an &lt;strong&gt;interface&lt;/strong&gt;.&lt;/em&gt; 


  A namespace that organizes classes and interfaces by functionality is called a ❓.
  &lt;em&gt;A namespace that organizes classes and interfaces by functionality is called a &lt;strong&gt;package&lt;/strong&gt;.&lt;/em&gt; 


  The term API stands for ❓ ?
  &lt;em&gt;The term API stands for &lt;strong&gt;Application Programming Interface&lt;/strong&gt;.&lt;/em&gt; 

&lt;/p&gt;

&lt;h3&gt;
  
  
  [REFERENCES]
&lt;/h3&gt;

&lt;p&gt;[1] &lt;a href="https://docs.oracle.com/javase/tutorial/java/concepts/index.html" rel="noopener noreferrer"&gt;Java OOP Concepts&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
      <category>codenewbie</category>
      <category>todayisearched</category>
    </item>
    <item>
      <title>Coding is NOT not for girls.</title>
      <dc:creator>patricianicole</dc:creator>
      <pubDate>Mon, 21 Jun 2021 16:12:49 +0000</pubDate>
      <link>https://dev.to/pat_the99/coding-is-not-not-for-girls-6l9</link>
      <guid>https://dev.to/pat_the99/coding-is-not-not-for-girls-6l9</guid>
      <description>&lt;h2&gt;
  
  
  She Coded, 2021 👧
&lt;/h2&gt;

&lt;h3&gt;
  
  
  📌 My two cents
&lt;/h3&gt;

&lt;p&gt;It is a consensus that the IT industry is a male-dominated field. I know for a fact that most women are less inclined to pursue tech as a career - probably due to genetics, or because of society-imposed gender roles. &lt;/p&gt;

&lt;p&gt;Yes, it can be intimidating to approach and be part of a "mostly-guy" team because there will always be differences in interests. However, from experience,I have women workmates and classmates who are just as good as the guys from the team.&lt;/p&gt;

&lt;p&gt;When it comes to work, I think about it like this. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Both men and women have two hands. Both of them have brains and two eyes. Aren't those enough to code? Last time I checked, there is no &lt;code&gt;gender&lt;/code&gt; requirement in coding and people should internalize that. Coding is not, not for girls. Coding is not, not for guys. &lt;strong&gt;Coding is for people who likes to code, whether that be for a living, or as a hobby 💁.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  💻 And thus, I started coding.
&lt;/h4&gt;

&lt;p&gt;Honestly, at first, I am not very interested in programming. I entered computer science just because it was the most feasible choice for me that time. It is not taught in my high school so I was a little behind from my college classmates who had programming classes already. Our class composition was around 40% girls, 60% boys. I think I can say that all of them are equal in terms of programming skills. There is no such time that I have had thoughts of a classmate being good in programming because he is a boy. Our computer science lessons were tough for me, not because I am girl, but because I came from a high school with no programming background. &lt;strong&gt;Nevertheless I tried coding and coding&lt;/strong&gt;. After graduation, I think I can say I was able to keep up with my classmates. &lt;em&gt;(Hi classmates 👋! XD.)&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  💌 To the SheCoders,
&lt;/h3&gt;

&lt;p&gt;The world is changing now. There are very few role models for women in tech and that also needs to change. Role models are important to help young girls dream and imagine themselves in certain fields, like IT. Many girls are probably good at coding (remember &lt;a href="https://en.wikipedia.org/wiki/Margaret_Hamilton_(software_engineer)" rel="noopener noreferrer"&gt;Margaret Hamilton&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Ada_Lovelace" rel="noopener noreferrer"&gt;Ada Lovelace&lt;/a&gt;) but they are afraid of being the only elephant in the room or scared of being judged for their competency as girls. And there is no fun in constantly proving yourselves to others. So let us get out of our shells. All the best and I am rooting for every #shecoder, as a fellow.&lt;/p&gt;

&lt;h3&gt;
  
  
  💌 To the SheCoderAllies,
&lt;/h3&gt;

&lt;p&gt;These allies are one of the reason why women who are in tech have stick to there strengths and did not give up in the face of a tough environment. Thank you. Hiring tech talents without stereotypes is an incredibly good move. I believe you are not missing out on hiring and/or working together with the best people for the work, whether that be a guy or a girl.&lt;/p&gt;

&lt;h3&gt;
  
  
  💻 Choose to challenge
&lt;/h3&gt;

&lt;p&gt;As a #shecoder,&lt;br&gt;
📌 I will work hard everyday to improve my coding skills.&lt;br&gt;
📌 I will break into tech.&lt;/p&gt;

&lt;p&gt;Lastly, I suddenly remember a phrase I read a long time ago. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;IT is a strange field. As long as you have the skills, you are good to go.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And I think that tells us a lot.&lt;/p&gt;

</description>
      <category>wecoded</category>
      <category>womenintech</category>
    </item>
  </channel>
</rss>
