JSON.simple – Read and Write JSON
JSON.simple is lightweight JSON processing library which can be used to read JSON, write JSON file. Produced JSON will be in full compliance with JSON specification (RFC4627).
JSON.simple is lightweight JSON processing library which can be used to read JSON, write JSON file. Produced JSON will be in full compliance with JSON specification (RFC4627).
Template method design pattern is widely accepted behavioral design pattern to enforce some sort of algorithm (fixed set of steps) in the context of programming. It defines the sequential steps to execute a multi-step algorithm and optionally can provide a default implementation as well (based on requirements). Table of Contents …
JDOM parser can be used to read XML, parse xml and write XML file after updating content of it. It stores JDOM2 document in memory to read xml values.
Learn to read a text file into String using Files.readAllBytes(), Files.lines() and BufferedReader classes in various ways.
Java example to use regular expressions to search and replace unwanted and non-printable characters ASCII characters from text file content.
Since Java 8, in simplest words, the method references are a way to refer to methods or constructors without invoking them. Learn the syntax with examples.
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.
learned to parse a string (decimal, octal and hexadecimal) to int or Integer types using Integer.parseInt(), valueOf() and decode() methods.
In this guide to Java enum with string values, learn to create enum using strings, iterate over all enum values, get enum value and to perform reverse lookup to find enum by string parameter.
Learn to split string by comma or space and store in array or arraylist. Use given Java program to convert string to List in Java.
We may need custom serialization in java in many cases. For example, we have legacy java classes that we 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 …
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 dependency scope is used to specify the visibility of a dependency. It provides six scopes i.e. compile, provided, runtime, test, system, and import.
Maven repositories are physical directories that contain packaged JAR files along with extra metadata. Learn about local, remote and central repositories.
In this Maven tutorial, learn about Maven dependency management, including external dependency, transitive dependency tree, excluding dependencies and version ranges. 1. What is Maven Dependency? In Maven, a dependency is just another archive—JAR, ZIP, and so on—which our current project needs in order to compile, build, test, and/or run. These project dependencies are collectively specified in …
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.
When writing unit tests, it makes sense to check whether certain methods throw the expected exceptions when we supply invalid inputs or pre-conditions that are not satisfied. Junit 5 provides the following assertion methods for handling test exceptions. These method names are self-explanatory enough to suggest their usage. Please continue …
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.
In JUnit 5, test lifecycle is driven by 4 primary annotations i.e. @BeforeAll, @BeforeEach, @AfterEach and @AfterAll. Along with it, each test method must be marked with @Test annotation. @Test annotation is virtually unchanged, although it no longer takes optional arguments.
Learn to configure junit 5 with gradle, its juniper and platform modules and how to use them to create and execute tests.
Learn to configure junit 5 with maven, its jupiter and platform different modules and how to use them to create and execute tests.
JUnit 5 @Tag can be used to filter testcases from test plans. It can help in create multiple different test plans for different environments, different use-cases or any specific requirement. You can execute set of tests by including only those tagged tests in test plan OR by excluding other tests from test plan.
JUnit 5 test suites are written with @Suite annotation. Suites help us run the tests spread into multiple classes and packages. We can use Include and Exclude annotations (discussed later in this tutorial) for filtering test packages, test classes, or even test methods. @RunWith(JUnitPlatform.class) has been deprecated in favor of …
JUnit 5 @RepeatedTest annotation enable to write repeatable test templates which could be run multiple times. The frequency can be configured as parameter to @RepeatedTest annotation.
JUnit 5 @AfterAll annotation is replacement of @AfterClass annotation in JUnit 4. The annotated method should be executed after all tests in test class.
JUnit 5 @AfterEach annotation is replacement of @After annotation in JUnit 4.The annotated method should be executed after each @Test method in test class.
JUnit 5 @BeforeEach annotation is replacement of @Before annotation in JUnit 4. Annotated method should be executed before each @Test method in test class.
JUnit 5 @BeforeAll annotation is replacement of @BeforeClass and is used to signal that annotated method should be executed before all tests in test class.
Learn to execute JUnit 5 tests in Eclipse IDE. Maven has been used to import dependencies in this JUnit 5 example. 1. Add JUnit 5 Maven Dependencies To run JUnit 5 tests in Eclipse, at minimum, we will need the latest versions of the following dependencies. 2. Use @Test Annotation …
Learn to convert XMLGregorianCalendar to Date class or string value. Also learn to apply timezone changes and daylight saving effects as well.
Learn to build JAX-RS 2.0 HATEOAS links in REST resources using it’s javax.ws.rs.core.Link, javax.ws.rs.core.UriBuilder and javax.ws.rs.core.UriInfo classes.
To triage SSL issues, enable SSL debug logging by passing javax.net.debug=ssl runtime argument to your server/program.
In Spring, custom PropertyEditor implementation converts a custom object’s value to and from its native type representation into a String.
Mostly for logging and security purposes, we need the IP address information for incoming requests. 1. HTTPServletRequest.getRemoteAddr() In a Java web application, we can get IP address using HTTPServletRequest.getRemoteAddr() method. String ipAddress = httpServletRequest.getRemoteAddr(); BUT, if our application is running behind a load balancer proxy and we would like to …
Spring boot @Scheduled example to schedule jobs at a fixed rate, fixed delay, using a cron expression and concurrent task executions.
Learn how to use Spring Boot CommandLineRunner interface with examples, and how it is different from the ApplicationRunner interface.
Spring boot loads lots of beans internally to run the application with minimal configuration. In this example, we will learn to find out all those loaded beans by Spring Boot and their class type information. Using ApplicationContext to get all loaded beans To execute a method automatically, when the application …
Learn the default spring boot logging and configuring custom log levels, file appenders and colored logs via application.yaml file.
Learn the default spring boot logging and configuring custom log levels, file appenders and colored logs via application.properties file.
Spring Boot bundles Tomcat and Jetty dependencies as separate starters to make easy switching them using configurations and properties.
By default, Spring boot embedded server starts at port 8080. Learn to change the default port using Java configuration, command line, and properties.
By default, Spring boot applications are accessed by context path “/”. We can customize it using server.contextPath or server.servlet.context-path.
In Spring Boot 3 JSP example, learn to configure the Spring MVC with JstlView.class and serve JSP pages with static content and triage some common issues.
In fizz buzz game, we say numbers such that if that number is a multiple of five, we say “fizz”, if multiple of seven, we say “buzz”, multiple of both, we say “fizzbuzz.”
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.