In this tutorial we will create a Spring Server that will manage a Person repo and support PUT, POST, GET, and DELETE operations. The Spring framework allows us to quickly spin up a backend server for our application.
First let’s set up the basic Spring App, if you have Intellij, you can just select Spring boot and add the Spring Web and Spring devtools options. If you are just using Maven, here is what my POM dependencies look like.
</dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion>…
Reflect is a little know java library that lets you edit fields and invoke methods of a given object of a class. Maybe you are thinking
“Whats so cool about that, I thought I could already call class methods and reference their variables?”
Well what if I told you that this library ALSO allowed you to access private fields and methods 😲!!!
Yes, it is true, you can access the private methods of a class OUTSIDE THAT CLASS!!! That is why I consider it black magic 🧙♂️.
Ok but why would you want to use this? If you want to…
The Singleton Pattern is used when you only want one instance of an object at a time.
An example when this pattern is useful is for an access point to a database 💾. In an app, it is beneficial to have one entry point to the database as opposed to multiple entry points (like what would happen with a regular class with a constructor).
Testing is a very important part of coding, 📈 Test driven development is a very popular way of testing where you write test code before you actually write any ACTUAL code 😲.
A Test is supposed to ISOLATE one function of one service and make sure it works ✅. However, when this service depends on other services, it can be hard to isolate that one section and verify any error is coming from that service😞.
Here is an example of WHY we NEED to mock
To understand what the factory pattern is and why it is useful, I will use a simile. Imagine you are a dealership and want to order some cars for your dealership. you have two options…
The first option is akin to the old way of instantiating objects (i.e. a class…
You know that old saying
“If you fall of the horse, dust yourself off and get back on”
It actually has a lot of application when designing and writing software. Occasionally, there are processes or workflows that will fail. What would you do in these cases? Some programmers will simply say
“Not my fault, I called this service and it failed me so I am just going to give an error message to the user and have THEM restart the workflow”
This is undesirable, even if the service works 99% of the time — when it fails — it will…
You might be looking at this and thinking
“Why should I limit my application’s performance? I want my application to load and perform as fast as possible so I shouldn’t limit my API calls”
Well, you’re right and you’re wrong
You shouldn’t arbitrarily limit your API calls that is true. However, sometimes — for large applications — it may be necessary to limit your API calls to avoid being throttled by the API.
Throttling as defined by Adobe as
a process that is used to control the usage of APIs by consumers during a given period. You can define throttling…
Introducing, the black magic that is the objectMapper. This library is the go to, state of the art, hands down #1 place to go for translating Json to a java class and vis-versa.
Here is the link to the library if you want to dive deep in all the things you can do with ObjectMapper.
In this short tutorial, we will show how powerful the ObjectMapper is by serializing to and from a Classroom java object — which itself will contain a List of Person Objects — so there will be a decent level of complication since our Classroom is…
In big 💪, fast 🏃♂️, and complicated ⁉️ codebases, there is a substantial amount of processing that needs to be done. Doing all of that processing synchronously (one after another) will increase the time 🕐 the code needs to execute.
A good way to get around this problem is to do some of these processes asynchronously when they do not depend on each other.
Best practice Involves using a Thread Pool and wrapping your tasks in a Runnable (does not return anything) or a Callable (does return something).
In this tutorial, we will see how we can speed up our…
JSON is used in many applications to store and send data, the ability to parse and read this data is very important on your journey to becoming a skilled programmer. Before I knew about ObjectMapper, I would manually search for fields in a JSON by doing.
String myVal = json.substring(json.indexOf(field)+ 1, lengthOfVal)
This is a gross and error prone way to get values from a JSON and when a senior dev on my team saw me doing this they showed me the light 🌤️. (The light being Jackson ObjectMapper)
I am a software engineer working for Amazon living in SF/NYC.