A Quick Reflection About Java Reflection

I was asked a question:“What do you know about reflection in Java?” I wasn’t really confident while answering that question, so let’s get a bit wiser and polish my rusty knowledge.
Read more →

Nested Classes in Java

I have recently tried one Java quiz and there was a question about class nesting. I didn’t answer correclty since I hardly ever use this language feature and when use nested classes, I use them intuitively. Let’s refresh this piece of knowledge and add some remarks.
Read more →

Autowiring a Spring Bean from External JAR

About importing an external library containing a Spring Bean into a project
Read more →

Spring (Boot) application.properties and Variables

Define an environment variable in environment export my_config=1337 To make a default value if the environment variable is not defined. application.properties 1 # Default value 2 my_config=666 3 4 # Take either a value from system environment or the default value. 5 my.config=${my_config} Consume the variable somewhere in the application. MyClass.java 1 @Component 2 public class MyClass { 3 @Value("${my.config}") 4 private int myValue; 5 6 // Consume myValue ad libitum 7 } Careful with the naming, it happened several times that I defined the default configuration with dot-notation and then the application did not work.
Read more →

Files and Directories

Check if directory is emptyBecause having something like Directory.isEmpty() would be too obvious. File dir = new File("path/to/my/file"); boolean isEmpty = file.isDirectory() && file.list().length == 0 Create a Path to Nonexistent Temporary fileThis is an interesting task. I needed to create a path to a temporary zip archive that did not exist yet so that I could use a zip4j library. It is easy to create a temporary file. 1 File tempFile = File.
Read more →