Sunday, April 28, 2024

Top 17 Spring AOP (Aspect-Oriented Programming) Interview Questions Answers

If you are preparing for Java and Spring Developer interviews or Spring professional certification then a good knowledge of Aspect-oriented Programming or AOP is required. It's a boring and tough topic but important from a Spring interview and Spring certification point of view and that's where these 15+ AOP interview questions come really handy. You can use them to revise key AOP concepts before any telephonic or face-to-face interview as well as to learn and explore more about Aspect-Oriented ProgrammingIn this article, I am going to share frequently asked AOP interview questions and also tried to answer AOP questions give on the official Spring certification exam guide.

20 Design Patterns and Software Design Interview Questions for Programmers

Design patterns and software design questions are an essential part of any programming interview, no matter whether you are going for a Java interview or a C#  interview. In fact, programming and design skills complement each other quite well, people who are good programmers are often good designers as well as they know how to break a problem in to piece of code or software design but these skills just don’t come. You need to keep designing, programming both small-scale and large-scale systems, and keep learning from mistakes. 

Saturday, April 27, 2024

Top 5 Spring Boot Features for Java Development

You might have heard about Spring Boot and its magical powers about creating a Spring Web application in just under 140 characters which can be written in a tweet, but what does that really mean? What are those features which provide Spring Boot such power and make Spring application development so easy? Well, that's what you will learn in this article, but if you are in hurry let me tell you that you will learn about Spring Boot's auto-configuration, Starter dependencies, Spring Boot CLI, Actuator, and Spring Initializer feature in detail. These are the feature that takes away most of the pain and friction associated with writing a Spring-based Java web application.

Friday, April 26, 2024

What is bean scope in Spring Framework? Example Tutorial

Java classes or POJO which are managed by Spring Framework are called Bean or Spring Beans and Bean scope in Spring framework or Spring MVC is scope for a bean managed by Spring IOC container. Bean scope refers to the lifecycle and visibility of a bean instance in spring container. The scope determines how long the bean instance will live and how it will be shared with the other parts of application. You may know that Spring is a framework that is based on Dependency Injection and Inversion of Control and provides bean management facilities to Java application. In Spring-managed environment bean (Java Classes) are created and wired by the Spring framework. Spring allows you to define how those beans will be created and the scope of the bean is one of those details. Scope are similar to access modifiers in Java which specifies visibility of a particular class. 

Thursday, April 25, 2024

Difference between @RequestMapping and @GetMapping in Spring MVC? Example

Hello Java programmers, if you are wondering what is the difference between @RequestMapping and @GetMapping annotation in Spring MVC and when and how to use them then you have come to the right place. Earlier, I have shared the best Spring MVC courses and books, and In this tutorial, we are going to discuss about Spring MVC and spring boot web services. In there, most of the interviewers asked about the difference between @RequestMapping and @GetMapping annotations in spring applications. Before going to discuss the difference between these annotations, first, understand what is @RequestMapping?, How do we use the @RequestMapping?, What is a request? and types of them.

Wednesday, April 24, 2024

Spring Boot @Transactional Annotation Example - How to Manage Transactions using Spring Framework?

One of the most essential parts of Spring MVC is the @Transactional annotation, which provides support for transaction management and allows developers to concentrate on coding business logic rather than worrying about data integrity in the event of system failures. In other words, @Transactional annotation  simplifies the process of transaction management and it allows you to specify transactional behavior directly within your code, typically at the service layer. You can put @Transactional annotation both at the class level and method level. When you put the @Transacational at the class level, it applies to all the public method of the class but when you put the @Transacational annotation at the method level. It only applies to that method. 

Tuesday, April 23, 2024

4 Ways to take Heap dump in Tomcat and Java and 3 Tools to Analyse .hprof files

The heap dump is a great source of information on identifying memory related issues on Java application e.g. web and application servers like Tomcat, WebLogic, JBoss, WebSphere and IDEs like IntelliJIDEA and Eclipse. When you take heap dump all live objects of heap with their count and other details are written into a huge file (the .hprof file) for analysis. The name and location of heap dump file is provided by command you use to take the heap dump. There are many command line tools in JDK e.g. jmap and jcmd which can be used to take the heap dump in Java. 

Monday, April 22, 2024

Top 50 Java 8 Stream, Lambda, and Functional Programming Interview Questions

Hello guys, if you are preparing for Java interviews and looking for some Java 8 Stream, Lambda Expression, and other Java 8 features then you have come to the right place. Earlier, I have shared 140+ Core Java interview questions, 50 Java Programs from Interviews and 20+ Spring Boot questions and in this article, I am going to share Stream, Lambda expression, and other Java 8 feature-based questions.  Java 8 features are now not remained as good to know features. They have been increasingly adopted by many organizations and most of the new development encourage developers to write code in Java 8 style to take full advantage of massive CPU power available in modern servers like HP 380 Gen 8 servers, also known as G8. 

Sunday, April 21, 2024

Top 3 Design Patterns and Best Practices Java Developers Can Learn From Spring Framework

There is no doubt that the Spring Framework is one of the most popular Java frameworks and makes it really easy to create real-world, enterprise-grade Java applications easy by providing features like dependency injection and inversion of control. But, to be honest, Spring is much more than just another DI and IOC framework. It goes one more level to simplify many Java APIs like JDBC, JMS, Java Mail, etc by providing a useful layer of abstraction. It's much more comfortable to work with JDBC with Spring's JdbcTempalte and other utility classes. They remove most of the friction Java developer faces with respect to executing SQL statements and processing ResultSet to get the Java object they want.

2 Reasons of org.springframework.beans.factory.BeanCreationException: Error creating bean with name [Solution]

The Spring framework is one of the most popular frameworks for developing Java applications. Apart from many goodies, it also provides a DI and IOC container that initializes objects and their dependencies and assembles them together. The Java classes created and maintained by Spring are called Spring bean. At the startup, when the Spring framework initializes the system by creating objects and their dependencies depending upon @Autowired annotation or spring configuration XML file, it throws "org.springframework.beans.factory.BeanCreationException: Error creating a bean with name X" error if it is not able to instantiate a particular Spring bean.

Top 21 Spring Framework and Spring Boot Testing Interview Questions Answers for 2 to 5 Years Experienced

Testing is an important part of Software development but many people don't pay attention to it only to find bugs in the later stages of development that can be easily avoided by unit testing. When it comes to Java and Spring Boot development, we are lucky to have JUnit, Mockito, JsonPath, AssertJ, and some in-built testing facilities on Spring Framework and Spring Boot for our testing needs. Since the advent of DevOps, there is an increased focus on automation testing and that's why unit testing and integration testing has become important topics on Java Interviews and it's essential for Java developers to have in-depth knowledge about how to test a Spring framework and Spring Boot based Java application.

Friday, April 19, 2024

Differences between @RequestParam and @PathVariable annotations in Spring MVC?

The Spring MVC framework, one of the most popular frameworks for developing a web application in Java world also provides several useful annotations to extract data from the incoming request and mapping the request to the controller, like @RequestMapping, @GetMapping, @RestController, @RequestParam, and @PathVariable. Even though both @RequestParam and @PathVariable are used to extract values from the HTTP request, there is a subtle difference between them, which makes them a useful question from a Spring Framework interview and spring certification point of view. We'll examine the subtle difference between @RequestParam and @PathVaraible in this article.

Top 25 Spring Security Interview Questions Answers for Java Developers

Hello guys, Spring Security is one of the most popular security frameworks in the Java world and I strongly believe that every experienced Java developer should learn it. Because of its popularity, there is always some question on Spring Security on Java interviews but there are not enough resources to prepare for that. That's why when  I shared the Spring MVC questions and spring boot interview question last year, a lot of you asked me to share similar interview questions on Spring Security, Spring Cloud, and Microservices. I listen to those requests and have been doing some research since then to write those articles. 

Thursday, April 18, 2024

How Spring MVC Framework works? How HTTP Request is processed?

Hello guys, one of the frequently asked Spring MVC Interview questions is about explaining the flow of web requests i.e. how an HTTP request is processed from start to end. In other words, explaining the flow of requests in Spring MVC. Since many of my readers ask this question time and again, I thought to summarize the flow of request processing in a short article. It all starts with the client, which sends a request to a specific URL. When that request hits the web container like Tomcat it looks into web.xml and finds the Servlet or Filter which is mapped to that particular URL. It the delegate that Servlet or Filter to process the request. Since Spring MVC is built on top of Servlet, this is also the initial flow of requests in any Spring MVC based Java web application.

Thursday, April 11, 2024

10 Examples of @RequestMapping Annotation in Spring MVC and REST

The @RequestMapping annotation is one of the most important annotation of Spring MVC which provides mapping of HTTP requests to controller methods, I mean Java methods on Controller class for processing. If you wonder, how Spring handles a particular request and which method from controller class is called for a particular request, answer lies on @RequestMapping annotation. This annotation maps web request to methods on controller class. You can apply @RequestMapping on class or method level of your controller. This is a powerful annotation and give you a lot of option to sophistically map a web request e.g. you can narrow down mapping by using HTTP headers, HTTP methods e.g. PUT or POST, and by using Query parameters.

Top 3 Books to Learn Java for C and C++ Programmer?

In the last 2 decades, many Java programmers started programming with C and C++, but the situation is changed now, you have more choices like you can choose Python, or you can even start with Java. It seems Academia prefers Python in the USA and Java in India, but there are still many programmers who know C and C++ and want to learn Java for one or other reasons. I often receive emails from my readers about book recommendation, and recently, a couple of them asked me to suggest the best Java books for C and C++ programmers. I can relate those beginners to myself because I have also gone through the same phase, but those days, the university textbooks are our only source to learn new things. We didn't have broadband, and unlimited access to the Internet and eBooks was not popular at that time, but things have changed.

Wednesday, April 10, 2024

How to limit Concurrent Login Sessions in a Java web application using Spring Security? Example

If you don't know, Spring security can limit the number of sessions a user can have in a Java web application. If you are developing a web application especially a secure web application in Java JEE then you must have come up with the requirement similar to many online banking portals have like only one session per user at a time or no concurrent session per user. If the user tries to open a new session then either an alert is shown or his previous session is closed. Even though you can also implement this functionality without using spring security but with Spring security, it's just a piece of cake with coffee :). 

2 Ways to setup LDAP Active Directory Authentication in Java - Spring Security Example Tutorial

The LDAP authentication is one of the most popular authentication mechanism around the world for enterprise application and Active directory (an LDAP implementation by Microsoft for Windows) is another widely used LDAP server. In many projects, we need to authenticate against active directory using LDAP by credentials provided in the login screen. Sometimes this simple task gets tricky because of various issues faced during implementation and integration and no standard way of doing LDAP authentication in a Java web application. Even though Java provides LDAP support but in this article, I will mostly talk about spring security because of it's my preferred Java framework for authentication, authorization, and security-related stuff.

10 Things Aspiring Java Developers Should Learn in 2024

Hello guys, if you are a beginner looking for a job as Java developer but not sure what you should know or learn to become a professional Java developer then you have come to the right place. In the past, I have shared the best Java coursesbookswebsites, and even a complete Java developer roadmap and today, I am going to share few must know things to become a professional Java developer. I have interviewed many freshers and computer engineers from colleges, interns, and new hires, so for the people fresh out of school and colleges, here are some of the things I wish/hope they know before applying for developer job.

Entuware or Whizlabs? Which Exam Simulator Should you Buy for Java Certifications (OCAJP, OCPJP, and Others)?

I often receive queries from Java certification aspirants about exam simulators like whether should I go for Whizlabs or Enthuware, which one is better? If I have to buy just one exam simulator, which one would you recommend, Whizlabs or Enthuware? I thought to answer all those questions in a blog post and here you go. To be honest with you both of them are really high-quality test simulators and whichever you buy, you will do well on actual exams. But, as a programmer, I really like to analyze the situation, I compare pros and cons of each of them before I buy one of them. Since I have used both of them in the past I am sure about that in quality, they are neck to neck there, but here are couple of things which you can consider before buying Java certification simulator from Whizlabs or Enthuware?

Monday, April 8, 2024

How HTTP Basic Authentication works in Spring Security? Explained

In the last article, I have taught you how to enable Http basic authentication in Spring security-based Java application, and now we'll go one step further to understand how exactly http basic authentication works in Spring security. If you remember, when you use HTTP Basic for authentication purposes, the client, like a browser or a rest client sends login credentials in the http request header. The header is aptly named "Authorization," and it contains a Base64 encoded string, which is created by concatenating username and password using a colon. For example, if the username is "johnsmith" and the password is "JOHN3214" then they will be concatenated as "johnsmith:JOHN3214" before encoded using base 64 encoding algorithms.

Top 5 Software Development and Project Management Books - Best of Lot, Must Read

Hello guys, if you are looking for Software development and Project management books then you have come to the right place. Earlier, I have shared Software development and project management courses and today I am going to share best books you can read on Software development and project management. You may be wondering, Why software development project managers should read books? Isn't they are experienced enough to become a project manager and handle software development and manage Programmers? A genuine question, but Software management is harder than any other management purely because every Software or Project is different than the previous one. Many other streams of engineering, like Civil or Mechanical, got better in terms of estimation and management with the help of software, but software development is still run on experience.

How to send HTTP request using curl and wget command from Linux and UNIX? Example Tutorial

You can use either curl or wget command to send HTTP requests from UNIX or Linux operating system. Both commands allow you to send GET and POST requests, which means you can also call REST web services.  I have a Java web application, which runs on Linux and exposes WebServices. I was writing a UNIX script to download In some data from that web service when I hit by the question, how do I make an HTTP call from UNIX? What is the UNIX command should I use? If you are also facing the same problem, then you have come to the right ht place. Basically, you can use two UNIX commands to make the HTTP request, wget, and curl.

How to Prepare for Java 8 Certifications - Oracle Java SE 8 Programmer 1 (1Z0-808) and II (1Z0-809)

Today one of my readers asked about what is the latest OCPJP or Oracle Java exams available and is there a Java certification available for Java SE 19 and Java SE 17?. This prompted me to browse through Oracle's certification website. During my casual browsing, I noticed that even though it's almost a year since Java SE 9 was released and 6 months since Java SE 20was released the latest Java certification is still the Java SE 17 certification. I know, you might be thinking about Java SE 11 certification, which is the latest Java certification available, but still many programmers are going for Java 8 because that's what they use in their production environment. 

How to Fix Exception in thread "main" java.util.ConcurrentModificationException in Java? [Solved]

Hello guys, if you are struggling to solve Exception in thread "main" java.util.ConcurrentModificationException" error in Java and wondering why this error comes even if you are not using multiple threads then you have come to the right place. In this tutorial, I will tell you everything about this error like why it comes and how you can solve it. One of the common problems while removing elements from an ArrayList in Java is the ConcurrentModificationException. If you use classical for loop with the index or enhanced for loop and try to remove an element from the ArrayList using remove() method, you will get the ConcurrentModificationException but if you use Iterator's remove method or ListIterator's remove() method, then you won't get this error and be able to remove the element. 

How to fix java.lang.numberformatexception for input string null - Cause and Solution

The java.lang.NumberFormatException comes when you try to parse a non-numeric String to a Number like Short, Integer, Float, Double etc. For example, if you try to convert . "null" to an integer then you will get the NumberFormatException. The error "Exception in thread "main" java.lang.NumberFormatException: For input string: "null" is specifically saying that the String you receive for parsing is not numeric and it's true, "null" is not numeric. Many Java methods which convert String to numeric type like Integer.parseInt() which is used to convert String to int, Double.parseDoble() which convert String to double, and Long.parseLong() which convert String to long throws NumberFormatException to inform that the input String is not numeric.

How to fix java.net.SocketException: Software caused connection abort: recv failed

Out of many client servers related socket errors here is one more interesting socket related error from the Java program, "java.net.SocketException: Software caused connection abort: recv failed". The key point in this error message is "abort" and "recv", which means is someone (client or server) is trying to read from a closed connection. This error usually comes at the client socket end, when the server closed the connection before the client has read the response, but, in general, it can come to an end of the TCP socket, so you must check the log files for both clients and server to find out who is complaining. If the Server is complaining then it's fine and the client has closed the TCP connection may be due to timeout or any RuntimeException at the client end.

How to Sort an HashMap by values in Java 8 - Example Tutorial

In the last article, I have shown you how to sort a Map in Java 8 by keys, and today, I'll teach you how to sort a Map by values using Java 8 features e.g. lambda expression, method reference, streams, and new methods added into the java.util.Comparator and Map.Entry classes. In order to sort any Map, like HashMap, Hashtable, LinkedHashMap, TreemMap, or even ConcurrentHashMap, you can first get a set of entries by using the entrySet() method and then you can get the stream by calling the stream() method. The entrySet()  method returns a Set which inherit the stream() method from the java.util.Collection class. Once you got the stream, you can just call the sorted() method which can sort all Map.Entry objects available in Stream using a Comparator.

10 Example of lsof commands in Linux and UNIX

It's been a long time since I have written anything on UNIX or Linux commands. Still, today, I'll talk about the lsof command, a utility command every system admin and developers love. The lsof command stands for list open file descriptors, and as the name suggests, it is used to find open files by the process. Since almost everything in UNIX are file, you can use lsof command to find an open regular file, a directory, a symbolic link, a special block file, an NFS mounted file, a socket stream, a shared library, a special character file, a regular pipe, a named pipe, an internet socket, a UNIX domain socket, and many others. I have mostly used it to find all the files opened by a particular process, which I will show you in the next section.

How to Convert a Lambda Expression to Method Reference in Java 8?

If you have been coding in Java 8 then you may know that using method reference in place of lambda expression makes your code more readable, hence it is advised to replace lambda expression with method reference wherever possible. But, the big question is, how do you find whether you can replace a lambda with method reference? Yes, it's not that easy, especially if you have been using Java 8 only for a couple of months and struggling to get the functional programming concepts and idioms sorted in your head. Sometimes, IDEs like IntelliJ IDEA and Eclipse does offer some hints to convert lambda expression to method reference but it does make sense to learn the logic behind it, otherwise, it won't make sense.

Does Oracle's Java Certifications is Good to Start your Career as Java Developer?

Being the author of a Java blog and a certified Java programmer, I receive lots of questions about the usefulness of Java certifications like SCJP, now known as OCJP or OCPJP. Questions like, does getting a Java Certification help to land a job, or does certified Java developers earn more or gets better offers, are quite common to Java developers, especially freshers. In this post, I will try to answer a few of these questions based on my own experience as a Java blogger and a certified Java developer. Well, I did my first Java Certification, SCJP (Sun Certification for Java Programmers) along back when SCJP 1.4 was hot and after scoring 100% on that I did two more Java certifications i.e. my SCWCD (Sun Certification for Web Component Developer) and SCMAD (Sun Certified Mobile Application Developer). 

4 Ways to find Nth highest salary in SQL - Oracle, MSSQL and MySQL

One of the most common SQL interview questions is to find the Nth highest salary of employees, where N could be 2, 3, 4 or anything e.g. find the second highest salary in SQL. Sometimes this question is also twisted as to find the nth minimum salary in SQL. Since many Programmers only know the easy way to solve this problem e.g. by using SQL IN clause, which doesn't scale well, they struggle to write the SQL query when the Interviewer keeps asking about the 4th highest, 5th highest and so on. In order to solve this problem effectively, you need to know about some key concepts like a correlated subquery, window functions like ROW_NUMER(), RANK(), and DENSE_RANK()etc. Once you know the generic logic to solve this problem, you can tackle all those variations by yourself.

Sunday, April 7, 2024

Review - Is Grokking Algorithms book by Aditya Bhargava worth it?

Hello guys, I have read many books on data structures and algorithms like Introduction to Algorithms by Thomas H. Corman and Algorithm design manual by Steve S. Skiena, so when I come to know about this book, I thought, just another book on algorithms, but I was wrong. This is not just another book on algorithms but one of the most interesting books you will ever read on Algorithms and Data structure. It doesn't cover all the data structure and algorithms you see in Computer Science but whatever it covers, it does really well and that's what matters most for beginner programmer or Computer Science students.

Top 5 Books to Learn Docker for Beginners - Best of Lot

Hello guys, if you are a developer or software engineer then you might have heard about Docker and containers. Being an author of a Java and Programming blog, I daily receive a lot of questions about Docker like what is Docker? what is Docker compose, which Docker commands should I learn, what is Docker Hub, How can I migrate my application to Docker and how can I deploy Docker container on AWS, Azure, and GCP. These are also some of the common doubts of programmers across the world. Let's start with What is Docker and why a Programmer should learn Docker? Simply speaking, Docker programming language makes project management and deployment seem easy.

Top 5 Books to Learn Core Java for Beginners - Best of Lot

Hello guys, I have shared a lot of books related to Java and related technologies in the past, like books and online courses to learn Spring, Hibernate, JVM internals Java Performance tuning, Multi-threading, and Concurrency, Design patterns, Data structure, and Algorithms, etc., but I haven't shared books for core Java books for beginners yet. Even though I have mentioned a couple of popular titles every now and then, I really didn't have a complete compilation of essential core Java books for beginners. Since Java is one of the most popular programming languages and very useful for getting a job as a Software developer, it has become a choice of programming language to start learning coding and application development, it makes sense to start well with core Java.

SQL Self Join Example - SQL Query to Find Employees Earning More Than Managers - LeetCode Solution

Hello guys, are you looking for a simple example of how to use SELF JOIN in SQL? If yes, then you have come to the right place. This article will show you how to use Self join in solving interesting SQL problems from LeetCode. Along the way, you will also learn this useful SQL concept. So, what are you waiting for? Let's first check the problem, and then we'll write an SQL query using SELF Join to solve this problem.

Write an SQL Query to Find Employees Earning More Than Managers
The Employee table holds all employees, including their managers. Every employee has an Id, and there is also a column for the manager Id, as shown below:

+----+-------+--------+-----------+
| Id | Name  | Salary | ManagerId |
+----+-------+--------+-----------+
| 1  | Joe   | 70000  | 3         |
| 2  | Henry | 80000  | 4         |
| 3  | Sam   | 60000  | NULL      |
| 4  | Max   | 90000  | NULL      |
+----+-------+--------+-----------+

Given the Employee table, write a SQL query that finds employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager because Henry's Manager is Max, who earns 90000, which is more than Henry's salary of 80000.

Difference between row_number(), rank() and dense_rank() window functions in SQL

Though all three are ranking functions in SQL, also known as a window function in Microsoft SQL Server, the difference between rank(), dense_rank(), and row_number() comes when you have ties on ranking i.e. duplicate records. For example, if you are ranking employees by their salaries then what would be the rank of two employees of the same salaries? It depends on which ranking function you are using like row_number, rank, or dense_rank.

Saturday, April 6, 2024

Top 10 Java map() and flatMap() Functional Programming Coding Problems with Solutions

Hello friends, in last a couple of years, I have seen an increase in coding problems where interviewer expect you to solve using functional programming concepts and particularly map() and flatMap(). They do this because they want to know whether you know about these methods or not and whether you can use them in real world scenarios like solving coding problems. I have been collecting such coding problems and today, I am ready with 10 such map and flatMap related coding questions which I am going to share with you. The beauty of these coding interview questions is that you can easily solve them using Stream API and map() and flatMAp() method but if you try to solve them without using Stream API, it could be little tricky.