mkyong.com mkyong.com

Java SSLSocket TLS 1.3 example

This Java 11 JEP 332 adds support for TLS 1.3 protocol. SSLSocket + TLS 1.3 An SSLSocket client with TLS1.3 protocol and TLS_AES_128_GCM_SHA256 stream cipher, to send a request to https://google.com and print the response. JavaTLS13.java package com.mkyong.java11.jep332; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import java.io.*; // Java 11 public class JavaTLS13 { private static final...

mkyong.com mkyong.com

Java 11 shebang example in Docker

In Java 11, JEP 330 adds support to run single-file source code directly. Terminal # Before Java 11 $ javac Hello.java $ java Hello # Now Java 11 $ java Hello.java This indirectly supports the Java single-file program to run as a script using Unix Shebang. For example, run below .sh file will print Hello World!. run.sh #!/opt/java/openjdk/bin/java --source 11 public class SheBang { public static void main(String[]...

mkyong.com mkyong.com

Java - What is serialVersionUID

In Java, serialVersionUID is something like version control, assure both serialized and deserialized objects are using the compatible class. For example, if an object saved into a file (Serialization) with serialVersionUID=1L, when we convert the file back to an object (Derialization), we must use the same serialVersionUID=1L, otherwise an InvalidClassException is thrown. Terminal Exception in thread "main"...

mkyong.com mkyong.com

Java - What is transient fields?

In Java, transient fields are excluded in the serialization process. In short, when we save an object into a file (serialization), all transient fields are ignored. 1. POJO + transient Review the following Person class; the salary field is transient. public class Person implements Serializable { private static final long serialVersionUID = 1L; private String name; private int age; // ignore this field ...