Tag: java

NPE-safe String Comparisons, And More…

For the longest time I recall I’ve always been prone to do this when doing String comparisons* in Java… …And furthermore, I often find myself using the .equalsIgnoreCase() method. (Yes, considering that the requirements does not care about the letter case.) There is really nothing wrong with this way of checking if the string values…

continue reading
No Comments

Rewriting Nested If/Else

An often overlooked (perhaps) way to write cleaner if condition statements. This is not about having to go through all the refactoring into a Factory pattern, Switch statements, and other possible conditional logic methods just to avoid our classic if condition. Rather merely making it look better, when the scenario is right for it. Of…

continue reading
No Comments

A Multiple Of 3 or 5?

Saw this problem on the Internet about Multiples. Thought I might solve it. Don’t know why I dislike these kinds of things, but still want to try to solve it. It always seems tricky, although elementary? For transparency I only reviewed the Maths definition of a Multiple just to make sure if memory has not…

continue reading
No Comments

Not Loading Java Beans on Boot

Java Beans are eagerly created in Spring Boot applications by default. That includes dependency beans. This is something I need to remember always. I tend to forget it and take it for granted since Spring Boot is great at spoiling Java developers. While that is a boon in most times, it can easily become a…

continue reading
No Comments

Chaining Profiles and Additional Documents

Just recently I have been playing around with multiple active profiles. This is apart from having the main application config, plus the profile that matches the environment on which the application is running. That is quite commonplace. Instead I’m talking more of an additional profile that gets activated aside from the environment profile based on…

continue reading
No Comments

Divide A List To Sub-Lists Via Collectors

Consider a List of Color objects with attributes of index, name and group. This object is defined as, Group is simply an Enum of, My list of colors are the following, Now, I want to divide these colors into their own sub-lists of color grouping based on the value of the object’s Group attribute. Traditionally,…

continue reading
No Comments

Spring Boot Apps With Spring Cloud Config

It is not uncommon for a Java application to have a number of properties that needs to be defined for it to to run smoothly at start. While these configurable parameters that are required by the app can be set in the code, placing those outside is a more logical and cleaner approach. Things like…

continue reading
No Comments

Rewriting Nested Ifs With Java 8 Stream

Say I have these numbers in an array, for example: I want to do something with that set of numbers, such as taking out null values, and extracting only the odd ones. Too take it further, maybe I want an even number or two mixed in the processed list as well. So I have this…

continue reading
No Comments

Simple SQL Query Builder

Did a simple, customized SQL query builder that’s only specific for UPDATE statements some time early last year. Thought I’d just write it down here. It was a smaller part of a bigger application. It wasn’t required for all update cases, but a number of them did. I’ve mostly re-written it from memory. It should…

continue reading
No Comments

Thymeleaf Basics In Spring Boot

I recently started on the path on building content on the fly that gets sent out as soon as possible, using a template engine, but from a back-end perspective. If that makes sense? This is for an event-driven application that sits there and listens for incoming messages. A simple one. Consume the message as soon…

continue reading
No Comments

When API Response Is In Array

From time to time I get some of this odd API response from requesting information for a specific something. I expect the response data to be a simple JSON object. Instead I am looking at a JSON array. I suppose that is still simple enough and it’s not so odd. This kind of response happens…

continue reading
No Comments

Nested Java Bean Validation

Somebody asked me recently why their POJO validator was not working as expected. They had already followed the “code I wrote” down to a T. Emphasis on the quotes, because trust me that block of code for bean validation they used as reference from an older project I did, was pretty much a very trivial…

continue reading
No Comments

Quickly Get JSON Values Via Jayway JsonPath

There is this Java library that I utilize to quickly get values from JSON objects that is fairly easy to use. This would be Jayway JsonPath. More can be had at their GitHub page. It is still being actively maintained. There appear to be a number of contributors involved in this project at different points…

continue reading
No Comments

Spring OAuth2 Using Password Grant Type With Additional Headers Continued

Part 2 – Accessing a Resource Recap This is a continuation of the previous post that I made some time last month. You can start reading from there to get more context – https://www.joseyamut.xyz/2021/02/24/spring-oauth2-using-password-grant-type-with-additional-headers The first part dealt with getting the access token from a 3rd party token service provider using a password grant. The…

continue reading
1 Comment

Spring OAuth2 Using Password Grant Type With Additional Headers

Part 1 – Getting the Access Token In this example, I am using the older Spring Security library which is: spring-security-oauth2 The JAR file can be found at Maven public repositories here. Dependency For my case, I am specifically using the release version below because I am trying to match some limitations (Such as what…

continue reading
1 Comment