Java

Inspect Class Annotations

Class annotations can be inspected via reflection as follows: Class clazz = Foo.class;Annotation[] clazzAnnotations = clazz.getAnnotations();

Transform a String into IntStream

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();

Performing File Compression in Java

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

Set Up a Database Dialect in Spring Boot

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

How to Check if DayLight Saving Is Present for a TimeZone

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(); }

Converting a Code-Point into a String

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));

Formatting Global Dates in Java

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

Loop the Characters of a String

Looping the characters of a string can be done via charAt() or toCharArray() as follows: String str = “hello world”;for (int i = 0; i

Working with Multi-line Text

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

No more posts to show