Java example to use regular expressions to search and replace unwanted and non-printable characters ASCII characters from text file content.
Java 8 allows to refer method from class or object using class::methodName syntax. Learn about different types of available method references in java 8.
Learn to convert byte to String and String to byte in java – with examples. Conversion between byte array and string may be used in many cases including IO operations, generate secure hashes etc.
Learn to use Integer.parseInt(), Integer.valueOf() and Integer.decode() to convert java string to int value. Also learn to handle NumberFormatException while conversion.
Learn to create enum using strings, iterate over all enum constants, getting single enum value and doing reverse lookup to find enum by string value. Create enum of string constants Example of creating enum with strings. This enum contains deployment environments and their respective URLs. Iterate all enum constants To iterate over all enums, use […]
To convert comma separated string to list in java, you can use below methods. Comma-separated String to List Using Regex You can use regular expression “\\s*,\\s*” to match comma into CSV list and then use String.split() method. Output: [how, to, do, in, java] This resulting List is a fixed-size List backed by the array. It […]
You may need custom serialization in java in may cases. For example, you have legacy java classes which you are not willing to modify for any reason. There can be some design constraints as well. Or even simply, the class is expected to be changed in future releases which could break the deserialization of previously […]
RxJava 2.0 is open source extension to java for asynchronous programming by NetFlix. It is much closer to functional programming as seen in java 8 lambda expressions. The basic building blocks of reactive code are Observables and Subscribers. An Observable emits items; a Subscriber consumes those items.
Maven parent POM (or super POM) is used to structure the project to avoid redundancies or duplicate configurations using inheritance between pom files.
Maven scope attribute is used to specify the visibility of a dependency, relative to the different lifecycle phases (build, test, runtime etc). Maven provides six scopes i.e. compile, provided, runtime, test, system, and import.
Maven repositories are physical directories which contain packaged JAR files along with extra meta data about these jar files. This meta data is in form of POM files which have jar file project information, including what other external dependencies this JAR file has. These other external dependencies are downloaded transitively into your project and become […]
In Maven, dependency is another archive—JAR, ZIP, and so on—which your current project needs in order to compile, build, test, and/or to run. The dependencies are gathered in the pom.xml file, inside of a <dependencies> tag. When you run a build or execute a maven goal, these dependencies are resolved, and are then loaded from […]
POM (Project Object Model) is an XML file that contains information about the project and configuration details used by Maven to build the project i.e. sourcecode location, project dependencies etc. This file must be named as pom.xml and placed under root folder of project.
Maven settings.xml file contains configurations that are not specific to a project, but are global in nature. It also contains information that is not meant to be distributed (e.g. passwords).
JUnit 5 aims to adapt java 8 style of coding and to be more robust and flexible than JUnit 4. In this post, JUnit 5 vs JUnit 4, we will focus on some major differences between them.
Eclipse has great tooling support for JUnit test cases. Having code templates for JUnit test cases configured in Eclipse is a great addition in faster test development. Learn to create and import JUnit 5 test templates in eclipse.
In JUnit 5, to test exception cases you should use org.junit.jupiter.api.Assertions.assertThrows() method. There are other ways for junit 5 exception testing, but I will suggest to avoid them. Syntax of Assertions.assertThrows() It asserts that execution of the supplied executable throws an exception of the expectedType and returns the exception. public static <T extends Throwable> T […]
JUnit @Disabled annotation can be used to disable the test methods from test suite. This annotation can be applied over a test class as well as over individual test methods.
JUnit 5 Assumptions class provides static methods to support conditional test execution based on assumptions. A failed assumption results in a test being aborted. Assumptions are typically used whenever it does not make sense to continue execution of a given test method. In test report, these test will be marked as passed.
JUnit 5 assertions help in validating the expected output with actual output of a testcase. To keep things simple, all JUnit Jupiter assertions are static methods in the org.junit.jupiter.Assertions class.