How to write single file source code executable in java

Since JDK 11, Java supports executing source file directly without the need to first compile to class file, which makes it possible to write scripting in Java, as is usually done with dynamic programming languages like python, ruby, or nodejs. This post serves as an example as well as a quick reference on how to achieve it.

Convert epoch millisecond timestamp to readable datetime

In many cases such as when dealing with API response in JSON format, working on JavaScript assets embedded on websites, and so on, we keep seeing 13-digit long numbers very frequently and we probably know it is epoch timestamp originating from code like new Date().getTime(), however, as a human we just can not quickly tell what date and time it represents. There is a convenient website named Epoch Converter that can help convert it to human-readable format easily but most of the time for developers, there are even quicker ways than opening the website, which is by using the interactive shell that comes with many programming languages.

Insert images into excel with POI

How to insert images when outputting excel using POI packages in Java.

Java common data type and structure operations

Java common data type and structure operations.

Java only creates sub class instance

Code example to show that when a new instance is created, Java only creates instance for the sub class, and for the super class.

Java open url with URL and URLConnection

Java open url with URL and URLConnection.

Java child class also 'inherits' parent class private fields

Code example to show that Java child class also inherits parent class private fields.

Java group list objects by attribute

How to group a list of objects by one of the object's attribute, which is similar to SQL group by statement and having the same results.

Java base64 encode and decode example

Java base64 encode and decode example.

Java String concatenation performance concern

Java String concatenation performance concern.

Java POI excel merge cell and style

Quick code example on how to merge cells with POI and apply cell style to the merged cell.

Java lazy initialization singleton instance pattern

Java lazy initialization singleton instance pattern.

Java sort arrays in descending order

Java sort arrays in descending order.

Java bubble sort implementation

Java bubble sort implementation.

Java binary search implementation

Java binary search implementation.

Java stream distinct by property

Java 8 stream has a distinct() method which could be used to filter out a list of distinct objects, but the distinctness of that method is based on Object.equals(Object). What if you want to filter a list of objects based on any property (field) of the object? The StreamEx library comes as an elegant solution.

Submit json data with utf-8 in Spring resttemplate

In Spring framework RestTemplate is very useful in terms of sending various http requests to RESTful resources and this post shows simple examples on how to set Content-Type, Accept headers, as well as the content encoding, which is especially important when requesting with non-ascii (e.g. CJK languages) data.

Java generates base64 encoded hmac with sha256

Java generates base64 encoded hmac with sha256.

Java Executors ThreadPool example with Callable and Future

Java Executors ThreadPool example with Callable and Future.

Java sort HashMap by key

Java sort HashMap by key.

How to iterate maps in java

How to iterate maps in java.

Execute shell command in java

Execute linux/unix command in java.

Rabbitmq java client

Sample entrance code of rabbitmq java client.

Passing testng command line arguments from ant

How to pass testng command line arguments dynamically when Ant is used for invoking testng task.

Passing parameters to testng xml from ant on jenkins

With Jenkins “This build is parameterized” feature, we can dynamically pass testng parameters (i.e. test config or data input) through Ant.

Log4j tips

Some log4j tips.

Java convert string to stream

How to convert string to stream in java.

Java read file into string

How to read content of a file into string in java.

Java private field access

Java private field access.

Java okhttp trustall certificate

Java okhttp client trustall certificate (for test only).

Java static class

In Java, static fields and static methods are common but how about static class? Here is an example.

Java multithreading

Java multithreading programming demo.

Java parse common data files

Java parse common data files such as csv, json, yaml, xml, ini, properties and etc.

Java serialization

Java serialization and deserialization examples.

Java reflection

Java reflection examples.

TestNG custom listener and reporter

TestNG custom listener to log individual result of test method execution and custom reporter to log summary report of test suite execution.

Log4j TestNG reporter appender

When developing test automation framework in java with TestNG and log4j, one can append log4j logs to the "Reporter output" section of TestNG html report and this post shows how to achieve that.

Maven simple guide

Apache maven simple guide for installation, configuration, and usage.

Java scp util

Java scp util implemented with JSch lib.

Java convert stack trace to string

Java convert stack trace to string.

Java initialization

Java initialization.

Java classloaders

Java class loading and three classloaders.

Java overload override inheritance polymorphism

Java overload, override, inheritance, and polymorphism.

Java abstract class and interface

Java abstract class and interface and their difference.

Extract the i-th digit of integers

Extract the i-th digit of any integers, where i starts from right to left.