Home » Java » Page 20

Java

Mockito: Cannot instantiate @InjectMocks field: the type is an interface

Anyone who has used Mockito for mocking and stubbing Java classes, probably is familiar with the InjectMocks-annotation. Use this annotation on your class under test and Mockito will try to inject mocks either by constructor injection, setter injection, or property injection. This magic succeeds, it fails silently or a MockitoException is thrown. I’d like to explain what causes the “MockitoException: ...

Read More »

REST: Creating resources

java-interview-questions-answers

Resource creation is a common REST API operation. In this post we will see how single resource can be created. The client request Resources are typically created by sending a POST request to the parent collection resource. This creates a new subordinate resources with a newly generated id. For example, a POST request to /projects might be used to create ...

Read More »

Migrating Neo4j graph schemas in Kubernetes

When running enterprise applications with zero-downtime, we need to be able to perform database schema migrations without disrupting active users. This is important not just for relational databases, but also for graph databases such as Neo4J, which don’t enforce a schema on write. However, it still makes sense to refactor your graph and to keep your graph data model in ...

Read More »

Optional orElse vs orElseGet

Java 8 introduced a fantastic concept of Optional, which we looked into in our blog Java 8 Optional. So just to give a short recap, Optional is used to represent Optional object or empty value instead null reference. This will help to avoid null pointer exception which occurs when we try to perform some operation on null reference object. For accessing ...

Read More »

Better NullPointerException Messages Automatic in JDK 15

I discussed long-awaited and highly appreciated improvements to NullPointerException (NPE) messages in the posts “Better Default NullPointerException Messages Coming to Java?” and “Better NPE Messages in JDK 14“. When this JEP 358-driven feature was added to JDK 14, a developer who wanted to benefit from these more insightful NPE messages needed to explicitly state that desire by passing the argument ...

Read More »

Reverse A String Using Recursion

1. Introduction In this article, You’re going to learn how to reverse a string using recursion approach. The first program is to reverse a string and the second program will read the input from the user. In the previous articles, I have shown already how to reverse a string without using any built-in function and also how to reverse the words in a ...

Read More »

RESTful services with HATEOAS: REST APIs and Hypermedia on JVM

java-interview-questions-answers

1. Introduction So far we have spent a fair amount of time talking about the role of the hypermedia and HATEOAS in the RESTful web services and APIs, glancing over different specifications and usability aspects. It sounded like supporting hypermedia and HATEOAS is not that difficult, just pick you favorites and you are good to go! As you may guess, ...

Read More »

How to restore a Neo4J backup on managed Kubernetes

In the following video I’ll explain how to restore backups of Neo4J instances to a fresh instance that runs in a managed Kubernetes environment. The backup contents will be taken from a persistent volume to which we previously wrote the backup. In this previous post you can see how to take backups in the first place. Try it yourself Again, ...

Read More »

How to backup Neo4J on managed Kubernetes

In the following video I’ll explain how to take full and incremental backups of Neo4J instances that run in a managed Kubernetes environment. We’ll use additional pods to take remote backups and store the backup data on persistent volumes which are provided by our managed environment. In case you’re wondering how to deploy Neo4J to managed Kubernetes, have a look ...

Read More »