Disclosure: This article may contain affiliate links. When you purchase, we may earn a small commission.

Template Method Pattern in Java? Example Tutorial

Template Method Pattern defines a sequence of steps of an algorithm. The subclasses are allowed to override the steps but not allowed to change the sequence. It can also be provided a default implementation for one or more steps. Let us look at the following example to understand Template Method Pattern.  A Template method pattern provides a skeleton for performing any sort of algorithm or an operation, and it allows the sub-classes to re-define part of the logic. One of the key advantage of Template pattern is that its natural fit for building frameworks, so that parent framework classes can make callbacks into methods implemented in children. Spring Framework makes full examples of Template pattern and you will find several key classes like JdbcTemplate, RestTemplate, and JmsTemplate which are created using Template pattern.

What is Spring Expression Language (SpEL)? Difference between $ and # in @Value expressions Example

Hello Java programmers, if you are wondering what is Spring Expression Language and how to use them in your Spring Framework or Spring Boot application then you have come to the right place. Earlier, I have shared the best Spring Framework coursesFree Spring Questions, Spring projects, and books, and in this article, I am going to teach you about Spring Expression Language with simple, easy-to-understand examples. The Spring Expression Language (SpEL for short) is a powerful language that supports querying and manipulating an object graph at runtime. The syntax is similar to Unified EL, but it has several more features, such as method calling and rudimentary string templating.

Top 23 Object Oriented Design Patterns (GOF) Java Programmers Should Learn

Design Patterns are tried and tested way of solving a problem within a given context. They are not invented, rather they are discovered, which is also obvious by use of word pattern. By using design pattern, you take knowledge of all wide communities and can safely use it to solve that problem. At times they might not give you perfect solution, require bit of tweaking, but they certainly provides one of the best solution, as long as you use them properly. While doing object oriented development, they are numerous task which appears quite often e.g. creating objects, structuring code, and implementing different behaviors based on different context.

Student Management System Project - FullStack Java + Spring Boot + React.js Example Tutorial

Hello Java programmers, if you want to learn Spring Boot and Reactjs and looking for a full-stack Java example or a mini project then you have come to the right place. Earlier, I have shared the best Spring Boot coursesbooks, and best reactjs courses as well as many courses to learn full-stack development in Java and become a full-stack java developer. In this mini project, you will learn how to create an application that is capable of creating, deleting, updating, and retrieving functions using the Spring Boot, React, and H2 Database. In this tutorial you will create a School Classroom Application that can insert, update, delete and search students. The frontend of the application is developed using Reactjs and also the backend is developed using spring boot. And, most importantly communication between the two platforms will be done using the REST APIs. 

How to merge two HashMap in Java 8 - Map.merge() example

You can merge two Map in Java using the newly added merge() function in Java 8. This allows you to copy values from one map to another to merge both of them. It also provide a lot of flexibility to handle duplicate keys. In the last article, I have shown you how to combine two Map in Java using the putAll() method but there was a problem. If a key is present in both map, then putAll() overrides the value from the second map, which you may or may not want. The real issue is that you don't have any control on what should happen if there exists duplicate keys in those Map e.g. you may want to keep the original value intact or you always want values from second map to override values in first map, or you just want to concat or add two values to form a new value. This problem is solved by the Map.merge() method in JDK 8, which allows you to pass a lambda expression to control the remapping operation.

How to create RESTful Web Services in Java using Spring Boot? Example Tutorial

Hello guys, if you are looking for a complete tutorial to create REST API on Spring Boot then you have come to the right place. In the past, I have shared the best RESTful Web Services courses and best Spring Boot courses and in this article, I am going to show you how to create RESTful web services using Spring Boot step by step. After going through this tutorial you will be able to create your own REST endpoints and RESTful application using Spring Boot and Spring Framework and Java programming language. How to make Spring boot REST API? is a common question that everyone has who is new to Spring boot application development. 

How to use Lombok in Java? Lombok @Data and @NonNull Annotations Examples

Hello Java programmers, if you have been doing professional Java development, you may have heard about Lombok library, one of the most popular Java libraries among professional Java developers, making coding in Java much more fun and rewarding. Java has always been criticized for its verbosity, and many programming languages like Scala and Groovy are invented to solve that problem, but Lombok solves that problem in Java itself. This means you don't need to learn a new programming language, but you can use the Lombok library and its annotations to write clear and concise code in Java. 

How to use NamedQuery in Spring Framework JDBC? Example Tutorial

Hello guys, many people don't know that Spring Framework provides support for NamedQuery where you can pass parameters in a much readable way by using named placeholders than the default placeholder of ? (question mark) which is used with PreparedStatement in Java. If you want to learn Spring JDBC then you have come to the right place. In the past, I have shared the best Spring Framework courses, books, and tutorials to learn Spring Framework and its different features, and in this example, I will show you how to use NamedQuery in Spring Framework. You can then use this technique to write much more readable queries on the Java layer for your application. 

10 Data Structures Every Programmer Should Learn

Data Structure and Algorithms are two pillars of Programming. They are also the most important ingredient of a good program and right choice of Data Structure and Algorithms can improve performance drastically, whereas a wrong choice can spoil the party, but do you know what exactly they are? Well, Data Structure are nothing but a way to store data, while Algorithms are ways to operate on that Data. There is a reason why Data Structure and Algorithms are taught in every single Computer Science classes, it doesn't matter whether you are learning Java, C++, Python, JavaScript, Golang, or any other programing language, those data structure and algorithm will be same everywhere. 

How to upload/download file in Spring MVC and Spring Boot Java application? Example Tutorial

Hello guys, if you are wondering how to upload file and download files from a Spring MVC application then you have come to the right place. This is an important functionality for any real-world application and knowing how to upload a file in a Spring application is important for professional Java developers and that's what you will learn in this Spring MVC tutorial. Earlier, I have shared several Spring Boot tutorial like Spring Boot + Microservices, and Spring Boot + REST and even  how to upload files using Servlet and JSP using Apache Commons FileUpload library and In this tutorial, we are going to discuss how to upload and download files using Spring MVC. 

How to use Mockito to Unit test Java Program with JUnit? Example Tutorial

Hello guys, if you are writing unit test your Java application then you would have definitely come across JUnit and Mockito, two of the essential unit testing framework  for Java developers. While JUnit offers support to run your test, setup and teardown and also assertion to check the expected and actual output. Mockito complements JUnit by offering you a mock based testing approach. Mock is nothing but a test double which can return a configured value when a certain method is called. It also provides ability to check if a particular method is called or not. By using Mock object or test double you can check if your code is behaving properly or not in different scenarios. This is also the key difference between JUnit and Mockito, JUnit provides infrastructure to run your test while Mockito provide infrastructure to created Mock objects. 

How to Enable log SQL statements in Spring Boot? Example Tutorial

Hello guys, if you are a Java developer developing Spring Boot applications, you may need to have proper knowledge of various kinds of errors and also how to overcome those. For example, most of Java developers use JPA in spring boot to make our work easy when managing databases. If you get an error like an internal server error (504 error), you need to go through your backend system and find the error. In many cases, these errors are caused by running invalid SQL or due to error on database. At that time, you often need to know which SQL statements are executed by Hibernate or JPA, or any other database library you are using.  

How to choose Collection in Java? List, Set, Map, and Queue Example

The Java collection framework offers implementation of different data structure like an array, list, set, map, queue, tree, etc and the choice really depends upon the situation and properties of the different data structure. For example, if your requirement is fast search with index then you can use ArrayList and if you want to store key-value pairs then you would consider using hash table data structure and there are a couple of implementation of hash table data structure in Java, like HashMap, Hashtable, LinkedHashMap, TreeMap, and ConcurrentHashMap. Now, which one will you choose? If you don't know or confused don't worry, I will give you a set of rules and use cases which will help you choose the right Collection type in Java depending upon scenario. 

Top 10 Matrix Coding Exercises for Programming interviews and Homework

Hello guys, if you are preparing for Coding interviews and solved 100+ data structure problems then you may know that Matrix is one of the under-rated topic for coding interviews but Matrix coding problems are not that easy to solve and  In this article, we'll see some of the popular Matrix coding problems for coding interviews. I actually learned a lot by solving Matrix related problems. I still remember the first Matrix based problem I solve was about how to multiply two matrices in Java and I learned a lot about multi-dimensional array and nested loop in Java by solving that problem. The second problem I solved was about transposing Matrix and that was also quite challenging for me at that time but helped me to further solidify my knowledge about loops and array in Java. 

How to find first recurring or duplicate character in given String? [Solved]

Hello guys, while surfing the Internet for a couple of weeks back, I come to know that this problem was asked on Google interviews, find the first recurring character in a given String. I don't know if that's true but this looks like a very simple coding problem from Google's Interview standard. If it was indeed asked, then that guy must have been very lucky. Anyway, I liked this coding problem and thought to write about it, because it's a good coding problem to check candidates' data structure and algorithms skills because it's tricky. It's tricky because it's very easy to make a mistake assuming just one recurring character in String, which you should avoid. Even if it was not asked on Google, you will potentially find this problem on various startups, and other IT companies like Infosys, TCS, Cognizant, Microsoft, and maybe Amazon

Difference between CAST, CONVERT, and PARSE SQL Server? Example Tutorial

Though all three, CAST, CONVERT, and PARSE are used to convert one data type into another in SQL Server, there are some subtle differences between them. The  CAST method accepts just two parameters, expression, and target type, but CONVERT() also takes a third parameter representing the format of conversion, which is supported for some conversions, like between character strings and date-time values. For example, CONVERT(DATE, '2/7/2015', 101) converts the character string '2/7/2015' to DATE using DATE format 101, representing United States standard.

Top 5 Spring MVC Annotations for Developing RESTful Web Services

Hello guys, Spring framework is one of the most popular Java framework and Spring MVC is probably the most common way to develop web applications in Java, but things just doesn't end there. In the past a couple of years, Spring has become the best way to develop RESTful Web services in Java. Despite numerous RESTful Web Service frameworks in Java world e.g. Restlet, Jersey, RESTEasy, and Apache CFX, Spring MVC has maintained its position as the leading framework for creating RESTful APIs in Java, and there are multiple reason why Spring is the best framework for Java developers for creating RESTful solutions and we will look one of them in this article. 

Difference between SQL, T-SQL and PL/SQL?

Hello guys, if you are preparing for SQL and Database Interviews or any Software engineering interview and looking for difference between T-SQL, SQL, and PL/SQL then you have come to the right place. Earlier, I have shared 50 SQL Interview questions and 12 SQL query Examples from interviews and today, we are going to see another common and interesting SQL interview question, what is the difference between SQL, T-SQL, and PL/SQL? It is also one of the most common doubts among SQL beginners. It's common for programmers to think that why there are many types of SQL languages, why not just single SQL across DB? etc. Well, let's first understand the difference between SQL, T-SQL, and PL/SQL, and then we will understand the need for these dialects. 

How to check Perfect number in Java? Example Tutorial

Hello guys, if you are wondering how to check if a given number is a perfect number or not in Java then you have come to the right place. This is one of the interesting coding problem to solve and learn and improve your coding and programming skill. In face, I learned most of my programming by solving these kind of questions. I started with simple ones like factorial, prime number, palindrome, anagram, string permutations before I started solving tree based problems and Dynamic programming problems. These kind of exercise not only give you a chance to get familiar with the programming language constructs like data type, operators, functions, class etc, but also help to build coding sense, which is nothing but your skill to convert your logic into code. 

12 SQL Queries Example and Practice Questions for Tech Interviews

Hello guys, if you are looking for SQL query examples from interviews or SQL Query Practice questions to improve your SQL skill then you have come to the right place. Earlier, I have shared best websites to learn SQL and Practice Query online and in this article, I am going to share 12 popular SQL query examples from interviews. You can also practice them to test your SQL skills before your technical Interview. If you don't know SQL, a short form of Structured Query Language is one of the essential skills in today's programming world. No matter whether you are a Java developer, C++ developer or Python developer, you must know how to write SQL queries. Every programming job interview has at least one or two questions that require you to write SQL queries for a given requirement and many developers struggle there. 

Why Singleton is Anti Pattern in Java Now and Why you should avoid it? Example

There was a time when the Singleton pattern was the darling pattern of many developers. It's a unique feature to keep certain services available globally, makes it very useful in all kinds of applications. It was also one of the most used design patterns among Java developers. I think the main reason for the Singleton pattern's popularity of designing the application is that there is always one instance of the most important service like Manager and Data Access classes. Still, with the adoption of Dependency injection, Singleton slowly faded away, and now it's considered an anti-pattern in Java applications. 

Java Stream + map + flatMap + Collectors.toSet() Example Tutorial

Hello guys, I was searching for a good example of flatMap online but didn't found a good one, so created my own. As name suggest flatMap is used to flatten stream like unwinding multiple list of values. For example you have a Stream of List of Integer and you want to create Stream of Integer by unwinding those list, you can do that using FlatMap function from java.util.Stream class. Coming back to flatMap, its actually a general concept which is available in other functional programming language like Scala. Just like map() function works by applying a function to each element in the Stream, flatMap works by applying a function that returns a sequence for each element in the list, and flattening the results into Stream or another list. 

Top 16 Lambda Expression and Stream Interview Questions Answers for Java Programmers

For a long time my readers were asking about some Java 8 interview questions, particularly on lambda expression, streams and around language changes e.g. default methods, method reference and functional interface. Finally, I am able to put some common Java 8 interview questions on lambda expression and Stream API and essential functional programming concepts like map, flatmap, and reduce together, which I going to share with you in this article, but before that, let's talk a little bit about impact of Java 8 in Java Developers interviews and why it's imperative for Java programmers to learn Java 8, particularly Lambda and Stream API in 2022. 

How to Join Two or More Tables in a SQL query? Left Join Example Leetcode Solution

Hello guys, when it comes to combining two tables in SQL, many programmers don't know that they can use the JOIN clause. In fact, JOIN is there to fetch data from multiple tables together. There are mainly two types of joins, INNER Join and OUTER join. On Inner join, only those records have matching values in both tables, while in Outer join, all records from one table are selected in addition to matching records from other tables. There are two kinds of Outer join in SQL, LEFT OUTER JOIN and RIGHT OUTER JOIN. Both are actually the same thing, which means you can get the same result by using either of the outer joins by changing the table's position from left to right.

Top 21 GraphQL Interview Questions and Answers for Beginners and Experienced Developers

Hello guys, if you are preparing for web developer interviews where GraphQL skills are needed and you are looking for frequently asked GraphQL Interview questions then you have come to the right place. Earlier, I have shared both Web development interview questions as well as REST Interview Questions and in this article, I am going to share 20 common GraphQL Questions from Interviews with answers. These questions covers essential GraphQL concepts like difference between REST And GraphQL and pros and cons of using GraphQL to consume APIs. If you have used GraphQL in past then you can easily answer these questions but if you forgot then you can always join of these best GraphQL online courses to learn and revise key GraphQL concepts.

Top 20 CSS Interview Questions and Answers for 1 to 2 Years Experienced Web Developers

Hello guys, if you are preparing for web developer job interview and looking for common CSS Interview Questions then you have come to the right place. Earlier, I have shared HTML Interview questions and CSS Interview Questions and in this article, I am going to share 20 common CSS Interview Questions with answers. If  you have used CSS for a couple of months then most likely you know the answer of these CSS questions but if you struggle with any of them then you can always go back to these best CSS online courses to revise key concepts. I have tried to include as many questions as possible covering different CSS concepts but you can also contribute, feel free to ask questions on comments. 

Is CodeGym Good Place to Learn Java? Is CodeGym Premium Worth it?

>Hello guys, if you are learning Java or want to learn Java but not sure if CodeGym is the right place for you or not then you have come to the right place. Earlier, I have shared best places to learn Java coding for FREE and in this article, I will review CodeGym, one of the interactive platform to learn Java. But, Before we see whether CodeGym is worth it for learning and mastering Java, let me tell you a little bit about what CodeGy really is.   CodeGym is an excellent and innovative alternative to traditional learning platforms like Udemy and Coursera. It is basically a platform that is designed for young and passionate people who want to learn Java. The CodeGym platform aims to deliver practical learning with the help of games that can make learning fun and interesting.

Top 30 Gradle Interview Questions with Answers for Java Developers

Hello guys, if you are preparing for Java developer interview then you must have come across Gradle, a Groovy based build tool which is gaining popular with Java community. While its not mandatory to learn Gradle for Java Interview if the job description mention Gradle or Groovy then you should prepare Gradle is one of the essential tool for Java developers. It's similar to  Maven and ANT, two other popular build tool for Java project but offers several advantages which I have explained in Maven vs Gradle post earlier.  These Gradle questions are good for both beginners and Java developer with 1 to 3 years of experience which are using Gradle in their project or expecting Gradle question on Java Interview.

How to use Composite Design Pattern in Java? Example Tutorial

Hello Java Programmers, if you want to learn about Composite Design patterns in Java, like how to implement Composite design pattern and when to use it then you have come to the right place. Earlier, I have shared the best Java design pattern courses and in this article, I am going to talk about Composite design Patterns, one of the 24 GOF patterns described in the classic Object Oriented design pattern book.  Composite Design Pattern is a behavioral design pattern from GOF, first described in their classic book design pattern. The composite pattern allows you to build a structure as a tree, which contains both leaf and composites

How to use State Design Pattern in Java? Vending Machine Example

The state design pattern is a behavioral pattern, first introduced by GOF in their class is book design patterns. State pattern looks similar to Strategy pattern but it helps in managing object state and thus enabling them to behave differently in a different state. In this example, we will take a famous object-oriented design interview question, implementing Vending Machine in Java. In the past, we have solved this problem without using any design pattern, but here we will use state design patterns to create a vending machine with different states.  This example will not just help you to understand how to implement State Design Pattern in Java but also gives you experience about when to use State Pattern on your application. 

Top 17 Interview Questions to Test debugging Skill of Java Programmers

Hello guys, if you are a beginner or an experienced Java developer with 1 to 3 years of experience under your belt, when you go for a Java interview you should prepare some Java debugging interview questions like how to debug a Java program running in Linux environment etc. In the past, I have shared 130+ core Java questions, 50+ Multithreading Questions, 25+ Java Collection questions and 50+ Lambda and Stream interview questions and in this article, I am going to share 17 questions to test debugging skills of Java programmers. While a couple of questions are Java related but many questions are also based upon problem solving and general debugging skill which can be used to test any programmer like Python, JavaScript or C++ programmer. 

Top 12 Locking, Synchronization and Multithreading Interview Questions for 5 to 7 Years Experienced Java Programmers

Hello guys, if you are an experienced Java developer say 3 to 5 years or 5 to 7 years experience and  preparing for Java Interviews then you very well know that Locking, Synchronization, ConcurrentHashMap, volatile and atomic, compare and swap (CAS), Executor Service, Stream API, and Multithreading in general are quite important and as an experienced Java developer you should be ready for them. In the past, I have shared 50+ Java Multithreading questions, 12 concurrency questions, 21 HashMap questions, and 10 ConcurrentHashMap questions and in this article, I am going to share 10 of my favorite question on Locking, Synchronization and Inter thread communication in Java. If you have been doing Java Interviews then its highly likely that you have already seen this problem but if you haven't you should definitely prepare them.

Top 20 Mockito Interview Questions with Answers for Java Programmers

Hello guys, if you are preparing for Java developer interview then you must prepare for Mockito, one of the most popular mocking and unit testing library for Java developers. Mockito is used across all kind of companies, both big and small like startups for unit testing Java applications and that's why good knowledge of Mockito is required to crack the Java Interview. Along with JUnit, Mockito is quite important and if you are looking for Mockito Interview questions and answers then you have come to the right place. Earlier, I have shared best JUnit and Mockito courses and unit testing books, and even popular JUnit interview questions and in this article, I am going to share 20 common Mockito questions for your interviews.

Top 35 Python Interview Questions with Answers 1 to 3 Years Experienced Programmers

Hello guys, if you are preparing for a Python developer job and looking for some frequently asked Python interview questions then you have come to the right place. Earlier, I have shared the Complete Python Developer RoadMap,  best books and best courses to learn Python and in this article, I am going to share 35 Python questions, covering different concepts for Python developer interviews. Sitting in any interviews, especially in tech interviews, is a tough job itself. You can't go in without proper preparation. Even if you have taken or given dozens of interviews, it is always recommended to go through the quick preparation notes or concepts.

10 Reasons to learn JavaScript Programming Language in 2022

Hello guys, if you want to become a web developer but not sure whether JavaScript is the right programming language or not, or want to learn JavaScript but not sure whether its worth the effort then you are the right place. Earlier, I have shared best JavaScript courses, books, and best places to learn JavaScript and in this article, I am going to share 10 key reasons to learn JavaScript in 2022. In the last five decades, hundreds of programming languages have been made. Most of these programming languages never even caught public attention. Only a handful of them actually became popular. Though, these handfuls of programming languages also make a long list. 

3 best ways to learn Web Development in 2022

Web development has changed a lot in the recent decade. More and more frameworks and libraries have come out while the older ones are either updated or left out. For example, React and Vue has debuted in the mid-2010s and quickly became popular while AngularJS was completely re-written to survive modern web development. Today, Web development is one of the most popular domains in the IT community. Every company or product wants a website because the web is easily accessible today. Even when mobile applications are gaining popularity, the web remains at the top. 

Top 20 System Design Interview Questions with Answer for 1 to 3 Years Experienced

Hello guys, if you are preparing for FAANG or any Software developer Job Interview on Startup or a Tech company like Spotify, Flipkart, or Zoom but worried about System design questions then you are not alone. System design is an intimidating topic and requires a lot of study and experience to design a real world system. While it's not a rocket science the knowledge of different system design components and concepts are hard to acquire. In the past, I have shared best System Design Courses and best Software architecture courses as both are related to each other and in this article, I am going to share 20 System Design Interview Questions with answers for programmers with zero to 3 years of experience. 

9 Best System Design Interview Courses for Beginners and Experienced Software Developers

Hello guys, if you are preparing for System design interview and looking for best online courses to learn essential System design concepts like load balancing, scalability, architecture as well as how to solve popular System design questions like how to design YouTube, WhatsApp, Parking Lot, Library System as well when to use NoSQL and SQL then you have come to the right place.  In the past, I have shared best System Design BookSystem design prep guide, and System Interview Questions and in this article, I am going to share best places to learn System design in 2022. Before we get to the best  Before we get to the 9 best courses that will teach you everything you need to know about system design interviews, let me tell you a little bit about what it really is.

Top 20 Spring Cloud Interview Questions with Answers for 3 to 5 Years Experienced

Hello guys, if you are preparing for Spring and Microservice developer job and need Spring cloud interview questions then you have come to the right place. Earlier, I have shared interview questions on Spring Boot, Spring MVC, Spring Security, Spring Testing and Spring Core and in this article I am going to share common Spring Cloud questions for Java and Microservice developers. If you have used Spring Cloud in your project then you can answer all of these questions easily but if you struggle to answer any of these questions then you can always go back and join one of these best Spring Cloud courses and best Microservice courses to learn and revise essential Spring Cloud concepts. 

Top 35 React.js Interview Questions with Answers for Fullstack Java Developers

Hello guys, if you are preparing for React developer interviews and looking for frequently asked React.js interview questions then you have come to the right place. Earlier, I have shared the best courses, books, and websites to learn React.js and in this article, I am going to share 35 frequently asked React.js interview questions, suitable for 1 to 2 years experience developers. ReactJS is one of the most recently built open-source front-end programming languages. It came directly from Facebook's headquarter back in 2011. Earlier Recat.js was only limited to Facebook but now, it is one of the most extensively used programming languages all across the world.

Difference between Proxy and State design Pattern in Java

Hello guys, if you are preparing for Java interviews and looking for difference between Proxy and State design pattern then you have come at the right place. In the past, I have explained several important object oriented design patterns like State patttern, Strategy, Adapter, Facade, Factory, Observer, Decorator, Command, and Composite Pattern and also shared frequently asked questions on design patterns (See here) and in this article, I am going to share the key difference between Proxy and State Design Pattern in Java and OOP. The difference between Proxy and State pattern comes in both intent and structure, here are the key difference between both Proxy and State Design Pattern in Object oriented programming.

Top 20 Apache Kafka Interview Questions Answers for Java Developers

Hello, guys if you are preparing for the  Java Developer or Apache Kafka interview and looking for frequently asked Apache Kafka interview questions and answers then you have come to the right place. Earlier, I have shared the best Kafka courses and popular interview questions on JavaJMSSpring Boot, and Hibernate and in this article, I Am going to share 20 frequently asked Apache Kafka interview questions with answers. Over the years, Kafka which is developed by Apache Software Foundation has gained popularity because of its immense capability of data processing. Apache Kafka provides a unified, high-throughput, low-latency platform for handling real-time data feeds and because of that it has become a go to choice for high-speed message for many fortune 500 companies.  

Difference between @Mock and @MockBean in Spring Boot? Example Tutorial

Hello guys, if you are writing test for your your Spring Boot application then Sooner or later, you'll come across @Mock and @MockBean annotations while testing your Spring Boot application. Both annotations generate fake or Mock  objects, but for different reasons and its important for Java and Spring Boot developer to know the correct difference and when to use @Mock and @MockBean while writing tests. It's possible that this will seem perplexing at first, in face I was confused for a long time until I did my research and cleared it up. But, you don't need to scan through internet, In this blog article, I'll clear up any misunderstandings and clarify the difference between @Mock and @MockBean when testing Spring Boot apps.

Top 25 DevOps Interview Questions and Answers for Experienced Developers

Hello guys, if you re preparing for DevOps Engineer interviews and looking for frequently asked DevOps Interview questions then you have come to the right place. Earlier, I have shared the DevOps RoadMapbest DevOps Courses, and DevOps books and in this article, I will share the frequently asked DevOps Interview Questions and their Answers. But, before we get to the most frequently asked DevOps interview questions, let me tell you what DevOps actually is. DevOps is basically a way of thinking or a collective approach to all the tasks that a company's application development and IT operation teams perform but it has taken the IT software development world by storm.

How to test a Spring Boot Application using JUnit, Mockito, and @SpringBootTest? Example Tutorial

Hello guys, if you are wondering how to test your Spring Boot application then you are at the right place. In the past, I have shared several Spring and Spring Boot resources like best Spring boot coursesbest Spring Boot booksSpring Boot Interview questions and even Spring Boot projects and in this article, I am going to share how to test your Spring Boot application using @SpringBoot annotation. This article will teach you essential concept for testing Spring Boot applications. It's expected that you are know about essentially the fundamentals of Java, Maven and Spring Boot (Controllers, Dependencies, Database Repository, and so on).

Top 20 Spring Data JPA Interview Questions with Answers for 3 to 5 Years Experienced Java Programmers

Hello guys, if you are preparing for Spring and Java developer job interview and looking for common Spring Data JPA interview questions then you have come to the right place. Earlier, I have shared spring boot questions, spring cloud questions, spring security questions, and spring MVC questions and in this article, I am going to share 20 common Spring Data JPA questions with answers. These are simple questions focused on key Spring Data JPA concepts like finder methods, query methods, pros and cons of Spring Data JPA, how to implement Spring Data JPA repository interface etc. If you have done work or used Spring Data JPA in your project then most likely you will be familiar with those concepts but if not then don't worry, you can also checkout these Spring Data JPA courses to learn them in detail. 

Top 20 Maven Interview Questions with Answers for Java Programmers

Hello guys, if you are preparing for Java developer interviews then you should not ignore Maven as its on of the important build tool for Java developers. Most of the Java projects you are going to work will use Maven for building artifacts and deploying into both Physical machine and cloud. If you already know the importance of Maven and looking for frequently asked Maven interview questions then you have come to the right place. Earlier, I have shared 130+ core Java questions, Spring Boot questions, Hibernate Questions, and even JUnit questions for thorough preparation and in this article, I am going to share 20 common Maven questions from Java interviews with answers. 

Top 20 Linux Interview Questions with Answers for 1 to 3 Years Experienced Developers

Hello guys, if you are preparing for Developer and DevOps interview and looking for Linux questions for interviews then you have come to the right place. Earlier, I have shared popular UNIX Interview questions and DevOps Interview Questions and in this article, I am going to share 20 common Linux questions from interviews with Answers. These questions covers essential Linux commands like Linux file system, permission model, Linux commands, shell and kernels etc. If you have worked in Linux then you can easily answer these questions but if you have forgot them then you can always join these best Linux courses to learn and revise key Linux concepts before interviews. 

Top 20 Docker Container Interview Questions Answers for Developers and DevOps

Hello guys, if you are preparing for DevOps Engineer interview or a Software developer job interviews like Java developer then preparing about Docker is a good idea. Docker has become an essential tool for packaging and deploying Software, particularly Microservices, and you can expect a couple of questions about Docker during Interview to check your knowledge. Having absolutely no idea of Docker before going into interview can be detrimental to your prospect considering the importance of container on deploying apps and services on Cloud. That's why I always programmers and developers to prepare Docker interview questions and revise key Docker concepts before interview. 

Top 40 Java HashMap Interview Questions and Answers for 3 to 5 Years Experienced

The HashMap and ArrayList is two of the most useful classes from JDK and every Java programmer should be familiar with them. Because of their usefulness, they are also very popular on Java interviews. You will always find a couple of questions on HashMap, ArrayList and its close cousins like Hashtable and ConcurrentHashMap on various Java interviews, ranging from freshers to experienced, junior to senior programmers, and telephonic to face-to-face interviews. To help my readers to better prepare for Java interviews, I have shared some of the essential ArrayList interview questions in my last article and today I am going to share  frequently asked questions on Java HashMap. 

Difference between State and Strategy Design Pattern in Java

Hello guys, if you are wondering what is difference between State and Strategy pattern in Java then you are at the right place. In order to make proper use of State and Strategy design Patterns in any Java application, it's important for a Java developer to clearly understand the difference between them. Though both State and Strategy design patterns have a similar structure, and both of them are based upon the Open closed design principle, which represents 'O' from SOLID design principles, they are totally different on their intent. The strategy design pattern in Java is used to encapsulate a related set of algorithms to provide runtime flexibility to the client. 

Decorator Design Pattern in Java with Example Java Tutorial

Hello guys, if you want to learn about Decorator design pattern in Java then you are at the right place. I was thinking to write on decorator design pattern in Java when I first wrote 10 interview questions on Singleton Pattern in Java. Since design patterns are quite important while building software and it’s equally important on any Core Java Interview, It’s always good to have a clear understanding of various design patterns in Java. In this article, we will explore and learn the Decorator Design pattern in Java which is a prominent core Java design pattern and you can see a lot of its examples in JDK itself. 

Data Access Object (DAO) design pattern in Java - Tutorial Example

Data Access Object or DAO design pattern is a popular design pattern to implement the persistence layer of Java application. DAO pattern is based on abstraction and encapsulation design principles and shields the rest of the application from any change in the persistence layer e.g. change of database from Oracle to MySQL, change of persistence technology e.g. from File System to Database. For example, if you are authenticating the user using a relational database and later your company wants to use LDAP to perform authentication. If you are using the DAO design pattern to access the database, it would be relatively safe as you only need to make a change on Data Access Layer. DAO design pattern also keeps the coupling low between different parts of an application.

How to use for loop in Linux? Looping through List, values, and range in Bash with Example

If you know how to use for loop in bash shell or Linux, you can speed up a lot of task, saving precious time while doing support or troubleshooting in Linux. One of my favorite use of for loop is repeating same task among multiple host. For example, If I have to clean up some files from 10 hosts in the network, instead of manually going and removing files from individual host, you can use for loop and ssh command to automatically remove old log files from all the host, without manually logging into them. This is a tremendous time saving trick if you are working for an application which is running on more than one host. It's a life-saver if your application is running on 30 to 40 hosts. 

What is SRP of SOLID Design Principle? Single Responsibility Principle Example in Java

Hello guys, if you want to learn about SRP or the Single Responsibility principle and wondering how to write code that follows SRP and what are pros and cons of following this design principle then you have come to the right place. Earlier, I have shared the best object-oriented programming and design courses and books and in this article, I am going to talk about SPR. The Single Responsibility Principles, popularly known as SRP is part of 5 Object-oriented design principles, introduced by Robert C. Martin, popularly known as Uncle Bob. The Single Responsibility principle says that "there should be one reason to change a class". This means a class should do only one thing, and do it perfectly.

Top 5 Online Courses to Learn Kubernetes in 2022 - Best of Lot

Hello guys, Kubernetes has become a very popular tool and skill today in the container management community, and it's one of the most in-demand skills and a must-learn tool for both DevOps engineers and Developers. It is a tool written in Golang and it is created by Google. There are many things you need to take care of when working in production environments with microservice patterns and containers. These include version control, health check, rollback mechanism, and scaling. Kubernetes provides the management and orchestration capabilities to deploy containers in accordance with all the necessary mentioned things.

How to Convert a Map to a List in Java - Example Tutorial

Hello guys, if you are wondering how to convert a Map like HashMap or TreeMap to a List like ArrayList or LinkedList in Java then you are at the right place. Earlier, I have shared 10 examples of converting a List to Map in Java and this article, I am going to share my tip to convert a given Map to a List in Java. Map and List are two common data structures available in Java and in this article, we will see how can we convert Map values or Map keys into List in Java. The primary difference between Map (HashMap, ConcurrentHashMap, or TreeMap) and List is that Map holds two objects key and value while List just holds one object which itself is a value. 

How to design Trade Position Calculator or Risk Engine in Java? Software Design Problem Solution Example

Hello guys, it's been a long since I shared object-oriented design and system design questions in this blog. It was almost 7 to 8 years when I last blogged about how to solve vending machine design problems in Java. Actually, I had ideas for lots of such design questions at that time, but because of the lengthy nature of these kinds of posts and the amount of time they take, they just sit on my list of drafts. I thought to take them out and publish then slowly improve on them instead of publishing the perfect post for the first time, and today, I am excited to share one of such problems, how to design a trade position aggregator in Java. This program is like portfolio management software that monitors your risk and exposure in real-time based on trades. 

Top 20 Kubernetes Interview Questions with Answers

Hello guys, if you are preparing for DevOps Engineer interview or a Developer interview, knowledge of Kubernetes is very important given the rise of Cloud computing and cloud native development. If you are looking for frequently asked Kubernetes interview questions to quickly revise key Kubernetes concepts then you have come to the right place. Earlier, I have shared 20 Docker Interview Questions and in this article, I am going to share frequently asked Kubernetes Interview questions with Answers. But, before we get to the 20 most important Kubernetes interview questions, let me tell you more about Kubernetes. In the most simple terms, Kubernetes is actually a bundle of software solutions that allow developers and engineers to scale and service server setups.

How to display full argument list of a Running Process in Linux and Solaris? Example

One of the problems with ps command, which is a popular tool to find any processes along with the grep command in the Solaris operating system is that it doesn't show full command-line argument of process. This means if you are doing grep on any text which appears at the tail end of the long command line, you will likely not able to capture that process by using ps and grep. This is dangerous because it may lead you to assume that certain process is not running and you may restart it again, despite its being running and only because you didn't find the process.

How to Prepare for System Design Interview in 2022? Topics, Questions, and Resources

The Software Engineering job market is on fire! Especially if you have a couple of years of experience under your belt. And in the world of Software Engineering, if you are applying for a Senior Engineer / Lead / Architect / or a more senior role, System Design is the most sought-after skill, and hence one of the most important rounds in the whole process. If you mess this up, nothing else would matter. If you get it right though, you’re looking at a raise of at least tens of thousands of dollars annually.

How to add element at the head and tail of a LinkedList in Java? Example

Hello guys, if you are wondering how to add an element at the start and at the end of a linked list in Java then you are at the right place. LinkedList is an implementation of linked list data structure in Java and whenever you need a linked list you can use this. It also provides convenient methods to add elements like addFirst() to add any element at the fist position and addLast() to add element at the last position or tail of the linked list. Since LinkedList also implement List and Queue interface in Java, you can also use the common methods defined in the List and Queue interface to interact with LinkedList object in Java. In the past, I have also shared how to sort a LinkedList in Java and in this article, I will teach how you can use LinkedList in Java and how you can add object at the head and tail position of a linked list in Java. 

10 Linux Commands and Options Every Developer should Learn

Hello guys, you might have read many articles about popular Linux commands on the internet but this article is a bit different. In this article, I am going to share some lesser-known options of essential Linux commands like find, grep, mkdir, etc, which many Linux users, including programmers, don't know, even after using the command for quite some time. For example, cp -p is an option that I discovered quite late but ever since I discovered it I have been using it regularly as it preserve timestamp and I can see when this file was originally created. I am going to share 10 such Linux command examples in this post, which I am sure you will love it and if you already know them, then there is a good chance that you have something similar to share with us in the comments section. 

10 Example of find command in UNIX and Linux

The find command is one of the most versatile commands in UNIX and Linux, and I used it a lot in my day-to-day work. I believe having a good knowledge of find command in UNIX and understanding of its different options and usage will increase your productivity a lot in UNIX based operating systems, e.g. Redhat Linux or Solaris. If you are a QA, support personnel, and your works involve lots of searching text on Linux machine or if you are a Java or C++ programmer and your code resides in UNIX, find command can significantly help you to look for any word inside your source file in the absence of an IDE.

How to use mkdir command to make directories in Linux and UNIX? mkdir -p Example

One of the most common tasks in any Linux is creating directories, and most of us spend a lot of time creating complex directory structures in UNIX and Linux.  I am sure you know about the mkdir command, we have been using this command in almost every operating system like DOS, Windows, Linux, OS/2, Solaris, or any other *NIX operating system. It is one of the basic commands but as important as find, grep or chmod.  mkdir stands for "make directory" and this command is literally used to create directories. Suppose, you need to create a directory tree-like /opt/software/java/app/config, how are you going to create these directories? One by one right? Well, yes you can use mkdir and command to create these directories one by one as shown in below example :

Top 5 Software Design Courses for Programmers in 2022 - Best of Lot

Hello guys, if you are preparing for technical interviews for Software Engineering job then you may be aware of  Software Design or System design. It is one of the most important but at the same time very tough topic to master and many programmers even experienced developer struggle to solve System design problems during interview, particularly while interviewing with top tech companies like Google, Meta, Amazon, Apple, Microsoft, Netflix etc, popularly known as FAANG. If you are also preparing for programming job interview and looking for best System design and Software design resources then you are at the right place. Earlier, I have shared best System Design Books, System Design Questions and best Places to learn System Design and in this article, I am going to share best System Design Interview courses from Udemy, one of my favorite place to learn programming and technical stuff. 

How hostname to IP address Conversion works in Linux? nslookup Example

One of my favorite Linux Interview questions is about how to convert hostname to IP address in Linux? These questions not just test the candidate's basic Linux command skills but also shows his understanding of how name resolution works in UNIX or Linux? Many developers, software engineers, and support professionals don't really know how Linux converts a hostname into IP address or what happens when they type http://www.amazon.com in their browser in UNIX? They are not really familiar with how the name amazon.com is resolved to an IP address.

How to Delete Empty Files and Directories in UNIX or Linux Host? find Command Example

Deleting empty file and directory in Unix
Hello guys, if you are wondering how to find and remove all empty files and directories from a Linux host then you are at the right place. Earlier, I have shared Linux command to free disk space by removing big files and directories and in this article, I will share find command you can use to remove empty files and directories. Many times we need to find and delete empty files or directories in UNIX/Linux. Since there is no single command in Unix/Linux which allows you to remove empty files or empty directories rather we need to rely on find command and xargs command

How to find big directories and files to free space in Linux? find + du + sort + head command Example

Hello guys, 100% full disk space is a common problem and as a programmer or Linux user, you often need to free disk space by deleting biggest files and directories. In order to do that, you need to know some Linux find command examples to list and delete some biggest files and directories and that's what you will learn in this tutorial. As a Java developer, you also need to also support your application, most of which mostly run on Linux machines. Though production is monitored by the dedicated support teams and they receive regular alerts on the status of file system space, they often come running to you or the developer responsible about what to do when disk space is almost full or reaching 100%.

10 Example of SSH command in Linux and UNIX

Hello guys, if you have been working in Linux machine then there is great chance that you have come across SSH and SCP commands which are essential to switch between different hosts in a Linux network. As a Java developer, I need to work on more than 30 to 40 servers which contains development server, UAT servers, production servers as well as server from different regions like Asia, Middle East, UK, and the USA. It's difficult to work between server if you don't how to go from one host to other or copy data between them like files and directory and that's where this SSH commands comes handy. The SSH is one of the essential Linux commands which allows you to log in to remote host using secure socket protocol. By default, the SSH program listens on port 22..

How and when to use var to declare local variables in Java? Example Tutorial

Hello guys, In this series of new features of Java 10 articles, today, I am going to talk about probably the most popular and most useful, the introduction of var keyword (well, it's not really a keyword but I'll you later about it) in Java. If I am not wrong, this feature was supposed to come on Java 9 but dropped later. Finally, Java also has a var keyword to declare local variables which allows you to declare a variable without their type like instead of doing String str = "Java" you can now just say var str = "Java". This may not sound much gain when declaring String or an int variable but consider complex types with generics, this will surely save a lot of typing and also improves the readability of code.

How to merge two sorted array in Java? Example Tutorial

Hello guys, if you want to learn how to merge two sorted arrays in Java then you have come to the right place. Earlier, I have shown you how to sort arrays in Javaand in this article, I will show you how to merge two sorted arrays in Java. Btw, if you are a complete beginner then Firstly, you need to know what an array is before going about solving this problem about sorted array.  An array is a data structure in java that holds values of the same type with its length specified right from creation time. Think of a container, like a crate of eggs or coke, where number of places are fixed and you cannot change once you created it.

How to implement Selection Sort in Java? Example Tutorial

Hello guys, if you are wondering how to implement selection sort algorithm in Java then you are at the right place. In the past, I have taught you how to implement Bubble SortQuick SortMerge SortInsertion SortRadix Sort, and Counting sort and in this article, I am going to teach you how to implement the Selection sort in Java. Along with above mentioned sorting algorithm, Selection sort is another essential Sorting algorithms which every Programmer should be aware of. This sorting algorithm is a combination of searching and sorting. As the name suggest, it select the minimum number in the array or list and puts it into its correct position. It repeats the same steps on unsorted part until the whole array or list is sorted. It's an in place algorithm which means there is no additional space is required, but the time complexity of selection sort is O(n^2) which means you cannot use this algorithm to sort a large array.

How to convert an Array to HashSet in Java? Example Tutorial

The array was there in Java before the Collection framework makes its entry in JDK 1.4, hence, you will find several legacy codes, which accept an array then the Collection or Set. Due to this, we often need to convert an array to different types of collection e.g. List or Set. Earlier, I have told you the trick to convert an array to a list and today I'll teach you how to convert an array to HashSet by using the same technique. The concept you need to know is that Collection provides a copy constructor i.e. you can pass a collection to create another collection. We'll leverage the same fact and to create a HashSet, we'll pass an ArrayList.

List.of(), Set.of() and Map.of() Example in Java - How to create Immutable Map, List, and Set in Java

Hello guys, this is my first article in Java 9 features on this blog, and today you'll learn about my favorite feature "factory methods for collection", which is introduced as part of JEP 269. The JEP stands for the JDK enhancement proposal. If you have worked in Groovy or Kotlin then you know that how easy is to create the list with elements using collection literals e.g. to create a list of 1, 2, 3 you can simply write val items = listOf(1, 2, 3). Unfortunately, Java doesn't support that yet but things have been improved with the factory methods for collection in JDK 9 and it's almost like that. JDK has added static factory methods like of() on to basic Collection interfaces which you can use to create a list of items.

Difference between HashMap, LinkedHashMap and TreeMap in Java with Example

Hello guys, if you are wondering what is difference between HashMap, TreeMap, and LinkedHashMap in Java and when to use them then you are at the right place. In past, I have shared frequently asked HashMap Interview questions and ConcurrentHashMAp Interview questions and today, I Will answer this question in detail. The java.util.Map is one of the most important interfaces from the Java Collection Framework.  It provides hash table data structure functionality by its implementations like HashMap, Hashtable, LinkedHashMap, and a little bit of sorting with the TreeMap. So if you are looking to store key-value pairs in the Java program,  you have a wide range of choices available depending upon your requirement. The main difference between LinkedHashMap, TreeMap, and HashMap comes in their internal implementation and specific features, which a Java programmer should know to use them effectively. 

How to use @RequestBody and @ResponseBody Annotations in Spring? Example Tutorial

Hello Java programmers, if you are wondering how and when to use use the @RequestBody and @ResponseBody annotation in Java then you are at the right place. Earlier, I have shared how to create RESTful Web Service using Spring Boot and today I will teach you how and when to use these two crucial annotations @RequestBody and @ResponseBody. While developing client server Java application using Spring Framework you may need to connect the HTTP request and response body with the domain object while working on the REST API. The annotations @RequestBody and @ResponseBody in Spring were used to bind these HTTP requests and responses. In simple words, these are teh annotations which converts JSON to your Java object and your data to JSON while sending to client. Let's look at these two Spring annotations in more detail.

Why use @Override annotation in Java? Coding Best Practice Example

@Override annotation was added in JDK 1.5 and it is used to instruct the compiler that method annotated with @Override is an overridden method from super class or interface. Though it may look trivial @Override is particularly useful while overriding methods that accept Object as a parameter just like equals, compareTo or compare() method of Comparator interface. @Override is one of the three built-in annotations provided by Java 1.5, the other two are @SuppressWarnings and @Deprecated

4 Example to Iterate over Map, HashMap, Hashtable or TreeMap in Java

There are multiple ways to iterate, traverse or loop through Map, HashMap, or TreeMap in Java and we are all familiar with either all of those or some of those. But to my surprise, one of my friends was asked in his interview (he has more than 6 years of experience in Java programming) to write code for getting values from HashMap, Hashtable, ConcurrentHashMap, or TreeMap in Java in at least 4 ways. Just like me he was also surprised by this question but written it. I don't know why exactly someone asks this kind of java interview question to a relatively senior java programmer. Though my closest guess is to verify that whether he is still hands-on with coding in java. 

Java HashMap ContainsKey and ContainsValue Example - How to check if a Key Exists in Map?

Hello guys, one of the common problems many Java developers working with HashMap face is how to check if the Map contains a particular key or value? You can use this to check duplicate keys or just to ensure that you are not overriding the current value because if you insert a key that already exists in the HashMap, then you end up overriding its value. Since HashMap also allows duplicate values, it's also possible that the same value may be paired against multiple keys, so just removing a mapping may not be enough to remove that particular value. Not paying attention to these details has actually caused issues in the Java applications.

How to get Key From Value in Hashtable, HashMap in Java? Example

It's not easy to get key from the value in Hashtable or HashMap, as compared to getting value from key because HashMap or Hashtable doesn't enforce one to one mapping between key and value inside Map in Java. in fact, Map allows the same value to be mapped to multiple keys inside HashMap, Hashtable, or any other Map implementation. What you have in your kitty is Hashtable.containsValue(String value) or Hashtable.containsKey(String key) to check whether key or value exists in HashMap or not, but sometimes we want to retrieve a value from Map corresponding to any key and there is no API method to do in Map.