KOTLIN / CATATAN</>↗Kotlin06 Mei 2025
In Kotlin, you can use default arguments and named arguments to simplify function calls and make your code more readable and flexible. Here’s how each of them works: Default Arguments Default arguments allow you to set a default value for a function parameter. If you don’t pass a value for that parameter when calling the […]
KOTLIN / CATATAN</>↗Kotlin06 Mei 2025
In Kotlin, defining and calling functions is straightforward and follows a clear syntax. Here’s how you can define and use functions: Defining a Function The fun keyword is used to define a function in Kotlin. Basic Syntax: fun functionName(parameters: ParameterType): ReturnType { // Function body return someValue // Optional if the return type is Unit […]
KOTLIN / CATATAN</>↗Kotlin06 Mei 2025
In Kotlin, you can use both for and while loops to iterate through items. Here is a quick overview of how you can use these loops with examples: 1. Using a for Loop A for loop is used to iterate through a range, array, list, or any iterable. Iterating through a range: for (i in […]
CONCURRENCY / CATATAN</>↗Concurrency06 Mei 2025
The LinkedBlockingQueue in Java is an implementation of the BlockingQueue interface, which is well-suited for implementing the Producer-Consumer problem. It manages a thread-safe queue where producers can add elements and consumers can take elements, with built-in thread synchronization. Here’s how you can implement a basic producer-consumer solution using LinkedBlockingQueue: Example: Producer-Consumer with LinkedBlockingQueue package org.kodejava.util.concurrent; […]
SPRING CORE / CATATAN</>↗Spring Core06 Mei 2025
Spring provides annotations like @Component, @Autowired, and @Qualifier to simplify dependency injection and make applications loosely coupled and modular. Below, we’ll explore these annotations in detail, focusing on their usage and a complete example. 1. @Component Annotation The @Component annotation marks a class as a Spring-managed bean. It is auto-detected during component scanning, and Spring […]
CONCURRENCY / CATATAN</>↗Concurrency06 Mei 2025
Coordinating tasks with Phaser in Java concurrency involves leveraging its powerful synchronization mechanism, especially designed for dynamic scenarios where the number of threads (or parties) may change during execution. The Phaser class found in the java.util.concurrent package provides a flexible and reusable barrier, similar to CyclicBarrier or CountDownLatch, but with added versatility. Key Features of […]