Top 10 Udemy Courses for Java Developers - Best of Lot

Hello guys, if you are looking for best Udemy courses to learn Java and Spring Framework then you have come to the right place. Earlier, I have shred best Pluralsight courses for Java developers and best LinkedIn Courses for Java developers and today, I will share best Udemy courses for Java developers in 2024. Before we get to the important part and give you a list of the best courses that you can use to become expert Java programmers, let us start with the basics first. What is Java? In the most basic of terms, Java is a general-purpose, object-oriented, and class-based programming language that is known for having lesser implementation dependencies.

Top 10 Tools for REST API Development and Testing to Learn in 2024

Hello guys, it's been a long time since I have shared useful tools. Last, I have shared the best tools for Java developers to learn and then the best data visualization tools for Data Scientists to learn. So, today, I am going to write about 10 essential tools for REST API development and Testing. These are the tools that will help you in every stage of your REST-based project like design, development, testing, and documentation. If you are creating REST APIs in Java or any other programming language, most of the tools like Postman which are HTTP based are equally useful but a couple of tools are most suitable for Java developers.Without wasting any more of your time, here is my list of 10 useful tools every REST developer should learn

10 Examples of WebClient In Spring Framework and Java

Hello guys, if you are wondering how to use WebClient on Spring Framework and looking for simple how to examples of WebClient then you have come to the right place. Earlier, I have shared 10 example of RestTemplate in Spring Framework and in this article, I Am going to share 10 example of WebClient in Spring. These examples covers everything from sending GET request to REST API and consuming response, and also sending POST, PUT, and PATCH request to RESTful Web Services. You will also learn how to set header like Basic Authentication and Authorization header, cookies and much more.  

Top 20 Firebase Interview Questions and Answers for Developers

Hello guys, if you are preparing for Firebase Developer Job interview or interviewing for a Job where Firebase skills are needed and you need Firebase interview questions to prepare quickly and better then you have come to the right place. Earlier, I have shared HTML Questions, CSS Questions, and JavaScript Questions and tutorials and today I am going to share best Firebase Questions with answers. If you have used Firebase for few months or worked as Firebase developer then most likely you know the answers of these questions but if you struggle then you can always join any of these best Firebase courses to further learn  and revise essential Firebase concepts. 

Difference between wait() and join() methods in Java Multithreading? [Answered]

Hello guys, if you are wondering what is difference between wait() and join method in Java multithreading and when to use each of them then you have come to the right place. Earlier, I have shared best Java multithreading courses and books and today I will answer this common Java threading question for you. Even though both wait() and join() methods are used to pause the current thread and have a lot of similarities they have different purposes. One of the most obvious differences between the wait() and join() methods is that the former is declared in java.lang.Object class while join() is declared in java.lang.Thread class. This means that wait() is related to the monitor lock which is held by each instance of an object and the join method is related to the thread itself. The wait() method is used in conjunction with notify() and notifyAll() method for inter-thread communication, but join() is used in Java multi-threading to wait until one thread finishes its execution.

Difference between Callable and Runnable in Java? call() vs run() method

Hello guys, the difference between the Callable and Runnable interface in Java is one of the interesting questions from my list of Top 15 Java multi-threading questions, and it’s also very popular in various Java Interviews. The Callable interface is newer than the Runnable interface and was added on Java 5 release along with other major changes e.g. Generics, Enum, Static imports, and variable argument method. Though both Callable and Runnable interfaces are designed to represent a task, which can be executed by any thread, there is some significant difference between them. 

What is Volatile Variable in Java? When to Use it? Example

What is a Volatile variable in Java?
The volatile variable in Java is a special variable that is used to signal threads and compilers and runtime optimizers like JIT that the value of this particular variable is going to be updated by multiple threads inside the Java application. By making a variable volatile using the volatile keyword in Java, the application programmer ensures that its value should always be read from the main memory and the thread should not use the cached value of that variable from their own stack. With the introduction of the Java memory model from Java 5 onwards along with the introduction of CountDownLatch, CyclicBarrier, Semaphore, and ConcurrentHashMap.

Difference between synchronized block and method in Java? Thread Example

Synchronized block and synchronized methods are two ways to use synchronized keywords in Java and implement mutual exclusion on critical sections of code. Since Java is mainly used to write multi-threading programs,  which present various kinds of thread-related issues like thread-safety, deadlock, and race conditions, which plagues into code mainly because of poor understanding of the synchronization mechanism provided by the Java programming language. Java provides inbuilt synchronized and volatile keywords to achieve synchronization in Java. The main difference between the synchronized method and the synchronized block is a selection of locks on which critical section is locked.

Producer Consumer Problem with Wait and Notify - Thread Example Tutorial

The Producer-Consumer Problem is a classical concurrency problem and in fact, it is one of the most powerful concurrency design patterns which is used in most multithreaded Java applications. In the last article, I have shown you how to solve the Producer-Consumer problem in Java using blocking Queue but one of my readers emailed me and requested a code example and explanation of solving the Producer-Consumer problem in Java with the wait and notify method as well Since it's often asked as one of the top coding questions in Java. In this Java tutorial, I have put the code example of the wait notify version of the earlier producer-consumer concurrency design pattern. 

Java CountDownLatch Example for Beginners - [Multithreading Tutorial]

Hello Java programmers, the CountDownLatch is an important concurrency utility class that was added in JDK 1.5 to facilitate inter-thread communication without using wait and notify methods, but unfortunately, many Java developers still struggle to understand and use this powerful tool. In this article, you will learn what is CountDownLatch and how to use it to write better concurrent applications in Java. You can use the CountDownLatch if you are spawning multiple threads to do different jobs and want to know when exactly all tasks are finished so that you can move to the next stage. In other words, you can block a thread until other threads complete their task

2 Ways to Read a Text File in Java? BufferredReader and Scanner Examples

You can read a text file in Java by using either Files, BufferedReader or Scanner class. Both classes provide convenient methods to read a text file line by line e.g. Scanner provides nextLine() method and BufferedReader provides readLine() method. If you are reading a binary file, you can use FileInputStream. By the way, when you are reading text data, you also need to provide character encoding, if you don't then the platform's default character encoding is used. In Java IO, streams like InputStream are used to read bytes, and Readers like FileReader are used to read character data.

How to do Inter process communication in Java? MemoryMapped File Example Tutorial

Hello guys, in the past, I have shown you how to do inter-thread communication in Java using wait-notify, and today, I will teach you how to do inter-process communication in Java. There are many ways to do inter-process communication in Java, you can use Sockets, both TCP and UDP, you can use RMI (Remote Method Invocation), you can use web services, or you can use memory-mapped file. The socket is the most common way of achieving inter-process communication if two processes are in two different hosts and connected via a network. RMI and WebService can also be used for similar purposes, but the last one, inter-process communication using memory-mapped files, is particularly useful if you are communicating with other processes in the same host, sharing the same memory and file system.

Why wait() and notify() method should be called inside a loop in Java? Example

Hello Java programmers, if you have used the wait() and notify() method in Java then you know that the standard idiom of calling the wait() method uses a loop, but have you ever thought why? This is even advised by none other than Joshua Bloch, a Java guru and author of the popular Effective Java book, a must-read for any Java programmer. When I first started using this method, I was puzzled why not just use the if block because ultimately we are testing for a condition and then either waiting or going for further processing. An if block is more readable for the testing condition than a while loop like for the classic producer-consumer problem, the waiting condition for producer thread could be written as :

Java CyclicBarrier Example for Beginners [Multithreading Tutorial]

This is the second part of my concurrency tutorial, in the first part, you have learned how to use CountDownLatch and in this part, you will learn how to use CyclicBarrier class in Java. CyclicBarrier is another concurrency utility introduced in Java 5 which is used when a number of threads (also known as parties) want to wait for each other at a common point, also known as the barrier before starting processing again. It's similar to the CountDownLatch but instead of calling countDown() each thread calls await() and when the last thread calls await() which signals that it has reached the barrier, all threads started processing again, also known as a barrier is broken. 

Difference between wait and sleep in Java Thread? Example

Wait vs sleep in Java
Differences between wait and sleep methods in Java multi-threading is one of the very old questions asked in Java interviews. Though both wait and sleep put the thread on waiting for state, they are completely different in terms of behavior and use cases. Thread.sleep(long millis) is meant for introducing pause, releasing CPU, and giving another thread an opportunity to execute while wait is used for inter-thread communication in Java. These methods are defined in java.lang.Object class and available to every object in Java. It is based upon object lock, if you remember every object in Java has an implicit lock, also known as a monitor.

How to Sort ArrayList of Objects by Fields in Java? Custom + Reversed Order Sorting Comparator Example

There are a lot of examples of Sorting ArrayList in Java on the internet, but most of them use either String or Integer objects to explain sorting, which is not enough, because in real-world you may have to sort a list of custom objects like your domain or business objects like Employee, Book, Order, Trade, etc. In order to sort an ArrayList of custom or user-defined objects, you need two things, first a class to provide ordering and a method to provide sorting. If you know about ordering and sorting in Java then you know that the Comparable and Comparator class is used to provide the ordering for objects. 

How to send Email in Java using Spring Framework? JavaMailSenderImpl Example Tutorial

Hello guys, if you want to send emails from your Java application and looking for a Java + Spring Framework tutorial to send emails then you have come to the right place. Earlier, I have shared the free spring framework online courses, and today, I am going to share how to send Emails in the Java application using Spring Framework and JavaMailSenderImpl class which makes it really easy to send emails from Java application.  Email is one of the essential function of any enterprise Java application. Your application will need Email functionality to send reminders, bills, payments, confirmations, passwords, alerts, and several other kinds of system notifications.

How to Delete Objects from ArrayList in Java? ArrayList.remove() method Example

Hello guys, if you are wondering how to remove an element from a given ArrayList in Java then you are at right place. Earlier, I have shared how to sort ArrayList in Java as well how to loop over ArrayList in Java and In this Java ArrayList tutorial, you will learn how to remove elements from ArrayList in Java e.g. you can remove String from ArrayList of String or Integer from ArrayList of Integers. There are actually two methods to remove an existing element from ArrayList, first by using the remove(int index) method, which removes elements with a given index, remember the index starts with zero in ArrayList.

How to convert an ArrayList to Array in Java? Example

Hello guys, if you are wondering how to convert an ArrayList of objects to an array of Object in Java then you have come at the right place. In this article, I will show you a couple of ways to convert an ArrayList to Array in Java. For example, you can start with creating a new array and then copying elements from ArrayList to array, or you can also use use Stream to go through all elements of ArrayList and then collect result in an array. In this example, we will use Arrays.copyOf() method to convert a given ArrayList to array in Java. This method can be used to convert any ArrayList like ArrayList of Integer, String or any custom object to Array in Java. 

ArrayList.contains(), size(), clear, asList(), subList(), toArray(), and isEmpty() Example in Java

Java ArrayList Example
ArrayList in Java is one of the most popular Collection classes. ArrayList is an implementation of the List interface via AbstractList abstract class and provides an ordered and an index-based way to store elements. Java ArrayList is analogous to an array, which is also index-based. In fact, ArrayList in Java is internally backed by an array, which allows them to get constant time performance for retrieving elements by index. Since an array is fixed length and you can not change their size, once created, Programmers, starts using ArrayList, when they need a dynamic way to store object, i.e. which can re-size itself. See the difference between Array and List for more differences. 

How to read a File line by line in Java 8 ? BufferedReader lines() + Stream Examples

Hello guy, if you are wondering how to read a file line by line in Java but not sure which class to use then you have come to the right place. Earlier, I have showed you how to read Excel file in Java using Apache POI API and in this article, I am going to tell you about a useful method from BufferedReader class, the lines() method which can be used to read a file line by line. The BufferedReader.lines() is kind of interesting, letting you turn a BufferedReader into a java.util.Stream in Java 8. This is a very powerful thing as it allows you to tread a file as a stream and then you can apply all sorts of Stream methods like map, count, flatMap, filter, distinct, etc to apply the powerful transformation. We will actually see examples of those in this article by finding out the longest line from the file and printing each line of the file.

Difference between HashSet, TreeSet, and LinkedHashSet in Java

Hello guys, in the last article, we have learned about difference between HashMap, TreeMap, and LinkedHashMap and in this article, we are going to learn about difference between HashSet, TreeSet, and LinkedHashSet in Java, another popular Java interview questions for 1 to 2 years experienced developers. If you are doing Java development work then you know that LinkedHashSet, TreeSet, and HashSet are three of the most popular implementations of the Set interface in the Java Collection Framework. Since they implement a Set interface, they follow its contracts for not allowing duplicates but there is a key difference between them in terms of ordering of elements. For example, HashSet doesn't maintain any order, while TreeSet keep elements in the sorted order specified by external Comparator or comparison logic defined in the objects'  natural order. Similarly, LinkedHashSet keep the elements into the order they are inserted.  

10 Examples of ArrayList in Java

ArrayList Example in Java
Hello guys, In this Java ArrayList Tutorial, we will see 10 common usage of ArrayList with examples. You will learn how to add elements in ArrayList, how to remove elements from ArrayList, how to check if ArrayList contains a given object, how to sort an ArrayList of objects  and several other ArrayList functions which we use daily as a Java programmer. ArrayList is one of the most popular classes from the Java Collection framework along with HashSet and HashMap and a good understanding of the ArrayList class and methods is imperative for Java developers. ArrayList is an implementation of List Collection which is ordered and allows duplicates

How to Fix Reference Error: $ is not defined in jQuery and JavaScript [Solved]

Hello JavaScript developer, if you are wondering how to fix the Reference Error $ is not defined while using jQuery then you have come to the right place. "Reference Error: $ is not defined" is one of the common JavaScript errors which come when you try to use $, which is a shortcut of jQuery() function before you load the jQuery library like calling $(document).ready() function. "ReferenceError: XXX is not defined" is a standard JavaScript error, which comes when you try to access a variable or function before declaring it. Since jQuery is also a JavaScript library, you must first include the declaration of the jQuery function or $() before you use it.

How to fix java.net.SocketException: Broken pipe, Connection reset, and Too many open files in Java?

In this blog, I plan to talk about some common exceptions and errors that arise while using sockets. Quite often, these socket issues arise out of application bugs, system settings, or system load. It might be an unnecessary delay to go to product teams, only to discover that the issue can be resolved by tuning/configuring your local settings. Understanding these messages will not only help resolve the issues but also make a conscious effort in avoiding these scenarios while developing applications.

How to fix ArrayIndexOutOfBoundsException and StringIndexOutOfBoundsException in Java?

Though both StringIndexOutOfBoundsException and ArrayIndexOutOfBoundsException are children of IndexOfBoundsException class, the former is thrown by methods of String and related class like StringBuffer and StringBuilder to indicate that an index is either negative or greater than the size of the String, or more generally not valid. For example, charAt() method throws StringIndexOutOfBoundsException when an index is equal to the length of String? why? because String is backed by character array where index starts at 0 and ends at length -1

How to Fix Spring Boot cannot access REST Controller on localhost (404) Error in Java

Hello guys, if you are getting "cannot access REST Controller on localhost (404)" error in your Spring Boot application and wondering how to solve it then you have come to the right place. Earlier, I have shared how to solved 5 common Spring Framework errors and exception and in this article, we will take a look at the spring boot can’t access rest controller on localhost (404) issue. A 404 Not Found Error for your REST Controllers is a relatively typical problem that many developers encounter while working with Spring Boot applications. In this Spring boot tutorial, let's explore why such an error took place, and later on, we will learn how to fix this issue.

25 Examples of ConcurrentHashMap in Java

The java.util.ConcurrentHashMap is one of the most important classes of JDK. It was introduced in JDK 1.5 along with other concurrent collection classes like CopyOnWriteArrayList and BlockingQueue. Ever since then, it has been a workhorse in concurrent Java applications. It won't be an exaggeration If I say there is hardly any concurrent Java application that has not used ConcurrentHashMap yet. The class was another implementation of java.util.Map and a popular hash table data structure with concurrency inbuilt. This means you can also pass a ConcurrentHashMap to a method that is expecting a java.util.Map object. It was made scalable by dividing the whole map into a different segment, known as concurrency level, and then allowing threads to modify segments concurrently.

2 Ways to sort a Map in Java by Keys? TreeMap and HashMap Example

So you have a Map in your Java program and you want to process its data in sorted order. Since Map doesn't guarantee any order for its keys and values, you always end up with unsorted keys and Map. If you really need a sorted Map then think about using the TreeMap, which keeps all keys in sorted order. This could be either natural order of keys (defined by Comparable) or custom order (defined by Comparator), which you can provide while creating an instance of TreeMap. If you don't have your data in a sorted Map then the only option that remain for you is to get the keys and values, sort them and then process your Map in that order. 

How to Remove Entry (key/value) from HashMap in Java while Iterating? Example Tutorial

Hello guys, Can you remove a key while iterating over HashMap in Java? This is one of the interesting interview questions as well as a common problem Java developers face while writing code using HashMap. Some programmers will say No, you cannot remove elements from HashMap while iterating over it. This will fail fast and throw concurrent modification exceptions. They are right but not completely. It's true that the iterator of HashMap is a fail-fast iterator but you can still remove elements from HashMap while iterating by using Iterator's remove() method. 

How does HTTP Request is handled in Spring MVC? DispatcherServlet Example Tutorial

One of the common interview questions in Spring MVC is, how does the DispatcherServlet process a request in Spring MVC? or What is the role of DispatcherServlet in the Spring MVC framework? This is an excellent question for any Java or Spring web developer because it exposed the candidate's knowledge about Spring MVC architecture and how its main components like Model, View, and Controller.   The answers to this question show how much you know about the Spring MVC framework and its working. 

How to Convert a List to Map in Java 8 - Example Tutorial

One of the common tasks in Java programming is to convert a list to a map and I have written about this in the past and today we'll see how Java 8 makes this task easier. Btw, be it Java 7 or Java 8, you need to keep something in mind while converting a list to a map because they are two different data structures and have completely different properties. For example, the List interface in Java allows duplicate elements but keys in a Map must be unique, the value can be duplicated but a duplicate key may cause a problem in Java 8. This means a List with duplicates cannot be directly converted into Map without handling the duplicate values properly. 

How to use Stream and Lambda Expressions to write better code in Java? Examples

Hello guys, writing Clean Code in Java has always been my passion, more so after reading the Clean Code book by legendary author Uncle Bob Martin. I always look for ways to make my concise yet more readable but sometimes Java's verbose nature comes into the way. Thankfully after the introduction of powerful features like Lambda expression and Stream API, writing clean code in Java has become much easier. Streams enable the user to combine commands in some sort of pipeline just like we combine Linux commands using pipe and result in high-quality code which describes what you are doing instead of how to do things.

What is Default or Defender Methods in Java 8? Tutorial Example

Whenever someone talks about Java 8, the first thing they speak about is lambda expression and how lambda expression has changed the way you use Collections API today. In truth, lambda expression would not be that useful had language not been enhanced to support default methods on Java Interface. Also known as virtual extension or defender methods, they allow you to declare a non-abstract method inside the Java interface. This means, finally you can add new methods without breaking all classes, which implements a certain interface. This opens a new path for enhancing and evolving the existing Collection API to take advantage of lambda expressions. For example, now you can iterate over all elements of Collection in just one line, as opposed to four lines it requires you to do prior to Java 8.

11 Examples of LocalDate, LocalTime, and LocalDateTime in Java 8

Hello guys, if you are wondering how to use LocalDate, LocalTime, and LocalDateTime classes from Java's new Date and Time API then you have come to the right place. Earlier, I have shared best Java 8 courses, books, and Java 8 interview questions and in this article, I Am going to share common examples of LocalDateTime, LocalDate, and LocalTime class in Java. It's been many years since Java SE 8 was released and Java 8 adoption has come a long way. Java programmers around the world have accepted with both ends, many companies have switched their development on Java 8 and several others are migrating to Java 8 platform.

How to Convert Stream to List, Set, and Collection in Java 8? Example Tutorial

Hello guys, if you are wondering how to convert a Stream to List, Set, Map, or any other Collection class in Java then you have come to the right place. Earlier, I have shared best Stream and Collection courses, and books as well as many Stream tutorials and in this article, I will tell you how exactly you can use Collectors to convert a Stream to List, Set, Map, or any other Collection class in Java. if you are following Java releases then you know that introduction of the Stream class is one of the most important addition in Java 8 as it makes processing bulk data really easy. Since data is the core part of any application and probably is the most important thing now than ever, a good knowledge of how to use Stream class effectively is important like how to work between Collections and Stream classes. 

Difference between Hibernate, JPA, MyBatis

Hello guys, if you are wondering what is difference between Hibernate, JPA, and MyBatis in Java world and when to use them then you have come to the right place. Earlier, I have shared Hibernate Courses, books, and Interview Questions and in this article, I will answer this popular Hibernate question from Java developer's perspective.  This article aims to give a brief overview of Hibernate, JPA, and MyBatis. Moving ahead highlights the difference between them. It also put light on which underlying technologies they use. Lastly, it provides verdicts on when to use which one among these. But, before we start with the difference between JPA, Hibernate, and MyBatis. It is important to have an understanding of these technologies first.

How to test a Spring Boot application in Java? @SpringBootTest Example

Hello guys, if you are wondering how to test your Java + Spring Boot application then you are at the right place. Earlier, I have shared best Spring Boot Courses and Spring Boot + Microservice example and in this article, I will talk about how to test your Spring boot application, mainly about writing unit test and integration test for Java and Spring boot application. Unit testing and Integration testing are two skills which separates a normal developer from a professional Java developer and when it comes to testing Spring applications many Java developer doesn't really know how to do that. If you are new to Java and Spring development but keen to learn Unit testing both Java and Spring Boot application then you have come to the right place.

7 Reasons of NOT using SELECT * in a Production SQL Query? Best Practices

Hello guys, if you are doing a code review and see a SELECT * in production code, would you allow it? Well, its not a simple question as it looks like but let's find out pros and cons about using SELECT * in a production SQL query and then decide. I have read many articles on the internet where people suggest that using SELECT * in SQL queries is a bad practice and you should always avoid that, but they never care to explain why? Some of them will say you should always use an explicit list of columns in your SQL query, which is a good suggestion and one of the SQL best practices I teach to junior programmers, but many of them don't explain the reason behind it. 

How to use Stream allMatch() and anyMatch() function in Java? Example Tutorial

Hello friends, we all know how streams are super important for our day-to-day needs in Java programming and coding nowadays. It allows us to filter data in memory in a declarative way, it also allows us to transform objects as well create a complex Stream pipeline to represent our business logic in a declarative fashion. But, do we know all the stream functionalities? Of course not. Earlier, we have seen examples of filter(), map, flatMap, and findFirst() method and today we will learn two of the most important stream functions anyMatch() and allMatch().  So what’s the wait? Let's start!

How to use Stream findFirst and findAny function in Java? Example Tutorial

Hello friends, here we are again on the journey of Java excited and eager to find the next stop of knowledge. But do not worry my friends, continuing the java stream series further, today we will deep dive into two other functions of streams that are equally important and interesting. Let me start by providing a situation that you guys can analyze and then we will discuss it. Let’s say you have data coming into your code through an API call. Now, you have no idea what the stream of data would be but you want the first element present in it. So, stream provides a function for the same. Let’s see what it is and how it is written.

Java 8 Predicate and Lambda Expression Example

Hello guys, if you want to learn about Predicates in Java 8 and looking for examples then you have come to the right place. In the past, I have explained key Java 8 concepts and classes like Stream, Optional, Collectors etc and we have seen how to use those functional methods like map, filter, and flatmap and in this article, I will show you how to use Predicates in Java 8 with Lambda expression. If you don't know Predicate is a functional interface in Java. A functional interface is nothing but a function with one abstract method or annotated by @FunctionalInterface annotation. Predicate is a functional interface with a function which accepts an object and return Boolean. 

3 Examples to Convert Date to LocalDate in Java 8? Tutorial

One of the great features of Java 8 is the new Date and Time API which is intended to fix existing issues related to mutability and thread-safety with existing java.util.Date class. But given java.util.Date is used very heavily across all the Java applications, you will often end up with a situation where you need to convert java.uti.Date to java.time.LocalDate while working in Java 8. Unfortunately there is no toLocalDate() method in the java.util.Date class. Though, you can easily convert Date to LocalDate if you are familiar with how new and old API classes map to each other.