How to run JUnit test with Maven

java-featured-image

This tutorial will cover how to run Unit tests using the Maven’s Surefire plugin. If you are not familiar with Unit Testing, you can follow this tutorial for a quick catch-up. In our Maven Project, we need the following mandatory dependencies: <dependencies>     <dependency>         <groupId>org.junit.jupiter</groupId>         <artifactId>junit-jupiter-api</artifactId>         <version>5.4.2</version>         <scope>test</scope>     </dependency>     <dependency>        <groupId>org.junit.jupiter</groupId>         <artifactId>junit-jupiter-engine</artifactId>         <version>5.4.2</version>         <scope>test</scope>     </dependency> </dependencies>…

Continue reading

Java Parallel Streams Example

java-featured-image

Stream API allows developers to  take advatange of multi core architectures and improve the performance of Java program by  creating parallel streams and making your program perform operations faster. There are two ways of creating a parallel stream: by using the parallelStream() method by using the parallel() method When you are using parallel streams, effectively…

Continue reading

ThreadLocal Java Example

java-featured-image

ThreadLocal is a class that provides thread local variable and is used to achieve thread safety. The data stored will be accessible only by a specific thread. ThreadLocal extends Object class and provides thread restriction which is a “part” from local variable. Creating a ThreadLocal variable ThreadLocal threadLocalExample = new ThreadLocal(); The instantiation of the…

Continue reading

Depth-First-Search Example Java

java-featured-image

Searching and/or traversing are equally important when it comes to accessing data from a given data structure in Java. Graphs and Trees are an example of data structures which can be searched and/or traversed using different methods. Depth-first-search, DFS in short, starts with an unvisited node and starts selecting an adjacent node until there is…

Continue reading

Breadth-First-Search Example Java

java-featured-image

Searching or traversing is really important when it comes to accessing data from a given data structure. There are different methods of traversing/searching elements within these data structures such as Graphs and Trees. Breadth-first search is one example of these methods. BFS is an algorithm that traverses tree or graph and it starts from the…

Continue reading

Different Algorithm Time Complexities

java-featured-image

Before starting to explain the different time complexities, let’s first look at what an actual algorithm is. The formal definition of an algorithm is “a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.”. So in other words, an algorithm is a defined path which is…

Continue reading

Introduction to Docker and Docker containers in Java

java-featured-image

In short, Docker is a tool that allows you to build, deploy and run applications easily by the usage of so-called containers. These containers let us package all the essentials such as libraries and dependencies. In addition, the containers run on the host operation system. There are many benefits that come when we use Docker. It…

Continue reading

PathVariable annotation in Spring

spring-featured-image

Just like @RequestParam, @PathVariable annotation is used to extract data from HTTP request . However, they differ slightly. The difference is that @RequestParam gets parameters from the URL while @PathVariable simply extracts them from the URI. Example Let’s imagine you had a website that supported the following URL: http://www.yourwebsite.net/employee/1 1 in the URL above represents…

Continue reading

RequestBody annotation in Spring

spring-featured-image

The @RequestBody annotation can be used for handling web requests. More specifically, it is used to bind a method parameter with the body of a request and the way it works is HttpMessageConverter converts the request’s body based on the type of the content of the request. Syntax <modifier> <return-type> <method-name> (@RequestBody <type> <name>) { }…

Continue reading

Interceptors in Spring

spring-featured-image

In Spring, Interceptors, as the name suggests, intercept we requests through implementing HandlerInterceptor interface. It provides us with methods that allow us to intercept incoming requests that is getting processed by the controller class or the response that has been processed by the controller class. The methods that the interface provides us with are: preHandle() – returns true…

Continue reading

Dependency Injection in Spring Example

spring-featured-image

In this tutorial you are going to learn what Dependency Injection in Spring is, how it works and how you can use it. What is Dependency Injection? Dependency Injection is one of the fundamentals of Spring which you must know. When you create a complex application, chances are you are going to have different objects…

Continue reading

How to perform unit testing for Controllers and Services

spring-featured-image

As you may be well aware, testing is very important. In this tutorial therefore, you will learn how to do just that! Testing. And more specifically, you will learn how to perform that testing on Controllers and Services. Controllers Normal controller does 1 of 2 things: renders a view or handles form submission Let’s look at…

Continue reading

Installing and configuring MySQL database and server for Spring usage

spring-featured-image

In the end of this tutorial, you will have installed the right MySQL products needed to develop applications in Spring. You will need two essential things: MySQL Database and MySQL Server. Follow the steps below. Configuring the MySQL Database Visit https://www.mysql.com/downloads/ and then select Community downloads, like so: On the next page, you will see…

Continue reading

How to handle Login authentication in Spring

spring-featured-image

In this article, you are going to learn how to use Spring Security to achieve a login authentication functionality. The login page represents a form which asks for details such as username and password. That same login page can be done in Angular and the authentication process itself will be performed by Spring Security. There…

Continue reading

Introduction to Spring Security and how to Set it up

spring-featured-image

In this tutorial you are going to learn how to secure your web application using the Spring Security including user authentication, authorization and more. Spring Security – Introduction Spring Security is a customizable authentication framework. It is the standard when it comes to securing Spring-based applications. It provides both authentication and authorization. Authorization is also…

Continue reading

How to create RESTful web services with Spring

spring-featured-image

When we are dealing with RESTful web services, we need to be using @RestController annotation which basically represents the @Controller and @ResponseBody annotations. When we use @RequestMapping for our methods, we can add an attribute which is called produces which specifies that the output sent to the user will be in JSON format. Example Employee.java public class…

Continue reading

What is OAuth2-based authentication and authorization in Spring

spring-featured-image

OAuth2 allows third-party applications to receive a limited access to an HTTP service which is either on behalf of a resource owner or by allowing a third-party application obtain access on its own behalf. Thanks to OAuth2, service providers and consumer applications can interact with each other in a secury way. Workflow There are a…

Continue reading

Introduction to MVC Framework in Spring

spring-featured-image

MVC stands for Model-View-Controller and Spring supports it. The great thing about the MVC pattern is that it separates different aspects of the application like inputs, business logic and user interface.  This pattern is so widely used that it even has a song about it. The three components in the MVC pattern are Model, View, Controller,…

Continue reading

Autowired Annotation in Spring

spring-featured-image

@Autowired annotation is a relatively new style of implementing a Dependency Injection. It allows you to inject other beans into another desired bean. Similar to the @Required annotation, the @Autowired annotation can be used to “autowire” bean on setter methods as well as constructors and properties.. @Autowired Annotation on Setter Methods Please note that when…

Continue reading

Core concepts and Advice Types in AOP in Spring

spring-featured-image

If you are familiar with Spring, you’ve probably heard of Aspect Oriented Programming (AOP). That’s one of the main components of the Spring framework. However, no previous experience in AOP is needed. It is focused for complete beginners who want to understand how AOP framework in Spring works. In Object Oriented Programming, modularity of an…

Continue reading

How to use the MySQL connector in Java

java-featured-image

Before testing the MySQL connection from a Java program, we’ll need to add the MySQL JDBC library to the classpath.  We will need to download the mysql-connector-java-*.jar file from the downloads page: Now, depending upon your work environment (e.g. Eclipse or Command line) you will have to do either one: If working with Eclipse IDE,…

Continue reading

Best Tips to Hire Java Developers for Building High-Performance Java Applications

According to history, Java was launched nearly 20 years earlier, with new ideas of object-oriented programming that improved the misunderstandings of other common languages at the time, for instance, C or C++. Java’s garbage amassing and its fundamental doubter virtual machine made another technique for programming and introduced the new idea of “Create once, run…

Continue reading