
Inspect Class Annotations
Class annotations can be inspected via reflection as follows: Class clazz = Foo.class;Annotation[] clazzAnnotations = clazz.getAnnotations();
Class annotations can be inspected via reflection as follows: Class clazz = Foo.class;Annotation[] clazzAnnotations = clazz.getAnnotations();
Returning a stream of int zero-extending the char values from a String can be done via chars(): String str = “hello world”;IntStream chars = str.chars();
Often, file sizes are too big to back them up or share them with someone. You can create a compressed version that will save you disk space, transfer time, etc. Java provides you with a zip package that can be handy here: import java.util.zip.GZIPOutputStream;import java.io.*;public class CreateGZIP{ public static void
For setting database dialect in Spring Boot, rely on spring.jpa.properties.hibernate.dialect?property in application.properties. For example, setting the MySQL5Dialect dialect can be done as below: spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
See how to figure out whether or not a given TimeZone supports the Daylight Saving feature and if it is in use. Java supports this with the help of observesDaylightTime() method. import java.util.TimeZone; public class DayLightDetails { public static void main(String[] args) { DayLightDetails dayLightDetails = new DayLightDetails(); dayLightDetails.proceed(); }
To convert a code-point (Unicode surrogate pair) into a string, rely on the following code: String str = “hello world”;int cp = str.codePointAt(some_position_in_str);String ch = String.valueOf(Character.toChars(cp));
Dates are an important part of all record keeping activities. Due to globalization, it is important to understand how each country represents the date. Some countries start the date with Year, some with Month and some of them interchange Month and Date place holders. Formatting (using ofPattern() method) is a
Looping the characters of a string can be done via charAt() or toCharArray() as follows: String str = “hello world”;for (int i = 0; i
Starting with JDK 13, we can define multi-line strings using “”” as follows: String text = “””some textsome textsome text”””;