Home » Java » Page 2

Java

Functional Decomposition

Why Do I Have To Have A Function? function giveBonus(currentYear, price) { if ((currentYear % 4 === 0) && price > SUPER_THRESHOLD) { return SUPER_BONUS; } return price > BASIC_THRESHOLD ? NORMAL_BONUS : 0; } The above is a small function that gives a bonus. So why should I need more sub-functions? Personally, I’d probably hope to make the above ...

Read More »

Calling Google Cloud Services in Java

If you want to call Google Cloud Services using a Java based codebase, then broadly there are two approaches to incorporating the client libraries in your code — the first, let’s call it a “direct” approach is to use the Google Cloud Client libraries available here, the second approach is to use a “wrapper”, Spring Cloud GCP libraries available here. ...

Read More »

React Version Stamping Recipe

My view on version numbering is that we should take the build time and git SHA of our code and pass it through to the build as a version identifier. Then we can easily look at any stamped version of our application and find where it came from. To me, this is more powerful than stamping an arbitrary release number ...

Read More »

Serverless Spring is Quite Bouncy

I’ve written a couple of articles about AWS Lambda I showed how to use Hibernate in AWS Lambdas over on BaeldungI also showed a full alternative to Spring for an enterprise-grade set upThen I’ve discussed how the size of Log4j can make a Lambda start up more slowlyI’ve even complained about Oracle making a huge Java library for MySQL It’s ...

Read More »

The Chimera Function

I’ve written before about a function that essentially does two different versions of the same thing. It’s sort of cute to think that we can pass a boolean into a function to control whether it uses variant A or variant B of the algorithm. There can be milder forms of this too. Perhaps we pass in a boolean to ask the ...

Read More »

Comments Suggesting Refactoring

Allow me to share with you one of my favourite refactorings. This comment in the code indicates a missing extract method refactor A simple example: const customer = getCustomer(); // find the customer's discount rate const customerPoints = customer.loyaltyPoints + customer.weeklyPoints; const discountRate = customerPoints > 100 ? 0.1 : 0; return price - (price * discountRate); The interesting part ...

Read More »

Insane AWS Lambda Speed Up

java-interview-questions-answers

What makes this post annoying is that we’ve suffered from a slow Lambda cold start for a very long time, and the solution was literally a few seconds’ work. I’ve written before about reducing bloat in Lambdas, especially the MySQL driver. However, the JVM is still quite slow to start. I’ve learned to package AWS Lambdas using ZIP, rather than ...

Read More »

Which is better: A monolithic Kafka cluster vs many?

java-interview-questions-answers

Apache Kafka is designed for performance and large volumes of data. Kafka’s append-only log format, sequential I/O access, and zero copying all support high throughput with low latency. Its partition-based data distribution lets it scale horizontally to hundreds of thousands of partitions. Because of these capabilities, it can be tempting to use a single monolithic Kafka cluster for all of ...

Read More »

How to Reduce Cloud Cost by 99% for EDA Kafka Applications

java-interview-questions-answers

While the cloud offers great convenience and flexibility, the operational cost for applications deployed in the cloud can sometimes be significant. This article shows a way to substantially reduce operating costs in latency-sensitive Event-Driven Architecture (EDA) Java applications by migrating from Kafka to Chronicle Queue open-source, a more resource-efficient and lower-latency queue implementation. What is EDA? An EDA application is ...

Read More »