MyDigitalLife

Java How To?

How to find the jar file (with maven artifacts) for a class

Go to the site https://jar-download.com/, select ‘Class search’ and enter your class name.

Method References

There are four kinds of method references:

KindExample
Reference to a static methodContainingClass::staticMethodName
Reference to an instance method of a particular objectcontainingObject::instanceMethodName
Reference to an instance method of an arbitrary object of a particular typeContainingType::methodName
Reference to a constructorClassName::new

How to encode a URL string?

In a URL not all characters are allowed. Therefore strings have to be URL encoded.
This is done by the java method: java.net.URLEncoder.Encode(<string>,  <character-encoding>).
Where the <character-encoding> is typically set to “UTF-8”.

How to parse command line arguments?

Use the package ‘org.apache.commons.cli‘.

How to store temporary file (or how to use jimfs

To store temporary files use com.google.common.jimfs.Jimfs.
However, to iterate over the contents a DirectoryStream (obtained via Files.newDirectoryStream(path)) doesn’t seem to work.
Instead use Files.walkFileTree(path, simpleFileVisitor<Path>).

 How to create an EMF model programmatically