Logging AOP Implementation - 1

Introduction Logging is not code for handling business logic, but rather for monitoring. That’s why logging appearing in the middle of business logic is very uncomfortable to see. Spring provides AOP, but I wanted to try implementing it myself without looking at Spring’s implementation. So, this time, I want to think about how to implement a great logging AOP. Situation Let’s write a sayHello method in the Person class and call it from main. Here, let’s assume the person object is provided by a framework. ...

September 19, 2021

Closure

Introduction Let’s look up the word ‘closure’ in English. Dictionary: an act or process of closing something, especially an institution, thoroughfare, or frontier, or of being closed. It means ’to close’. So, when I first studied closures, it didn’t make sense to me. What is being closed? Today, let’s lift the veil! The Concept of Closure Lambda calculus is a concept from the 1930s, and closure is from the 1960s. ...

August 8, 2021

Lazy Evaluation

Introduction The concept of lazy evaluation is not difficult. So, this time, I will focus on its usefulness. Background Knowledge If you are confused between expression and evaluation, please refer to the following article: https://jurogrammer.tistory.com/129 Definition Lazy evaluation is a strategy where the evaluation of an expression is delayed until its value is needed. It is usually used to improve performance. Let’s see how delaying evaluation can improve performance. Example of Performance Improvement Here is an example where a value is only used if a certain condition is met. ...

August 8, 2021

Java - Exception Handling (Code)

Parent Topic Exception handling journey Situation Here is some smelly code I used incorrectly. Situation A function receives an order number and returns the corresponding order sheet. If the requested order number does not exist, an error should be raised and the client should be notified that the order does not exist. Code Controller 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 package com.company.exceptiontest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Controller { private final Service service; private final Logger logger = LoggerFactory.getLogger(this.getClass()); public Controller(Service service) { this.service = service; } public String orderInfo(Long id) { try { OrderSheet orderSheet = service.searchOrderSheet(id); return String.valueOf(orderSheet); } catch (CustomException e) { logger.info("controller - orderInfo method: Error occurred while requesting order sheet info!"); e.printStackTrace(); return e.getMessage(); } } } In the controller, the order sheet information is returned as a string. If an error occurs, it is caught, logged, and the error message is returned to the user. ...

August 8, 2021

Exception handling - Java Exception Handling (Theory)

Parent Topic Exception handling journey References clean code effective java oracle java docs This time, let’s talk about what an exception is and how to handle exceptions. What is an exception? Let’s see how Oracle defines it: An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions. It means an event that disrupts the normal flow during program execution. ...

August 8, 2021

Exception handling journey - Redirection

Parent Topic Exception handling journey References https://opentutorials.org/course/2598/14199 https://en.wikipedia.org/wiki/Standard_streams https://en.wikipedia.org/wiki/Redirection_(computing) Definition Redirection is a form of interprocess communication (IPC). It is a function that most command line interpreters have. This is the method that came up when I wondered how data entered in the console is delivered to the app. Cat Actually, the definition and explanation are so well explained by Life Coding, so I’ll just link to it. https://opentutorials.org/course/2598/14199 Java What I want to test is how Java handles input and output. I want to know when stdin, stdout, and stderr are used. ...

July 3, 2021

From Keyboard Input to Console Output

Parent Topic Exception handling journey Situation - Simple Input/Output Program The app receives input from the keyboard. The app prints the input value to the console. This app is run from the console. Additionally, to analyze the process in detail, the program also prints the pid. Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public class App { public static void main(String[] args) { printPid(); Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { System.out.println(scanner.next()); } } private static void printPid() { long pid = ProcessHandle.current().pid(); System.out.println("current pid: " + pid); } } Execution After compiling the code above in the console, run it in iterm. ...

July 3, 2021

Exception handling journey

First Step An exception can be seen as an abnormal situation. Excerpt from Oracle docs An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program’s instructions. Therefore, developers should provide exception messages so that they can understand the situation when an exception occurs. Also, a client who calls the API should be given a different message from the developer. ...

July 3, 2021

Functional Implementation of the Decorator Pattern

Motivation This time, the introduction is a bit long… Feel free to skip it. It all started with trying to understand the concept of flux. So, I was implementing a brick breaker game using redux + canvas. (Somehow, after some trial and error, I found that I could use redux without react.) Problem - I want to notify only the relevant renderer when the state changes. In redux, when the state changes, the rendering logic subscribed to a specific state change is executed. ...

June 19, 2021

Implementing a Data Table

Let’s Make a Data Table In the field, not only do I develop servers, but I also occasionally work on admin pages. Even if you don’t know much about the front end, you can develop them using jQuery. However, there was a need to improve performance… Let me share the process of improving it. Final result: https://jsfiddle.net/who3fa7t/2/ Problem I had to display about 5000 rows * 13 columns on a single screen without paging. ...

June 1, 2021