devxlogo

Java

Working with Multi-line Text

Starting with JDK 13, we can define multi-line strings using “”” as follows: String text = “””some textsome textsome text”””;

Setting a Proxy in Java

Let’s assume that we have a proxy at address proxy.host:8888. We can set up this proxy via the JDK 11 HttpClient as follows: HttpClient client = HttpClient.newBuilder() .proxy(ProxySelector.of(new InetSocketAddress(“proxy.host”, 8888)))

Using Enum Effectively

Learn how to use enum effectively in a switch case block. There are multiple advantages to not making any mistakes since the originals are defined in the enum. public class

Working with the StringJoiner Class in Java

The StringJoiner class helps in formatting strings when there are multiple values and you want to present them with some delimiter and some pre and post suffixes. The delimiter, pre

Quick Approach to Creating a Custom RuntimeException

The quickest way to create a custom RuntimeException is as follows (simply extend RuntimeException): public class IncorrectFileException extends RuntimeException { public IncorrectFileException(String errorMessage, Throwable err) { super(errorMessage, err); }}

Moving a Folder in Java

The move method accepts three arguments. The 1st and 2nd being the source and target Path attributes and the 3rd being the replace option. import java.nio.file.*;import static java.nio.file.StandardCopyOption.*;public class FileMove{

Syntax for Unicode Escapes in Java

In addition to the string and character escape sequences, Java has a more general Unicode escaping mechanism, as defined in JLS 3.3. Unicode Escapes. A Unicode escape has the following