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.
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.
How to insert images when outputting excel using POI packages in Java.
Java common data type and structure operations.
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.
Code example to show that Java child class also inherits
parent class private fields.
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 String concatenation performance concern.
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 sort arrays in descending order.
Java bubble sort implementation.
Java binary search implementation.
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.
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 Executors ThreadPool example with Callable and Future.
Java sort HashMap by key.
How to iterate maps in java.
Execute linux/unix command in java.
Sample entrance code of rabbitmq java client.
How to pass testng command line arguments dynamically when Ant is used for invoking testng task.
With Jenkins “This build is parameterized” feature, we can dynamically pass testng parameters (i.e. test config or data input) through Ant.
Some log4j tips.
How to convert string to stream in java.
How to read content of a file into string in java.
Java private field access.
Java okhttp client trustall certificate (for test only).
In Java, static fields and static methods are common but how about static class? Here is an example.
Java multithreading programming demo.
Java parse common data files such as csv, json, yaml, xml, ini, properties and etc.
Java serialization and deserialization examples.
Java reflection examples.
TestNG custom listener to log individual result of test method execution and custom reporter to log summary report of test suite execution.
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.
Apache maven simple guide for installation, configuration, and usage.
Java scp util implemented with JSch lib.
Java convert stack trace to string.
Java initialization.
Java class loading and three classloaders.
Java overload, override, inheritance, and polymorphism.
Java abstract class and interface and their difference.
Extract the i-th digit of any integers, where i starts from right to left.