How to obtain/get copied image from clipboard data in browser

JS code works well for Chrome, Firefox and Safari

    const source = document.querySelector('.source');
    source.addEventListener('paste', (event) => {
        if (event.clipboardData && 
            event.clipboardData.items && 
            event.clipboardData.items.length == 1) {
                const item = event.clipboardData.items[0];
                if (item.kind == 'file' && item.type == 'image/png') {
                        let blob = item.getAsFile();
                        let f = new FileReader();
                        f.onload = (e) => {
                                console.log(e.target.result);
                        }
                        f.readAsDataURL(blob);
                }
        }
        event.preventDefault();
    });

Image source to data base64 url from clipboard data

JSCodeGetImageBlobFromClipboardData

How to add Lombok to your project : Lombok Dependency is missing

Lombok Dependency is missing

Lombok Dependency is missing

How to add Lombok to your project

Enable Anotation

Java learning: possible lossy conversion from int to short

fault code

 short s = 5; s = s - 2; 
 error: incompatible types: possible lossy conversion from int to short         s = s - 2;               ^ 1 error 

Correct code

 // why below line ok ? ask java compiler. s -= 2; s = (short)(s - 2); 

Java report error while c/c++ do not even display a warning message

in fact, c++ do the same things like Java do:
Automatic promotion of shot to int, but implicit the conversion.

Java learning: why float a = 5.6; compile error ?

why can't float a = 5.6; ?

 error: incompatible types: possible lossy conversion from double to float         float a = 5.6;                   ^ 1 error 

Cause

double is the default type of floating point number in java language.

Fix

 float a = 5.6f; 

Java learning: Hello World program with java

Recently, I begin to use java in my work. I used to c++ for more than 10 years.

Programmer start every thing begin with Hello World

public class HelloWorld {                                                       
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Java main function, must be in a public class

 public static void main(String[] args) {} 

Compile HelloWorld

javac HelloWorld.java

Execute HelloWorld

java HelloWorld
remember, not java HelloWorld.class
otherwise, you will got below error
Error: Could not find or load main class HelloWorld.class

Java learning : how many classes defined in java source, how many .class byte code files will be generated after compile via javac

One java source file generate one .class byte code file ?

False.
I thought one java source code file will generate only one .class byte code file, since I am a c++ programmer for about 10 years.
The correct answer is
how many classes defined in java source, how many .class byte code files will be generated after compile via javac
public class HelloWorld {
    class HelloInternal {
    }
}

enum HelloEnum {
}

interface HelloInterface {
}
javac HelloWorld.java
ls *.class
HelloEnum.class   HelloWorld$HelloInternal.class
HelloInterface.class  HelloWorld.class

Java classes

The classes can be any class, interface and enum.
All java codes should be placed in the classes.
otherwise you will get compile error
class, interface, or enum expected
In fact, enum is a class too, just a syntactic sugar.

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...