QuickSort Algorithm Example in Java using Recursion - Tutorial

The Quicksort algorithm is one of the very popular sorting algorithms in programming, often used to sort a large array of numbers. Though there is numerous algorithm available to sort a list of objects, including integer, string, and floating-point number, quicksort is best for general purpose. It's a divide and conquers algorithm, where we divide the given array with respect to a particular element, known as 'pivot' such that the lower partition of the array is less than the pivot and upper partition elements of the array are higher than the pivot.

How to remove a number from an Integer Array in Java? [Example Tutorial]

Hello guys, In the last article, you have learned how to reverse an array in place in Java, and today I have come back with another array-based coding interview question. It's also one of the frequently asked coding questions, not as popular as the previous one but still has been asked a lot of times on various Programming Job interviews, particularly to beginners. In this problem, you are asked to write a program to remove a given number from the given array. It may seem easy, but the trick is that because an array is a fixed data structure and you cannot change the length of the array once created. 

3 ways to sort a List in Java 8 and 11 - Example Tutorial

There are multiple ways to sort a list in Java 8, for example, you can get a stream from the List and then use the sorted() method of Stream class to sort a list like ArrayList, LinkedList, or Vector and then convert back it to List. Alternatively, you can use the Collections.sort() method to sort the list. There is also a sort() method added to the List class itself. The Collections.sort() method is an older one and it's available from JDK 1.0 itself but List.sort() is a new method added in Java 8. This method accepts a Comparator if you want to sort a List in a custom order, otherwise, you can pass null if you want to sort a List on the natural order of their elements. 

5 Free SQL Books For Beginners and Experienced - Download PDF or Read Online

There is no doubt that SQL is one of the most essential skills for Programmers, IT professionals, Software Engineers, Quality Analysts, Project Manager, Data scientists, Database admins, and Business Analysts. I had even mentioned this as one of the top skills in my post about 10 things every programmer should know, if you haven't read that yet, you can read it here, it's completely worth your time. Since many Enterprise applications use the relational database at their backend, like Oracle, Microsoft SQL Server, MySQL, it's crucial to learn SQL to work with those applications and use the data stored on those databases.

How Binary Search Algorithm Works? Java Example without Recursion

The binary search algorithm is one of the fundamental Computer Science Algorithms and is used to search an element in a sorted input set. It's much faster than the linear search which scans each and every element and improves performance from O(n) to O(logN) for searching an element in the array. In order to perform the binary search, you need a sorted array, so you can either ask the user to enter the array in sorted order or you should sort the array before performing the binary search. It's also one of the popular algorithms for Programming Job interviews. The interviewer often asks candidates to implement binary search algorithms by hand in their favorite programming languages like Java, C++, Python. or JavaScript.

How to solve java.lang.NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton in Spring Boot [Solved]

Problem:
I was trying to run a HelloWorld program using Spring Boot when I got this error:

Exception in thread "main" java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer due to internal class not found. This can happen if you are @ComponentScanning a springframework package (e.g. if you put a @ComponentScan in the default package by mistake)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:52)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:92)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:174)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:136)

10 Examples to DateTimeFormatter in Java 8 to Parse, Format LocalDate and LocalTime

Parsing and formatting dates are other essential topics while working with date and time in Java. Even though the old Date API had the SimpleDateFormat and DateFormat class to support the formatting of date and parsing texts, they were not simple, or should I say there were just simple in writing the wrong code. You might know that SimpleDateFormat was not thread-safe and quite heavy to be used as a local variable. Thankfully, this has been sorted now with a new LocalDateTime class and DateTimeFormatter class, which has several inbuilt formats.

How to declare and Initialize two dimensional Array in Java with Example

An array of more than one dimension is known as a multi-dimensional array. Two of the most common examples of multi-dimensional arrays are two and three-dimensional arrays, known as 2D and 3D arrays, anything above is rare. I have never seen 4-dimensional arrays, even 3D arrays are not that common. Now the question comes when to use a multi-dimensional array? Any real-life example? Well, 2D arrays are very common on platform games like Super Mario Bros to represent screen or terrain; 2D arrays can also be used to represent structures like a spreadsheet, or to draw board games like Chess, which requires an 8x8 board, Checkers and  Tic-Tac-Toe, which requires 3 rows and 3 columns.

Difference between first level and second level cache in Hibernate

The main difference between the first level and second level cache in Hibernate is that the first level is maintained at the Session level and accessible only to the Session, while the second level cache is maintained at the SessionFactory level and available to all Sessions. This means, you can use the first-level cache to store local data, i.e. the data which is needed by the Session, and you can use the second-level cache to store global data, i.e. something which can be shared across sessions. This is also one of the frequently asked Hibernate Interview questions and accessible in both telephonic rounds as well as on the face-to-face interviews, in both fresher and experienced level interviews.

Difference between IN, OUT, and INOUT parameters in JDBC Stored Procedure? Answer

Hello guys, Java Database Connectivity, the JDBC API supports three types of parameters, I mean, IN, OUT, and INOUT. They are used to bind values into SQL statements. An IN parameter is the one whose value is unknown when the SQL statement is created and you bind values using various setXXX() method depending upon the type of column those IN parameter refers in SQL query. For example in SQL query, SELECT * from EMPLOYEE where EMP_ID=? if the EMP_ID is a VARCHAR column then you must call the setString() method to pass the value to the IN parameter. 

How to use lifecycle methods in functional components in React.js? useEffect() hook Example Tutorial

Hello guys, if you have been following my blogs then you know that I have launched a new series - React for Java developers and this is the 4th article on the series. Earlier, we have seen state management in React, Redux, and useState hooks example, and in this article, you will learn about how to use lifecycle methods in functional React components. Lifecycle methods are powerful features provided by React.js in the class-based components. Each of the lifecycle methods executes at a particular time during the lifecycle of a component. 

How to compare two Arrays in Java to check if they are equal - [String & Integer Array Example]

Hello guys, one of the common Programming, the day-to-date task is to compare two arrays in Java and see if they are equal to each other or not. Of course, you can't compare a String array to an int array, which means two arrays are said to be equal if they are of the same type, has the same length, contains the same elements, and in the same order. Now, you can write your own method for checking array equality or take advantage of Java's rich Collection API. Similar to what you have seen while printing array values in Java, java.util.Arrays class provides convenient methods for comparing array values.

How to Convert or Print Array to String in Java? Example Tutorial

Array and String are very closely related, not just because String is a character array in most of the programming language but also with popularity - they are two of the most important data structure for programmers. Many times we need to convert an array to String or create an array from String, but unfortunately, there is no direct way of doing this in Java. Though you can convert an array to String by simply calling their toString() method, you will not get any meaningful value.  If you convert an Integer array to a String, you will get something like I@4fee225 due to the default implementation of the toString() method from the java.lang.Object class. Here, I show the type of the array and content after @ is hash code value in hexadecimal.

How to Format Date to String in Java 8 [Example Tutorial]

One of the common programming tasks in Java is to change the date format of a given Date or String. For example, you have something like "2017-01-18 20:10:00" and you want to convert it that date into "2017-01-18", or you want to convert from dd-MM-YY to MM-dd-YY or to any other format of your choice and need, but a valid date format as per Java specification. How will you do that? Well, it's not that difficult. It's just a two-step process. In the first step, you need to parse String to create an equivalent date using the current format, and then once you got the date, you need to again convert it back to String using the new format. The same process is repeated in both Java 8 and before, only corresponding API and class changes.

Can you Overload or Override main method in Java? Example

One of the common doubts among Java beginners while learning the overloading and overriding concept is, whether it's possible to overload the main in Java? Can you override the main method in Java? How will JVM find if you change the signature of the main method as part of the method overloading? etc. These are good questions and show the curiosity and application of knowledge of students, so if you are the tutor you must answer these questions. If you don't know the answer to this question, don't worry, just read this article till the end and you will find the answer yourself.  I have tried to explain in simple words but if you still can't get it, feel free to comment and I will try to help you personally. 

10 Advanced Programming and Development Books for Experienced Developers - Best of Lot

Hello guys, if you are looking for some advanced programming and development books to take your coding and software development skill to next level then you have come to the right place. Earlier, I have shared advanced courses in Java, Python, C++, and JavaScript and in this article, I am going to share some good books for the experienced programmer which can help them to become an expert. Learning never stops but once you become a professional programmer and spent a couple of years doing professional programming, you need to make some effort to reach the next level i.e. to become an expert programmer. Continuously doing the same stuff and not analyzing will not make you better. This is where these books can help you.

4 Examples of Stream.collect() method in Java 8

Hello guys, you may know that Java 8 brought Stream API which supports a lot of functional programming operations like filtermapflatMap, reduce, and collect. In this article, you will learn about the collect() method. The collect() method of Stream class can be used to accumulate elements of any Stream into a Collection. In Java 8, you will often write code that converts a Collection like a List or Set to Stream and then applies some logic using functional programming methods like the filter, map, flatMap and then converts the result back to the Collection like a ListSetMap, or ConcurrentMap in Java.

Difference between List and ArrayList Reference Variables in Java? Example Tutorial

Someone who is just starting with Java programming language often has doubts about how we are storing an ArrayList object in List variable, what is the difference between List and ArrayList? Or why not just save the ArrayList object in the ArrayList variable just like we do for String, int, and other data types. Well, the main difference between List and ArrayList is that List is an interface while ArrayList is a class. Most importantly, it implements the List interface, which also means that ArrayList is a subtype of the List interface. In Java or any object-oriented language, the supertype of a variable can store an object of subtype.

How to Increasing Heap Size of Java application in JVM? Example Tutorial

Hello guys, if you are wondering how to change the heap size of the heap space of your Java application then you have come to the right place. In this article, I am going to tell you how to increase Java heap space so that your JVM will not crash using OutOfmemoryError. We have already seen how to increase heap memory in Maven and ANT and now we will learn how to increase heap size in Java, Eclipse, Tomcat, and WebSphere Server in a series of articles. Since all these are Java applications, once you know how to change heap space in Java, you can do that in any Java application, provided you know the right place, which is what we will see in this article.

The Ultimate Guide of Remote Debugging in Java using Eclipse IDE? Example Tutorial

The remote debugging of the Java program is an ultimate tool in the arsenal of a Java developer, which is often becoming the last and only tool to investigate a bug on a Java application running on the remote host like on a Linux server or Windows server. Almost all major Java IDE provides remote debugging like NetBeans, Eclipse, and IntelliJ IDEA, but I mostly use Eclipse for Java coding and so it's my preferred tool to remote debug a Java program. In order to set up remote debugging in Eclipse, you need to do a couple of tasks like you need to start your JVM with debugging parameters or arguments and then you need to create a "remote debug configuration" in Eclipse IDE itself.

How to Convert java.util.Date to LocalDate in Java 8 - Example Tutorial

Hello guys, once you move to Java 8, you will often find yourself working between old and new Date and Time API, as not all the libraries and systems you interact with will be using Java 8. One of the common tasks which arise from this situation is converting old Date to new LocalDate and that's what you will learn in this tutorial. There seems to be a couple of ways to convert a java.util.Date to java.time.LocalDate in Java 8, but which one is the best way? We'll figure it out in this article, but first, let's explore these different ways to convert a java.util.Date object to LocalDate in Java 8 code.

How to parse String to LocalDate in Java 8 - DateTimeFormatter Example

From Java 8 onward, you are no longer dependent on the buggy and bulky SimpleDateFormat class to parse and format date Strings into real Date objects in Java e.g. java.util.Date. You can use the DateTimeFormatter class from java.time package for all your formatting and parsing need. You are also no longer required to use another buggy class java.util.Date if you are doing fresh development, but if you have to support legacy code then you can also easily convert LocalDate and LocalTime to java.util.Date or java.sql.Date. In this tutorial, we will learn about both parsing String to date in Java and formatting Date into String.