Petre Popescu Dev Blog

2

Masking log output in Log4j2

Users are demanding more and more privacy and as a web developer, you have to make sure that sensitive information does not get leaked as best as you can. Most of you have good security measures set in place that protect from most common attacks, however, one part of the application that is usually neglected are the logs. This is because logs are usually meant to remain internal. This is not always the case and even if it was, if...

2

An argument for using Optional as input parameters

This article may be the hardest I wrote so far here. Not because it is really technical nor because it required a lot of research prior, but because it is controversial and I had to be sure that the arguments I will present here are good. Still, I know that some will not agree with me. So let’s get down to business. There is an ongoing debate in the Java community regarding Optional and if it should be used as...

0

Intercepting and manipulating requests in Play Framework

There are situations when you have to intercept all requests coming into your application in order to do some processing prior to handling the request or doing some cleanup after it was handled. A good example that I usually give, and one that is widely used in many applications, is fishtagging for logging. This is when you write a unique identifier in the thread context and all messages are logged under the same tag (or NDC, as it was formally...

0

Using lazy-loading in JPA to speed up your application

Hibernate makes working with the database a lot easier. You just need to define your entities and the library does the job of retrieving data or persisting your objects. This is true for all modern JPA libraries, like Hibernate or Spring Data. The more complex you have your objects, the more the benefits of using such libraries. However, there is a big downside to this approach and one that can make your application feel slow or sluggish. An example of...

0

An introduction to using generics in Java

I recently worked on a few benchmarks for a database and while coding it used the power of generics to write as little code as possible. In the benchmark, I had two different DAO classes and corresponding Domain Objects that were identical, with the exception of the ID field. I could write everything twice, but there is no fun in that. Instead, I wrote generic classes that accepted the ID as a type parameter. Generics is one of the most...

0

Crawling and Parsing a Website in Java using JSoup

There are many scenarios where you would need to parse the contents of a website to extract data. Search engines do this, certain applications require this functionality in order to extract information, there are integration tests that need this and even some tools must have this functionality. In this article, I will be showing how to build a website crawler in Java and how to parse the website’s content and extract information from it. Building the entire parser is quite...

0

5 simple coding tricks to make your application more stable

The stability of your application or web service is important for both you and the user. Making things resilient is not easy, but there are a few coding tricks that you can use in order to increase stability and help you solve problems easier and faster. Here are 5 simple coding tricks that will make your application more stable, will reduce errors and will make you a better coder. Comparing with a static String In many applications you will need...

0

Writing unit tests in Java using jUnit and Mockito

Testing is important for all software systems and applications. It will help you easily find bugs and it will prevent crashes and downtimes for your application, especially if the system evolves over time. At first it may not seem critical, but as the system grows and becomes more complex, the likelihood of a bug appearing without being noticed grows. There are multiple testing frameworks available for Java, with jUnit being one of the most widely used. In this article, we...

0

Cleaner Data classes with Project Lombok

One thing that I like about Java is the vast amount of libraries that are freely available. There is a library or code snippet for almost anything that you could think of or any mundane or repetitive task out there. Data classes are no exception. All applications rely on data and the presence of data classes is widespread, however, they are usually quite simple, but can take up a lot of time, especially if you have many fields. Luckily, there...

0

Designing Twitter Part 1: Introduction

This will be the first article in a series where I will be designing a Twitter clone. By “design”, I don’t mean the actual interface, but the way such a system will be built, what micro-services will it have, how will they interact with one another, and more. In other words, the system architecture. These articles will explain the system design of such a service and how I think that it should be made. Tools of trade I don’t know...