Category Archives: Uncategorized

Enumerations in Java

Java supports enumeration types (in short enum) since Java 5. Enumeration is used to define a list of constants which can be later referenced in source code by its name. Enumeration type in Java is based on concept of the … Continue reading

Posted in Java, Uncategorized | Tagged | Leave a comment

Unexpected NullPointerException (NPE) in ternary conditional operator in Java

Sometimes I come across Java code that unexpectedly throws NullPointerException in ternary operator. It is especially surprising if this particular line of code seems very simple like: or even: At first, it might look like the condition is not met … Continue reading

Posted in Java, Uncategorized | Tagged | Leave a comment

Delete directory with contents in Java

Removing empty directory in Java is as simple as calling File.delete() (standard IO) or Files.delete() (NIO) method. However, if the folder is not empty (for example contains one or more files or subdirectories), these methods will refuse to remove it. … Continue reading

Posted in Java, Maven, Uncategorized | Tagged , , , | 3 Comments

How to delete file in Java

File management (good old CRUD: create, read, update, delete) is quite common operation in software development. In this short post I would like to present 2 ways of removing files in Java. Method available in every Java version Every Java … Continue reading

Posted in Java, Uncategorized | Tagged , | Leave a comment