18 Ekim 2023 Çarşamba

LocalStack Kullanımı - AWS Emulator

Giriş
Açıklaması şöyle
LocalStack is a cloud service emulator that runs AWS services solely on your laptop without connecting to a remote cloud provider .
Docker
Örnek
Şöyle yaparız
docker run --rm -it 
  -p 4566:4566 
  -p 4510-4559:4510-4559 
 localstack/localstack
Açıklaması şöyle
When interacting with LocalStack to emulate AWS services it’s important to configure your AWS CLI or SDK to point to the LocalStack endpoint URL. This allows you to interact with LocalStack easily without having to specify the --endpoint-url option every time you run a command.

Another option is installing a tool called “awslocal” which is a wrapper around the AWS CLI for LocalStack. It automatically configures the CLI to use the LocalStack endpoint URL, saving you from the manual step of specifying the --endpoint-url option.


17 Ekim 2023 Salı

Eclipse Memory Analyzer Tool (MAT) Object Query Language (OQL)

Giriş
OQL penceresini Araç Çubuğunda bulunan OQL simgesine tıklayarak açarız

Örnek
Şöyle yaparız
SELECT DISTINCT 
  s.payload[9:12] AS FID, 
  s.payload[13:16] AS CID 
FROM com.foo.Packet s 

SELECT 
  s.payload[9:12] AS FID, 
  s.payload[13:16] AS CID, 
  s.payload.@length AS length 
FROM com.foo.Packet s 
Örnek - - Thread İsmi
Şöyle yaparız
select * from java.lang.Thread t where toString(t.name) = "HTTPS-Sender I/O dispatcher-1"
Şeklen şöyle. Thread ve ona ait tüm nesneleri gösterir.

16 Ekim 2023 Pazartesi

AtomicMarkableReference Sınıfı

Giriş
Şu satırı dahil ederiz.
import java.util.concurrent.atomic.AtomicMarkableReference;
Açıklaması şöyle.
Provides atomic operations for markable reference variables. The primary difference between AtomicReference and AtomicMarkableReference is the presence of the “mark” boolean in the latter. Internally it saves a Pair.of(value, mark).
Örnek
Şöyle yaparız
AtomicMarkableReference<String> ref = new AtomicMarkableReference<>("Initial", false);

System.out.println("Current Reference: " + ref.getReference());
System.out.println("Current Mark: " + ref.isMarked());

// Set a new reference with a mark
ref.set("Updated", true);
System.out.println("Updated Reference: " + ref.getReference());
System.out.println("Updated Mark: " + ref.isMarked());

// Compare and set reference and mark
boolean success = ref.compareAndSet("Updated", "NewValue", true, false);
System.out.println("Compare and Set Success: " + success);
System.out.println("Updated Reference: " + ref.getReference());
System.out.println("Updated Mark: " + ref.isMarked());


AtomicLongArray Sınıfı

Giriş
Şu satırı dahil ederiz
import java.util.concurrent.atomic.AtomicLongArray;
Açıklaması şöyle. AtomicIntArray sınıfı da benzer işlev görür
Provides atomic operations for arrays of long variables.

AtomicBoolean Sınıfı

Giriş
Şu satırı dahil ederiz
import java.util.concurrent.atomic.AtomicBoolean;
Java'da Atomic kelimesi ile başlayan şu sınıflar var. AtomicBoolean, AtomicInteger,  AtomicLong. Bu sınıflar ortak bir arayüz veya ata sınıftan kalıtmıyorlar.

Açıklaması şöyle
Provides atomic operations for boolean variables. 
Interesting fact: the internal type of Atomic Boolean stored in the volotile int field. This is because int is the smallest type CAS operations can be implemented across different machine types.
compareAndSet metodu - boolean expect +  boolean update
Açıklaması şöyle
Atomically compares the current value of the AtomicBoolean with the expect value. If they match, it updates the value to update. The method returns true if the update was successful, indicating that the value was changed; otherwise, it returns false.
Örnek
Şöyle yaparız. Nesnenin mevcut değeri true ise false yapar ve if koşulu çalışır. Mevcut değeri false ise hiçbir şey yapmaz ve if koşulu çalışmaz.
if (atomicBoolean.compareAndSet(true, false)) {...}
Örnek
Şöyle yaparız
AtomicBoolean flag = new AtomicBoolean(true);

// Reading the value
boolean currentFlag = flag.get();
System.out.println("Current Flag: " + currentFlag);

// Updating the value
flag.set(false);
System.out.println("Updated Flag: " + flag.get());

// Compare and set
boolean success = flag.compareAndSet(false, true);
System.out.println("Compare and Set Success: " + success);
System.out.println("Updated Flag: " + flag.get());

// Get and Set (returns the previous value)
boolean previousValue = flag.getAndSet(false);
System.out.println("Previous Value: " + previousValue);
System.out.println("Updated Flag: " + flag.get());
get metodu
Açıklaması şöyle
Returns the current value of the AtomicBoolean as a boolean.
getAndSet - boolean newValue
Açıklaması şöyle
Sets the value of the AtomicBoolean to the specified newValue and returns the previous value.
set metodu
Açıklaması şöyle
Sets the value of the AtomicBoolean to the specified newValue.
Örnek
Şöyle yaparız
private AtomicBoolean keepRunning = new AtomicBoolean(true);

keepRunning.set(false);

while (keepRunning.get()) {...}
Eğer istersek get() metodunu çağırmadan if ile de kullanabiliriz.
if(!keepRunning) {...}

15 Ekim 2023 Pazar

Math.clamp metodu

Giriş
Aynı metodlar StrictMath sınıfında da mevcut. İmzası şöyle
static int clamp(long value,
                 int min,
                 int max)

static long clamp(long value,
                  long min,
                  long max)

static float clamp(float value,
                   float min,
                   float max)

static double clamp(double value,
                    double min,
                    double max)

Character Sınıfı Emoji Metodları

Giriş
Açıklaması şöyle
Over the years, Emojis gained more and more properties, like different color shades and combined presentations. To make identification easier, the Character type gained 6 new static methods
isEmoji metodu
İmzası şöyle
boolean isEmoji(int codePoint)
Java 21 ile geliyor. Açıklaması şöyle
This method determines whether a character is considered an emoji based on its Unicode properties defined in Unicode Emoji (Unicode Emoji Technical Standard #51). For example, executing Character.isEmoji(9203) would return true for the character ⏳, which has the code point 9203.
Örnek
Şöyle yaparız
boolean isEmoji = Character.isEmoji(9203);
System.out.println(isEmoji);
isEmojiPresentation metodu
İmzası şöyle
boolean isEmojiPresentation(int codePoint)
Java 21 ile geliyor. Açıklaması şöyle
Similar to isEmoji(), this method checks if a character has the Emoji Presentation property. It helps identify characters that display as emojis when rendered.
isEmojiModifier metodu
İmzası şöyle
boolean isEmojiModifier(int codePoint)
isEmojiModifierBase metodu
İmzası şöyle
boolean isEmojiModifierBase(int codePoint)
isEmojiComponent metodu
İmzası şöyle
boolean isEmojiComponent(int codePoint)
 isExtendedPictographic metodu
İmzası şöyle
boolean isExtendedPictographic(int codePoint)