GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing javaevolved.dev — Standard Base64 encoding and decoding | java.evolved
Security
Beginner
Standard Base64 encoding and decodingUse java.util.Base64 instead of internal JDK classes or third-party codecs. Code Comparison
✕ Internal JDK API
String encoded = new sun.misc.BASE64Encoder()
.encode(data);
✓ Java 8+
String encoded = Base64.getEncoder()
.encodeToString(data);
See a problem with this code? Let us know.
Why the modern way wins
🛡️
Supported APIAvoids inaccessible sun.misc implementation classes. 🧩
Complete variantsIncludes basic, URL-safe, and MIME encoders and decoders. 🚀
No dependencyEncoding and decoding are built into the JDK. Old Approach
sun.misc encoder
Modern Approach
Standard Base64 API
Since JDK
8
Difficulty
Beginner
JDK Support
Standard Base64 encoding and decoding
Available
Widely available since JDK 8 (March 2014). How it works
The standard Base64 API provides basic, URL-safe, and MIME encoders and decoders without relying on unsupported internal packages. Use getEncoder() and getDecoder() for standard Base64, or select the URL and MIME variants when the target format requires them. Related Documentation
Proof
Related patterns
Security
Advanced
PEM encoding/decodingJava 8
String pem = "-----BEGIN CERTIFICATE-----\n"
+ Base64.getMimeEncoder()
.encodeToString(
cert.getEncoded())
+ "\n-----END CERTIFICATE-----";
Java 25 (Preview)
// Encode to PEM
String pem = PEMEncoder.of()
.encodeToString(cert);
// Decode from PEM
var cert = PEMDecoder.of()
.decode(pemString);
JDK 25+
→
Date/Time
Intermediate
HexFormatJava 8
// Pad to 2 digits, uppercase
String hex = String.format(
"%02X", byteValue);
// Parse hex string
int val = Integer.parseInt(
"FF", 16);
Java 17+
var hex = HexFormat.of()
.withUpperCase();
String s = hex.toHexDigits(
byteValue);
byte[] bytes =
hex.parseHex("48656C6C6F");
JDK 17+
→
Strings
Beginner
String chars as streamJava 8
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (Character.isDigit(c)) {
process(c);
}
}
Java 9+
str.chars()
.filter(Character::isDigit)
.forEach(c -> process((char) c));
JDK 9+
→
|
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |