Preparing for Java and Spring Boot Interview?

Join my Newsletter, its FREE

Sunday, May 12, 2024

How to POST JSON request from Linux to test RESTful Web Services? Example

Even though, Postman is a great tool and chrome plugin to test RESTful Web services for Java developers, I often find myself using "curl" or "cURL" command in Linux for testing RESTful Web Services, particularly Java web services built using Spring or Spring Boot framework. The curl command is easily available on most of Linux hosts and you just need to type a command to sent various types of HTTP requests to your application from Linux command line, as shown here. Though, many RESTful web developer and tester knows this trick, they mainly use GET request to access data from web service and  many of them struggle to send HTTP POST request containing JSON data to create new resources. 

Saturday, May 11, 2024

Role based Access control using Spring Security and MVC, Mapping LDAP Groups to Authorities for Authorization

Authentication and Authorization is an integral part of any Java enterprise or web application. Since most of the company uses LDAP Active directory for authentication, authorization, and Role-based access control (RBAC), it's good to know How to implement Role-based access control using Spring MVC and Spring Security. This is the second part of my articles on using Spring Security for authentication and authorization in Spring MVC based Java application. In the last part, we have learned about doing LDAP authentication against Windows active directory, and in this Spring Security tutorial, we will learn How to map LDAP groups to authorities for implementing Role-based access control or authorization.

Friday, May 10, 2024

3 ways to solve java.lang.NoClassDefFoundError in Java J2EE

I know how frustrating is to see "Exception in thread "main" java.lang.NoClassDefFoundError" while running your Java application. This is one of the dreaded problem in Java  which is also a manifestation of NoClassDefFoundError in Java. I have seen it a couple of times and spent quite a lot of time initially to figure out what is wrong, which class is missing etc. The first mistake I did was mingling java.lang.ClassNotfoundException and NoClassDefFoundError, in reality, are totally different, and my second mistake was using the trial and error method to solve this java.lang.NoClassDefFoundError instead of understanding why NoClassDefFoundError is coming, what is the real reason behind NoClassDefFoundError and how to resolve this.

10 Examples of JdbcTemplate in Spring Framework

Hello Java programmers, If you have been using the Spring framework then you may know that the JdbcTempalte is one of the most useful classes of the Spring framework. The JdbcTempalte class provides lots of convenient methods for performing database-related tasks that take the pain away from using the JDBC API. If you have worked in any real-life Java project which connects to a Database using JDBC then you know that JDBC API is not very convenient to use as it requires a lot of boilerplate code. For example, to execute a simple SELECT query, you first need to create a Connection and Statement object to execute the query and iterate through a ResultSet Object to get the result of the query. Finally, you need to close all of these resources to prevent resource leaks in Java.

How to Solve java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener in Spring? [Example]

If you have worked in Spring MVC then you may be familiar with  
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
which is common problem during deployment. Spring MVC throws  java.lang.ClassNotFoundException:                           org.springframework.web.context.ContextLoaderListener ,
when its not able to find org.springframework.web.context.ContextLoaderListener class which is used to load spring MVC configuration files like application-context.xml and other Spring Framework configuration files defined in context-param element of web.xml in an Spring MVC web application as:

Thursday, May 9, 2024

How to Consume JSON from RESTful Web Service and Convert to Java Object - Spring RestTemplate Example

So far, I have not written much about REST and RESTful web service, barring some interview questions like REST vs. SOAP, which is thankfully very much appreciated by my readers, and some general suggestions about the best books to learn REST and best REST courses in the past. Today I am going to write something about how to consume JSON from a RESTful Web Service in Java using Spring Framework? I will also talk about how to convert the JSON to Java objects using Jackson. You will also learn about the RESTTemplate class from the Spring MVC framework, and how you can use it to create a REST client in Java in just a few lines of code.

Wednesday, May 8, 2024

Spring Boot + Kafka Example (Single and Multiple Consumer) in Java

Hello guys, if you want to use Apache Kafka with Spring Framework or Spring Boot and looking for an example then you have come to the right place. In the past, I have shared the best Spring Boot courses as well as best Apache Kafka courses for Java developers, and in this article, I am going to share how to use Apache Kafka with Spring Boot. You will learn both, to publish and consume messages from Apache Kafka topics in your Spring boot application. By the way, if you don't know, Apache Kafka is an open-source stream-processing software platform developed by LinkedIn and later they donated to Apache software foundation, king of open source development in Java world. 

Monday, May 6, 2024

How to set an "Accept:" header on Spring RestTemplate request? Example Tutorial

Hello Java programmers, if you have been using Spring for REST API development, both creation and consumption then you know that RestTemplate is one of the most commonly used tools for REST service invocations. So one of the major problems you might have in this RestTemplate is that how to set an "Accept" header on Spring RestTemplate request.  In the last article, I have shown you how to POST and Consume JSON using RestTemplate in a Spring Based Java application and In this tutorial, we will go through some important points on how to add headers to RestTemplate and fix the errors related to them. 

Saturday, May 4, 2024

Top 133 Java Interview Questions Answers for 2 to 5 Years Experienced Programmers

Time is changing and so is Java interviews. Gone are the days, when knowing the difference between String and StringBuffer can help you to go through the second round of interview, questions are becoming more advanced and interviewers are asking more deep questions. When I started my career, questions like Vector vs Array and HashMap vs Hashtable were the most popular ones and just memorizing them gives you a good chance to do well in interviews, but not anymore. Nowadays, you will get questions from the areas where not many Java programmer looks e.g. NIO, patterns, sophisticated unit testing or those which are hard to master e.g. concurrency, algorithms, data structures and coding.

Top 22 Spring Interview Questions Answers for Java Programmers [UPDATED]

Hey Java Programmers, if you are preparing for a Java developer interview then you should pay special attention to Spring framework-related questions. Spring framework interview questions are on the rise on Java web development and core Java interviews.  This is obvious given Spring Framework is the best most popular framework available for Java application development and now Spring IOC container and Spring MVC framework are used as a de-facto framework for all new Java development. Because of its popularity,  interview questions from the spring framework are top on any list of Java Interview questions and you should also prepare different Spring topics like Spring Boot, Spring Data JPA, Spring Security, Testing and Spring Cloud, etc to do well on Java developer interviews. 

How to fix @Autowired - No qualifying bean of type found for dependency in Spring Boot? [Solved]

Hello guys, if you are working in a Java and Spring Boot project and you are getting errors like "@Autowired - No qualifying bean of the type found for dependency " then you have come to the right place. Earlier, I have shared how to solve error creating bean with name in Spring framework and In this tutorial, we are going to discuss how to fix @Autowired - No qualifying bean of the type found for dependency. When we come across the org.springframework.beans.factory, we need to be careful. Whether there isn't a qualifying bean of type XXXX accessible, we should see if there is a spring bean called XXXX in the runtime. In most cases, we simply try to inject a bean that isn't defined.

Is "Java Concurrency in Practice" still Valid in the Era of Java 21?

Hello guys, one of my reader Shobhit asked this question on my blog post about 12 must-reads advanced Java books for intermediate programmers - part 1. I really like the question and thought that many Java programmers might have the same doubt whenever someone recommends them to read Java Concurrency in Practice. When this book came first in 2006, Java world was still not sure of about new concurrency changes made in Java 1.5, I think the first big attempt to improve Java's built-in support for multi-threading and concurrency. Many Java programmers were even not aware of new tools introduced in the API like CountDownLatch, CyclicBarrier, ConcurrentHashMap, and much more. The book offered them the seamless introduction of those tools and how they can use them to write high-performance concurrent Java applications.

Friday, May 3, 2024

Difference between @Component, @Service, @Controller, and @Repository in Spring

Before you learn the difference between @Component, @Service, @Controller, and @Repository annotations in the Spring framework, it's important to understand the role of @Component annotation in Spring. During the initial release of Spring, all beans are used to be declared in an XML file. For a large project, this quickly becomes a massive task, and Spring guys recognize the problem rather quickly. In later versions, they provide annotation-based dependency injection and Java-based configuration. From Spring 2.5 annotation-based dependency injection was introduced, which automatically scans and registers classes as Spring bean which is annotated using @Component annotation.

Wednesday, May 1, 2024

Top 20 Spring Framework Annotations Java Developers Should Know

Hello guys, annotations are quite important when working in modern Java application as almost all frameworks and libraries nowadays use annotations, including Spring Framework. There was time when we need to remember classes and methods to make effective use of JDK or any open source library but now we also need to remember annotations. For example, to use JUnit you must know about annotations like @Test, @BeforeEach, @AfterEach, @Disabled and so on. Similarly for Spring framework you need to know annotations like @Configuration, @Bean, @Component, @Service, @Value, @Autowired, @Repository, @Qualifier, @Required and more. 

Tuesday, April 30, 2024

Top 10 Java and Web Development Courses from Udemy in 2024 - Best of Lot

Hello guys, I am sure you all have made your goals and resolutions for this year, like what to learn in 2024. If you haven't, then check out my post 10 Things Java programmers should learn in 2024 for some ideas. If you have already made your goal, then it is time to think about how you are going to achieve them. For example, my top 5 goals in 2024 are to learn Java 17, AWS, Microservices, Spring 5, and Spring Security 5, but how am I going to learn them? Well, I like books and online courses, and that's why I have been searching for some excellent courses on Java, Spring Boot, Microservices, Docker, Web development, and Spring.