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

How to iterate over JSONObject in Java to print all key values? Example Tutorial

Hello guys, if you are wondering how to iterate over a JSONObject in Java and print all its fields and values then you have come to the right place. In this article, I will show you how you can print all data from JSONObject in Java. If you know, In json-simple library, one of the top 5 and lightweight JSON library, JSON object is a wrapper class which contains the actual JSON message. In the last article, I have explained how to parse JSON in Java using json-simple library and one question which pops up can we iterate over JSONObject properties? Well, yes, you can iterate over all JSON properties and also get the values from the JSONObject itself. In this article, I'll show you how you can print all keys and value from JSON message using JSONOjbect and Iterator.

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

Hello guys, if you are wondering how to merge two Map like two HashMap in Java then you have come to the right place. In this tutorial,  I will show you step by step to merge two HashMap in Java. 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 maps, then putAll() overrides the value from the second map, which you may or may not want. 

12 Database SQL Index Interview Questions and Answers for 2 to 5 Years Experienced

A good understanding of Index is very important for any programmer working with database and SQL. It doesn't matter whether you are working as DBA or Application developer, working in Oracle, MySQL, or Microsoft SQL Server or any other database, you must have good understanding of how index works in general. You should know different types of index and their pros and cons, how your database or Query engine chooses indexes and the impact of table scan, index scan, and index seek. You should also be able to build upon your knowledge to optimize your SQL queries as well as troubleshoot a production issue involving long running queries or poor performing queries. This is also a great skill for experience developers with 5 to 6 years of experience under his belt. 

50+ Java Collections and Generics Interview Questions with Answers

Hello guys, If you are preparing for Java interviews then you may know that Java Generics and Collections are two of the most important topics, particularly Generics where some of the trickiest Java questions can be asked. They are also used to gauge your experience and depth of your Java knowledge, hence it's imperative for both beginners and experienced Java programmers to prepare this topic well. While the Java Collection framework provides an implementation of some command data structures like ListSetArray, Hash table, Queue, Stack, PriorityQueue, etc, Generics provides Type safety.

Java Consumer Functional Interface Example

A Java Consumer is a predefined function interface that has been introduced by java 8. This type of interface accepts only one argument in order to generate the result. We can use Consumer once an object is ready to be used, so we send the input and it executes some operation on the object without returning any kind of value. In the last few article, I have explained what is Functional interface and showed example of Predicate Interface and in this article, I will show you how to use Consumer functional Interface in Java. 

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

Hello guys, 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. 

Switch case vs if-else-if vs Polymorphism in Java - Example Tutorial

Hello guys, conditionals like if-else and switch are very important for programming. After all, programming is for decision making and that's where these conditional programming elements help, but you may have heard that excessive use of if-else and switch is bad and is often taught as code smell. So does that mean, should you never use a switch case in Java? In this article, I will share my thoughts about using switch case vs if-else and then whether we can use Polymorphism to replace if-else in Java and Programming, but before that let's see what is a switch constructor in  Java. A switch construct allows you to choose between multiple options depending upon input,

8 ways to Sort List in Java 8 using Lambda Expression + Method Reference - Example Tutorial

Hello guys, as a Java developer we often need to sort List like ArrayList, LinkedList, or CopyOnWriteArrayList and while I have share many articles on sorting a list in Java in both increasing order  and deceasing order as well as sorting ArrayList in a custom order using Comparator, things have changed a lot in Java world, especially after Java 8 when Lambda expression and method reference was first introduced. Now there are more declarative and expressive way to sort a List of object in different order based upon different conditions. Enhancements made on Comparator API has also made comparing and sorting object in Java much easier and I have shown the power of new Comparator API in my earlier article about advanced Java Comparator example. I was particularly impressed with comparing() and thenComparing() as they literally make comparison on multiple condition easier. 

Top 5 Common Spring Bean Exception, Error and Solution [BeanDefinitionStoreException, NoSuchBeanDefinitionException, BeanCreationException]

Hello guys, error handling and troubleshooting is an important skill for Java developers. During development you can get variety of exception and sometime they are quite difficult to solve especially if you have no clue what they are and what causing them. Things can be even more difficult if exception is coming from the framework you are using like Spring Framework or Hibernate, that's why its important to know common error and exception for standard framework like Spring. In this article I will explain what BeanDefinitionStoreException, BeanCreationException, NoSuchBeanDefinitionException and BeanDefinitionOverrideException are, what can cause them and how to fix those problems.

Top 20 IT Support Interview Questions with Answers for 2 to 3 Years Experienced in 2023

Hello guys, if you want to start your career as IT support engineer and  preparing for IT support interview and looking for frequently asked IT support questions from interviews then you have come to the right place. Earlier, I have shared UNIX Interview Questions, SQL Interview Questions as well as Java support engineer interview questions and in this article, I am going to share common IT support questions for 3 to 5 years experienced professionals. If you have worked as IT support engineer then most likely you can answer all of these questions but if you struggle to answer them then I suggest you to first go through a comprehensive IT support course like Google's IT support Professional certification on Coursera to learn and revise key concepts required for IT support engineers. Even beginners can join this course to start their career as IT support engineers. 

Java 8 Predicate Functional Interface Example [Tutorial]

In Java 8, there is a defined functional interface which is called Predicate. The Predicate interface receives an argument and based on specific condition it returns Boolean value. It can be helpful in testing and it’s located in java.util.Function package. This is one of the many pre-defined or built-in functional interface which JDK provides. A couple of important ones are Supplier which can be used to produce a value of T (any object) and Consumer which can consume and project like takes data and print to console. forEach() is a good example of method accepting Consumer interface. Similarly many method accept a Predicate and when they do you can simply pass a lambda which generates a boolean by checking a condition.