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. 

Sunday, July 7, 2024

10 Singleton Pattern Interview Questions in Java - Answered

Singleton design pattern is one of the most common patterns you will see in Java applications and it’s also used heavily in core Java libraries. Questions from the Singleton pattern are very common in Java interviews and good knowledge of how to implement the Singleton pattern certainly helps. This is also one of my favorite design pattern interview questions and has lots of interesting follow-ups to dig into details, this not only checks the knowledge of design pattern but also checks to code, multithreading aspect which is very important while working for a real-life application.

Saturday, July 6, 2024

14 Multicasting Interview Questions and Answers

Hello guys, Multicasting is an important concept for Java developers, particularly those working on high frequency low latency Java application like trading apps, client connectivity and exchange connectivity systems, order management systems (OMS), Algorithm trading system, and smart order routers. As it provides a faster way to deliver messages than TCP. Yes, Multicasting is usually UDP based which is faster than TCP. While UDP doesn't guarantee message delivery, you can use things like sequence number to track messages and replay if a message went missing. Since multicasting is heavily used on big investment banks like JP Morgan, Barclays, Citi, Morgan Stanley, and others on their Java applications, its also an important topics for interviews. Not just on banks but also on many product based companies. 

Friday, July 5, 2024

Top 20 Algorithms Interview Problems for Programmers and Software Engineers

Hello All, If you are preparing for Programming job interviews or looking for a new job then you know that it's not an easy task. You got to be lucky to get a call from recruiter or hiring manager and make it to the first round of interview at any stage of your career but it is even more difficult at the beginner level when you are searching for your first job. That's why you can't just take your chance lightly. You got to be prepared to grab that chance and for that, you must know what is expected from you on the coding interview. What type of questions is asked, what topics should you prepare, etc? 

Wednesday, July 3, 2024

How HashMap works in Java?

Hello guys, if you are looking for an answer of popular Java interview question, how HashMap works in Java? or How HashMap works internally in Java then you have come to the right place. In this article, I will not just answer those question but also many related questions like How get() and put() method works in Java? what role equals() and hashcode() play in HashMap, How HashMap resize itself, and why key object of HashMap should be Immutable in Java. Let's start with the basics first. HashMap in Java works on hashing principles. It is a data structure that allows us to store object and retrieve it in constant time O(1) provided we know the key. Also this is one of my most popular article with more than 6 million views and I have now updated it to include latest information like how HashMap now uses a balanced tree instead of linked list for storing collision objects and new diagrams on HashMap working which provide visual explanations. 

Tuesday, July 2, 2024

Top 12 SQL Query Problems for Coding Interviews (with Solutions)

Hello guys, if you are looking for SQL query examples from interviews or SQL Query Practice questions to improve your SQL skill or just to prepare for tech interviews  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 questions from interviews. SQL is an important skills for both programmers and data scientist, even people from QA and BA stream also need to know SQL to do their job well in this era or data driven world. That's why SQL queries are also quite popular on interviews. 

Monday, July 1, 2024

Top 50 Java Programs from Coding Interviews

Coding problems are an integral part of any programming job interviews, and Java development interviews are no exception. I would even suggest you should never hire anyone without testing their coding skill, but coding is also an art, and more often than a good coder is also an excellent developer. If you look at tech giants like Amazon, Facebook, and Google they thoroughly test the coding skill of any developer they hire, notably Amazon who first send online coding exercises to filter Java programmers who can code from those who can't code. This online test usually gives you requirements and ask you to write a program in a limited time, usually 2 to 3 hours. The application should meet the output provided by the exercise itself. These type of tasks are very tough to crack if you don't have excellent coding skill.

42 Programming Interview Questions for 1 to 3 Years Experienced Programmers (with Answers)

Hello guys, if you are preparing for programming job interviews and looking for previous asked questions or popular questions to get idea what topics are important for interviews then you have come to the right place. In the past, I have shared system design questions, SQL questions, UNIX questions and Java questions and in this article, I am going to share 42 programming interview questions for 1 to 3 years of experienced programmers. Though, its also useful for programmers up to 5 years of experience and we will start with programming questions from telephonic round of interviews. Due to COVID and work from home culture, in the last few years, phone interviews also known as the telephonic round has become the single most popular way to screen candidates in a programming job interview. It's easy for both parties to gauge each other, the candidate doesn't need to travel to the prospective Employer's premises and the Interviewer also doesn't need to make any unnecessary arrangements.