Preparing for Java and Spring Boot Interview?

Join my Newsletter, its FREE

Wednesday, July 24, 2024

What is the delegating filter proxy in Spring Security? How it works?

The Delegating filter proxy or DelegatingFilterProxy is a spring aware class which implements javax.servlet.Filter interface and used to activate Spring security in a web application. Since Filters are created and maintained by Servlet or Web Container this filter is declared in web.xml and it is configured to process request for all URLs, which means every request and response pass through this filter. In other words, DelegatingFilterProxy works as a proxy between Web Container and Spring Container. It passes all request and response to Spring Security to implement security constraints e.g. performing authentication or authorization. 

5 Ways to Loop or Iterate over ArrayList in Java?

Looping over an ArrayList in Java or Iteration over ArrayList is very similar to a looping Map in Java. In order to loop ArrayList in Java, we can use either foreach loop, simple for loop, or Java Iterator from ArrayList. We have already touched iterating ArrayList in 10 Example of ArrayList in Java and we will see them here in more detail. We are going to see examples of all four approaches in this ArrayList tutorial and find out which one is clean and the best method of looping ArrayList in Java? But, before start writing an example for loop in ArrayList let's think about why do we need to iterate, traverse or loop an ArrayList if it’s based on the index and backed by Array.

Saturday, July 20, 2024

How to get the selected radio button on click using jQuery? Example Tutorial

In last couple of articles, you have learned how to get all checked checkbox and how to find the unchecked checkbox using jQuery, let's see another similar example, this time with radio button. Suppose, in form you have two radio buttons to select the gender i.e. male and female. How do you find which radio button was selected when user clicked on them? well, we will use the jQuery selector to find that. In fact, its not much different than what you have used to find the checked checkbox i.e. $("input[type=radio]:checked") will give the selected radio button. In order to find the chosen radio button when user click, you need to bind a click handler.

Friday, July 19, 2024

10 Example of Hashtable in Java – Java Hashtable Tutorial

Hello Java programmers, if you are wondering how to use Hashtable class in Java then you have come to the right place. In this Java Hashtable tutorial, I am going to share how to use Hashtable in Java with examples. These Java Hashtable Examples contain some of the frequently used operations on Hashtable in Java. when I discussed throw of How HashMap or Hashtable works in Java I touched based on the inner working of Hashtable, while in this Java Hashtable tutorial we will see more examples of Hashtable in Java like checking a key exits in HashMap or not or get all keys and values from HashMap, Iterating on Hashtable keys and values using Enumeration, checking if Hashtable contains a particular key or value, how to copy mappings from a Hashtable to HashMap in Java, etc.

Thursday, July 18, 2024

How to sort a Map by keys in Java 8 - Example Tutorial

Hello Java friends, In the last article, I have shown you how to sort a Map by values in Java 8, and in this tutorial, you will learn how to sort a Map by keys like a HashMap, ConcurrentHashMap, LinkedHashMap, or even Hashtable. Theoretically, you cannot sort a Map because it doesn't provide any ordering guarantee. For example, when you iterate over a HashMap, you don't know in which order entries will be traversed because HashMap doesn't provide any ordering. Then, how can you sort a Map which doesn't support order? Well, you can't and that's why you only sort entries of HashMap but you don't store the result back into HasMap or any other Map which doesn't support ordering. If you do so, then sorting will be lost.

Wednesday, July 17, 2024

Top 30 Array Interview Questions and Answers for Programmers

The array data structure is one of the most important topics for programming interviews. It doesn't matter if you are going to Google, Microsoft, Amazon or investment banks like Goldman Sachs, Barclays, Citi or even service-based companies like IBM, Accenture, TCS, or Infosys, if you are going to interview for the developer position, you must prepare array very well. In fact, it is the second most topic after String and if you look closely, may of String coding problems can be solved by treating them like character array. The array is also ubiquitous, no matter which programming language you choose, you will find array there, it's available in C, C++, Java and even on Python, Perl, and Ruby.

Monday, July 15, 2024

What is WeakHashMap in Java? When to use it? Example Tutorial

WeakHashMap is an implementation of Map interface in Java. It's a special Map where entries can be reclaimed by Garbage collector if there is no more strong reference exists to the value, apart from the key in the WeakHashMap, which is anyway the weak reference. This property allows a WeakHashMap to be used as Cache, where Garbage Collector can automatically cleanup dead entries. I mean those objects which are only alive inside map but there is no outside entries. Worth noting is that the key are stored as WeakReferences inside WeakHashMap which allows values to be reclaimed if there is no strong reference exists outside.

Sunday, July 14, 2024

17 SQL Query Best Practices Every Developer Should Learn

Hello guys, its no secret that SQL is one of the must have skill in this data driven world and its also one of those skills which is equally useful for programmers, developers, database admins, data scientists, data analyst, business analyst, quality analyst and even project managers. I first learned SQL 20 years back when I was in college and that time we are using Oracle database. I still remember my first query about "SELECT * FROM EMP",  EMP was one of the tables which was quite popular among learners and most of the Oracle DB instance on labs have that. 

Friday, July 12, 2024

How to declare and initialize two dimensional Array in Java? Example Tutorial

There are many ways you can declare a two-dimensional integer array in Java. Since 2D array in Java is nothing but an array of array, you can even declare array with just one dimension, the first one; second dimension is optional. You can even declare a 2 dimensional array where each sub array has different lengths. You can also initialize the array at the time of declaration or on some later time by using nested for loop. So there is lots of flexibility. In this article, you will learn common Java idioms to declare and initialize two dimensional arrays with different lengths. 

What is lazy loading in Hibernate? Lazy vs Eager loading Example

Lazy loading in Hibernate is a feature which allows Hibernate to load the dependent objects lazily to improve performance of Java application. By default Hibernate does eager or aggressive loading for single valued associations (many to one and one-to-one ) and lazy loading for collection-valued associations (one to many or many-to-many). If you set the loading to lazy=false or FetchType.EAGER then object will be eagerly loader, means when an object is loaded from database all its relationship and associated objects are also loaded from Database e.g. when an Author entity object is initialized then all the books written by this author will also be loaded into memory.

Wednesday, July 10, 2024

Difference between @Secured vs @RolesAllowed vs @PreAuthorize, @PostAuthorize Annotations in Spring Security

Spring Security is a powerful framework to implement security on Spring based Java web application as well as on security RESTful Web Services. It also provides method level security, which means restricting access to a method depending upon role and permissions of object. If a user calling the method has access the method will be executed, otherwise AccessDeniedException will be thrown by Spring Security. All these annotations e.g. @Secured, @RolesAllowed, @PreAuthorize, and @PostAuthorize is used to implement method level security in Spring security, but there are some subtle difference between them. 

How to reverse an ArrayList in place in Java? Example [Solved]

How to reverse an ArrayList in place is a popular coding interview problem, not just on Java interviews but also for other programming language. I often ask to check whether candidate is familiar with in place algorithms or not.  You can reverse an ArrayList in place in Java by using the same algorithm we have used to reverse an array in place in Java. If you have already solved that problem then It's a no-brainer because ArrayList is nothing but a dynamic array, which can resize itself. All elements of an array are stored in the internal array itself. 

Tuesday, July 9, 2024

How to Remove Duplicates from Array without Using Java Collection API? Example

This is a coding question recently asked to one of my readers in a Java Technical interview on investment bank. The question was to remove duplicates from an integer array without using any collection API classes like Set, HashSet, TreeSet or LinkedHashSet, which can make this task trivial. In general, if you need to do this for any project work, I suggest better using the Set interface, particularly LinkedHashSet, because that also keeps the order on which elements are inserted into Set. Why Set? because it doesn't allow duplicates and if you insert duplicate the add() method of Set interface will return false. 

12 Apache HTTP Server Interview Questions Answers for 1 to 3 years Experienced

Hello guys, if you are preparing for Java web developer interviews then you must prepare questions on Apache HTTP web server, one of the most popular web server on internet. Knowing how Apache Web Server works not only shows that you have practical experience but also demonstrate your attitude about learning things in depth. The Apache HTTP Server, also known as httpd, has been the most popular web server on the Internet since April of 1996. It is both free and robust and that's the reason that almost half of the world's websites  runs on Apache HTTP web server, ranging from small hobby websites to huge e-commerce giants and big banks. 

Monday, July 8, 2024

17 Scenario Based Debugging Interview Questions for Experienced Java Programmers

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 troubleshooting and debugging interview questions like how to debug a Java program running in Linux environment? have you done remote debugging? have you ever profile your application? Your application is getting OutOfMemoryError, how are you going to find the root cause and fix? etc. These types of scenario based questions are quite popular while interviewing 5 to 10 years experienced Java developers to see their hands-on knowledge and find out they are rusty or not.