Base64 (in java.util) provides encoding and decoding of binary data to and from Base64 representation, which is a way to encode binary data using only ASCII characters. This is useful for transmitting binary data over media designed to handle text.


Scenarios


Sample Usage

import java.util.Base64;

public class Base64Example {
    public static void main(String[] args) {
        String originalString = "Hello, Java!";
        
        // Encode
        String encodedString = Base64.getEncoder().encodeToString(originalString.getBytes());
        System.out.println("Encoded: " + encodedString);

        // Decode
        byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
        String decodedString = new String(decodedBytes);
        System.out.println("Decoded: " + decodedString);
    }
}

Output

Encoded: SGVsbG8sIEphdmEh
Decoded: Hello, Java!

Notes


Classes
Quiz
Videos
References
Books