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

How to convert a List to Set in Java? ArrayList to HashSet Example

Converting ArrayList to Set in Java means creating a Set implementation like HashSet from an ArrayList full of objects. Before Converting your ArrayList into HashSet do remember that List keeps insertion order and guarantees the same but Set doesn't have such obligation. Also, List allows duplicates but Set doesn't allow any duplicates, which means if you have duplicates in your ArrayList they will be lost when you convert ArrayList to HashSet and that's the reason why the sometimes size of ArrayList doesn't match with the size of HashSet after conversion.

How to become Blockchain Architect in 2023? Is Blockchain Architecture Certification by 101 Blockchains worth it?

Blockchain solutions have been making a lot of noise in the tech space recently for all the right reasons. It comes with the advantage of decentralization, security, and transparency. At the same time, you can also notice the possibility of a growing ecosystem of use cases. A Certified Enterprise Blockchain Architect can serve as a promising asset for enterprises in the present times. How? The work of an architect focuses on designing blockchain solutions by evaluating the requirements of the specific use case.

How to learn Metaverse from scratch? Is Certified Metaverse Professional (CMP) on 101 Blockchains worth it

Is Certified Metaverse Professional (CMP) on 101 Blockchains worth it?
Hello guys, if you want to learn Metaverse in 2022 and wondering how to learn Metaverse then you have come to the right place. Earlier, I have shared best Metaverse online courses and in this article, I am going to review one of the popular Metaverse certification, The certified Metaverse Professional certification from 101 Blockchains, one of the leading portal for Blockchain, Web3, NFT, and Metaverse training. The Metaverse is the next big thing, and you must have heard this a million times, just like many tech enthusiasts. The diverse elements of the metaverse have the potential to grab the attention of every person on the planet. Many big companies have already placed their stakes in the metaverse. 

10 Free Web Development Courses for Beginners in 2023 - Best of Lot

Hello guys, if you want to learn Web Development in 2023 and looking for best free resources like free online courses, tutorials, and books then you have come to the right place. Earlier, I have shared best online courses to learn HTML, CSS, JavaScript, React, Angular, and Node.js and in this article, I am going to share best free online courses to learn Web Development. The article includes free web-dev courses from sites like Udemy and Coursera which anyone can join free to learn essential Web development skills in 2023. But, Before we get to the 7 best free courses that will teach you everything you need to know about web development, let me tell you what it really is.

10 Example of Hashtable in Java – Java Hashtable Tutorial

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 some 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.

How to use ArrayList in Java? 10 Examples of ArrayList

ArrayList in Java is the most frequently used collection class after HashMap in Java. Java ArrayList represents an automatic re-sizeable array and used in place of the array. Since we can not modify the size of an array after creating it, we prefer to use ArrayList in Java which re-sizes itself automatically once it gets full. ArrayList in Java implements the List interface and allows null. Java ArrayList also maintains the insertion order of elements and allows duplicates opposite to any Set implementation which doesn't allow duplicates. ArrayList supports both the Iterator and ListIterator for iteration but it’s recommended to use ListIterator as it allows the programmer to traverse the list in either direction, modify the list during iteration, and obtain the Iterator's current position in the list.

Top 10 Free Spring Boot and Spring Framework Courses in 2023 - Best of Lot

Hello guys, if you want to learn Spring Framework and Spring Boot in 2023 and looking for free resources like free online courses, tutorials, and books then you have come to the right place. Earlier, I have shared best online courses to learn Spring Framework, Spring MVCSpring Boot, Spring Security, Spring Data JPA, and Reactive Spring/WebFlux and in this article, I Am going to share best free online courses to learn Spring Framework and Spring boot in depth. But, Before we get to the 10 best free Spring courses that are perfect for beginners, let me tell you more about what the Spring Framework really is.

How to use ConcurrentHashMap in Java? put, get, containsKey, containsValue, kyeSet, replace, remove Examples

Hello guys, if you are new to Java programming and want to learn ConcurrentHashMap class in Java then you have come to the right place. Earlier, I have shared the best books and best courses to learn Java, and today, I am going to share 10 examples of using ConcurrentHashMap in Java. As a Java programmer, you might have heard about the ConcurrentHashMap class of java.util.concurrent package. If you don't let me tell you that ConcurrentHashMap is an important class in Java and you will often find yourself dealing with this class in a multithreaded and concurrent Java application. If you are wondering where to start and how to master this essential Java class then you have come to the right place.

How to sort ArrayList in Natural and Custom Order in Java - Example Tutorial

Sorting ArrayList in Java is a common task for Java developers and we have touched it while discussing in my last article 10 Examples of  ArrayList in Java and again when we discussed comparator and comparable in Java. In order to sort an ArrayList, we need to use the Collections utility class which contains an overloaded sort() method for sorting different collections and supports different comparators in Java. In this article, we will see how to sort ArrayList in the natural order of elements and then sorting ArrayList in Java with a comparator.

Review Of Grokking Modern System Design For Software Engineers and Managers on Educative

System Design Interview is the hardest part of any coding interview and it requires a lot of preparation and knowledge to crack system design interview. If you are preparing for System design interview then you may know that Educative has best System design courses like this one and Grokking the System Design Interview.  Before I give you my verdict on whether you need to choose Educative's Grokking Modern System Design For Software Engineers And Managers course, let me tell you a little bit about what system design really is.

How to find current directory in Java with Example

Hello guys, if you want to find current directory in Java and looking for a simple example then don't worry. Its easy to get current directory in Java by using built-in system property provided by Java environment. Current directory represent here the directory from where "java" command has launched. you can use "user.dir" system property to find current working directory in Java. This article is in continuation of my earlier post on Java e.g. How to load properties file in Java on XML format or How to parse XML files in Java using DOM parser and Why Java doesn’t support multiple inheritance . If you haven’t read them already, You may find them useful and worth reading. By the way here is a quick example of finding current directory in Java:

How to read from and write to a text file in Java - Example Tutorial

Java has excellent support for reading from file and writing to file in Java. In the last post, we have seen how to create files and directories in Java and now we will see how to read content from files in java and how we will write text into file in Java. File provides a persistent solution to Java developers; in almost every Java application you need to store some of the data in persistent may be its user configuration, system configuration or related to state of the application but without persistence, no enterprise Java application can buildup. 

How to append text into File in Java – FileWriter Example

As a Java developer we often need to append text into File in Java instead of creating a new File, for example log files where every message is written into same file or appended at the end of the file. Thankfully Java File API is very rich and it provides several ways to append text into File in Java. Previously we have seen how to create files and directories in Java and how to read and write to a text file in Java and in this Java IO tutorial we will see how to append text into files in Java. We are going to use the standard FileWriter and  BufferedWriter approach to append text to File. One of the key points to remember while using FileWriter in Java is to initialize FileWriter to append text i.e. writing bytes at the end of the File rather than writing at the beginning of the File.

How to Copy a File in Java Program - Example Tutorial

How to copy files in Java from one directory to another is a common requirement, given that there is no direct method in File API for copying files from one location to another. A painful way of copying files is reading from FileInputStream and writing the same data to FileOutputStream to another directory. Though this process works it's pretty raw to work with and the best approach is for anyone to create a library for common File operations like cut, copy, paste, etc. 

How to read File into String in Java 7, 8 with Example

Many times you want to read contents of a file into String, but, unfortunately, it was not a trivial job in Java, at least not until JDK 1.7. In Java 8, you can read a file into String in just one line of code. Prior to the release of new File IO API, you have to write a lot of boilerplate code e.g. open an input stream, convert that input stream into a Reader, and then wrap that into a BufferedReader and so on. Of course, JDK 1.5's Scanner class did provide some breathing space but it was still not as simple as it should be, like in Python or Ruby. By using Java 7 new File API and Java 8's new features like lambda expression and Stream API, Java is now close to Python or other utility languages, when it comes to reading the file into String.

Top 5 Free and Paid OCAJP, OCPJP Mock Exams and Practice questions - (Java Certification)

In order to do well on Java certifications, you need good books and a reasonable number of practice questions before you go for exams. Practice questions and mock exams will help you to assess your topic-wise preparation level and help you to identify your strong and weak areas. Based on the result of the mock exams, you can concentrate on areas where you lack expertise like multi-threading is one of the tricky areas. It will also expose you to exam patterns and different types of questions you can expect in examination like multiple choice questions, rearranging code, fill in the blanks etc. Though I highly recommend commercial exam simulators like Whizlabs and Enthuware, I also suggest you take advantage of many mock questions which are freely available.

How to create a hidden file in Java- Example Tutorial

In the last article, we saw how to check hidden files in Java and now we will see how to hide files in Java or make hidden files in Java. As we said File API in Java doesn’t provide any method to make a file hidden in Java but still you can apply some quick tricks to hide files from Java program. Like in a Unix environment any file whose names begin with a dot (.) is hidden so you can name your file starting with a dot (.)  and your File will be hidden in Linux or Unix Environment.

How to Copy Non Empty Directory with Files in Java- Example Tutorial

It's easy to copy a file or an empty directory in Java as you can use Files.copy(fromPath, toPath) from Java 7, but, unfortunately, it's not as easy to copy a non-empty directory with all its files and subdirectories in Java, much like deleting a non-empty directory. There is no method in Java IO API which copies everything inside one directory to another. The copy(source, target, CopyOption...) method can copy directories, but files inside the directories are not copied. So the new directory will be empty even if the original directory contains files and folders. Similarly, the copy fails if the target directory already exists, unless the REPLACE_EXISTING copy option is specified.

How to check if a File is hidden in Java? Example

This article is a quick tip to find hidden files in Java by checking the hidden properties of a File or directory from the Java Program. File Handling is a crucial topic in java already we have discussed how to create a file in java, how to create a directory, how to read write in a text file in Java, how to set permissions on the file, and some more aspects and we will discuss one more property of the file, i.e. hidden property. Now the question arises can we make a file Hidden using our java code or not.

How to read a File in One Line in Java? Files.readAllLines() Example Tutorial

Reading a file in Java is not simple, it requires lots of boilerplate code, as we have seen in our earlier example of reading text files. Various things had to be wrapped e.g. a FileInputStream inside a BufferedReader, loops with weird terminating conditions had to be specified, and so forth. From JDK 7 onward,  you can do a lot better. It provides lots of useful classes like Files and Paths to deal with file and their actual path. In this article, we will see how we can read a file in just one line. Of course, your production code won't be like that, especially if you are reading a few gigabytes into memory and want to pay attention to the character set, if you don't specify, by platform's default character encoding will be used.

Java 8 - Stream FlatMap Example - List of Lists to List

The flatmap is an interesting concept of functional programming which allows you to flatten the list or stream apart from transforming it, just like the map does. This means you can use the flatmap to flatten the stream. If you have used the map() function from the Stream class before then you can use it to convert an object of type T to another object of Type S. For example, if you have a list of Authors then you can convert it to a List of books by transforming authors to books. FlatMap extends this idea, it not only transform one object to other it also flattens the list and that's it's very useful where you want to know about a combined data set. 

How to convert java.util.Date to java.sql.Date - JDBC Example

You often need to convert java.util.Date to java.sql.Date if you are storing dates in a database e.g. SQL SERVER or MySQL. Since JDBC has their own data types for date and time e.g. java.sql.Date, java.sql.Time and java.sql.TimeStamp to match with database date, time and date-time types, you cannot pass a java.util.Date directly. All methods which are supposed to store dates e.g. setDate(paramName, paramValue) expects java.sql.Date, so it becomes essential to know how to convert java.util.Date to java.sql.Date in JDBC. You would be surprised to know that java.sql.Date is a subclass of java.util.Date and all it does is suppress or remove time-related fields from java.util.Date.

How to use Stream range, rangeClosed, sum and sorted methods? Java 8 IntStream Examples -

Hello guys, if you want to learn about IntStream in Java 8 and looking for a simple tutorial and example then you have come to the right place. Earlier, I have shared 10 examples of Lambda expression and filter+ map+ collect examples and in this article, I will show you how to use IntStream in Java 8. IntStream is a specialization of Stream class for primitive int values. It allows you to perform a sequential and parallel aggregate operation on a list of values like count() to print the total number of element in stream, min() to find minimum value in the stream, max() to find maximum value in the stream, sum() to find a total of all values and average() to find the average of all numbers in the stream.

Educative Review - Is Grokking Advanced System Design Interview Course Worth it?

Before I give my review of Educative's Grokking Advanced System Design Interview, let me tell you a little bit more about this course so that we are on the same page. As you must already know if you have ever sat for a software engineering interview, system design questions are an integral part of the process. System design plays a very important part as it is considered more important than solving coding problems. And in order to impress your potential employers, you have to be able to show your real design skills and convince them that you are able to work with complex design systems.

How to convert String to Date in Java - SimpleDateFormat Example

Hello Java developers, you may know that SimpleDateFormat in Java can be used to convert String to Date in Java. java.text.SimpleDateFormat is an implementation of DateFormat which defines a date pattern and can convert a particular String that follows that pattern into Date in Java. This is the second part of the article on java.util.Date and String in Java. In the first part, we have seen How to convert Date to String in Java. SimpleDateFormat accepts a String in any date format e.g. yyyyMMdd is a date pattern and  20220924 is a String in that format. Now you want to create a java.util.Date object from this String.

How to Convert Date to String in Java with Example

As a Java developer we often need to convert java.util.Date or LocalDate to String in Java for  displaying purpose or sending Date as String in JSON or XML messages and that's where having a agree upon Date Format is very important. It easily allows you to convert your Date as String and pass between two System. I need it that while working on displaying date in my application and then I thought about this article to list down various way of converting this in various ways after some reading I found that SimpleDateFormat makes this quite easy. 

How to convert Date to LocalDate and LocalDateTime in Java 8 - Example Tutorial

The easiest way to convert a java.util.Date to java.time.LocalDate is via Instant, which is the equivalent class of java.util.Date in JDK 8. You can first convert util Date to Instant and then create a LocalDateTime object from that instant at your default timezone. Once you have an instant of LocalDateTime, you can easily convert that to LocalDate or LocalTime in Java. If you are not living under the rock in the last two years that its 2016 and Java 8 has been around for more than 2 years, 18th March 2014 Java SE 8 GA happened.

Java 8 Comparator comparing() and thenComparing() Example - Tutorial

Hello Java programmers, you may know that the JDK 8 has added a lot of new methods into the Comparator interface which makes comparing and sorting objects in Java really easy. Two such methods are called comparing() and thenComparing() which was added in the java.util.Comparator interface. These methods accept a key extractor function and return a Comparator that can compare to that key. The key must be Comparable though like String, Integer, or any Java class which implements java.lang.Comparable interface, I mean the key must implement Comparable interface. 

17 Examples of Calendar and Date in Java - Tutorial

The java.util.Calendar class was added in Java on JDK 1.4 in an attempt to fix some flaws of the java.util.Date class. It did make some tasks simpler, e.g. create an arbitrary date comes easier using the new GregorianCalendar(2016, Calendar.JUNE, 11) constructor, as opposed to the Date class where the year starts from 1900 and the Month was starting from zero. It didn't solve all the problems like mutability and thread-safety of Date class still remains, but it does make life easier at that time. Now with Java 8 everything related to Date and Time has become super easy and consistent but unfortunately, it will take another 5 to 10 years before the older version of Java goes away. Don't believe me, there are still applications running on JDK 1.5 which was released 12 years ago. The bottom line is it's still important to know about the Date and Calendar in Java.

10 Examples of Optional in Java 8

Null is bad, it can crash your program. Even its creator called it a billion-dollar mistake hence you should always try to avoid using nulls whenever you can. For example, you should not return a null String when you can return an empty String, similarly never return null collections when you can return an empty collection. I have shared many such tips in my earlier article, 10 tips to avoid NullPointerException and my reader liked that a lot. But, I wrote that article a couple of years ago when Java 8 was not around and there was no Optional, a new way to avoid NullPointerException in Java, but, things have changed now.

How to calculate GCF and LCM of two numbers in Java? Example

This week's programming exercise is to write a Java program to calculate GCF and LCM of two numbers. The GCF stands for a Greatest common factor and LCM stands for Lowest common multiplier, both are popular mathematical operations and related to each other. The GCF is the largest number which divides both the number without leaving any remainder e.g. if two numbers are 24 and 40 then their GCF is 8 because 8 is the largest number which divides both 24 and 40 perfectly, without leaving any remainder. 

How to find the largest and smallest number in given Array in Java? Example Tutorial

Hello guys, today I am going to discuss one of the frequently asked programming interview questions to find the largest and smallest number from an integer array. This question is commonly asked on telephonic interviews and the first round for screening candidates. This coding problem is in the same league of other frequently asked algorithmic questions like Fibonacci, Palindrome, Prime, and Power of two checks. They are easy but you will find them difficult during the interview because of the pressure, particularly if you have not solved them before. Sometimes even if you have solved the problem one time, you tend to do mistakes because you haven't understood them properly. So, always take your time to understand the question.

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

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. By the way, if you need to reverse an ArrayList then you should be using the Collections.reverse() method provided by the Java Collection framework. It's a generic method, so you can not only reverse an ArrayList but also Vector, LinkedList, CopyOnWriteArrayList, or any other List implementation.

How to Implement Stack Data Structure in Java? Example Tutorial

The stack is one of the popular data structures which supports LIFO (Last In First OUT) operation. Due to the LIFO advantage, you can use a stack data structure to convert a recursive algorithm to an iterative one. The stack data structure is very easy to implement using an array or linked list, but you don't have to implement it on your own because Java already provides a Stack implementation in java.util.Stack class. This class is a subclass of the Vector class and you should use it whenever you need Stack for your production code, there is no point in inventing the wheel again when the focus is on developing your application.

Review - Is Metaverse Professional Certification on 101 Blockchains worth it?

The metaverse is the next big thing, and you must have heard this a million times, just like many tech enthusiasts. The diverse elements of the metaverse have the potential to grab the attention of every person on the planet. Many big companies have already placed their stakes in the metaverse. Therefore, it is quite clear that a Certified Metaverse Professional certification would be helpful in terms of career development. Interestingly, the opportunities for career development in the metaverse have been doubling in recent times. The following discussion helps you find whether the CMP certification by 101 Blockchains is the best choice in metaverse certifications for you.

How to use jQuery Class and Id Selector to find DOM elements? Example

One of the best things about jQuery is there selectors, which gives jQuery enormous power to find and select DOM elements so easily. If you are coming from JavaScript background then you might love those classical methods to find DOM elements like getElementById() and getElementByName(). They have served very well in the old days of JavaScript coding,  but once you start using jQuery selector, which is quite similar to CSS selector, I am sure you will forget them. Searching and finding HTML elements using jQuery selectors are natural, intuitive, and super easy and that's why I love them.

10 Difference between Java and JavaScript for Programmers

Programmers, developers, and internet users have always been confused between Java and JavaScript.  Many people still think that JavaScript is part of the Java platform, which is not true. In truth, JavaScript has nothing to do with Java, the only common thing between them is the word "Java", much like in Car and Carpet, or Grape and Grapefruit. JavaScript is a client-side scripting language for HTML, developed by Netscape, Inc, while Java is a programming language, developed by Sun Microsystems. James Gosling is the Inventor of Java, popularly known as the father of Java. 

Top 20 jQuery Interview Questions and Answers for 1 to 3 Years Experienced

Without a doubt, jQuery has given a much-needed boost to JavaScript, a language so useful but equally underrated at times. Before jQuery comes into the picture, we used to write lengthy JavaScript code not just for bigger but even for smaller functions. Those codes were at times both difficult to read and maintain. Having written JavaScript before using this excellent library, I realized the true power of jQuery, just after using it for a month. Given its huge popularity, jQuery interview questions are increasingly asked in any web developer interview, not just beginners but also experienced developers, including HTML and JavaScript.

How to get current URL, parameters and Hash tag using jQuery and JavaScript? Example

While dealing with the current URL, many times you want to know what is the current URL path, What are the parameters, and what is the hashtag on the URL. The hashtag is pretty important if you are implementing a tab structure using HTML and JQuery. To avoid confusion, let's take an example of a URL: http://javarevisited.blogspot.com/2013/01/top-5-java-programming-books-best-good.html#ixzz2PGmDFlPd, in this example ixzz2PGmDFlPd, is a hashtag. Now, both JavaScript and JQuery provide a convenient way to retrieve the current URL in the form of window.location object. You can use various properties of the window.location JavaScript object like the window.location.href to get complete URL, window.location.pathname to get the current path, and window.location.hash to get a hashtag from current URL.

Top 10 Free NFT (Non Fungible Tokens) Courses for Beginners in 2023 - Best of Lot

Hello guys, if you want to learn about NFTs or Non Fungible Tokens and looking for best free online courses then you have come to the right place. Earlier, I have shared best paid NFT courses and in this article, I am going to share best free NFT courses for beginners, Bu, before we get to the 10 best free NFT courses that will teach you everything you need to know about this exciting new technology, let me tell you what it really is. NFTs, also known as Non-Fungible Tokens, are basically unique cryptographic tokens. These tokens exist in a blockchain, which means that they cannot be replicated. Each NFT has a unique identification and metadata. 

How to Print a left triangle star pattern in Java? Example Tutorial

Pattern based exercises are very common on Interviews as they are tricky for beginners and also offers coding practice. In the past, I have shared article on how to print pyramid pattern of stars in Java and Pyramid pattern of albhabets, and in this article, I will show you how to print left triangle star pattern in Java. There are different ways of printing different patterns, but most of them involves using loops and print methods like print() and println() to print characters like star, alphabets or numbers. If you know how to use loops and when to break from loop then you can easily solve pattern based coding problems. In this section, we shall be writing a program to print a left triangle star pattern. We would first implement that before I explain other things that you need to know in getting this task done.

SimpleDateFormat in Java is not Thread-Safe Use Carefully

SimpleDateFormat in Java very common and used to format Date to String and parse String into Date in Java but it can cause very subtle and hard to debug issues if not used carefully because DateFormat and SimpleDateFormat both are not thread-safe and buggy. call to format() and parse() method mutate the state of DateFormat class and should be synchronized externally in order to avoid any issue. here are a few points which you should take care while using SimpleDateFormat in Java:

Why Timestamp cannot be used in place of Date in Java? Example

One of the tricky questions from the Java Interview is, "Can we pass a Timestamp instance to a method expecting java.util.Date?", it's a tricky question because the answer is both Yes and No. You can, of course, pass a Timestamp object to a method with the argument as Date because first, Timestamp is a subclass of java.util.Date and second it contains both date and time values which are missing in either java.sql.Date and java.sql.Time. So there is more reason to pass a Timestamp value to Date but you should not be doing that. Why? because Timestamp is not exactly Date.

Top 10 Udacity Courses for Python and Data Science in 2023 - Best of Lot

Hello guys, if you are looking for best Python and Data Science courses on Udacity to start your career then you have come to the right place. Udacity is one of the best place to learn in-demand tech skills as it works with industry leaders to create project-based online learning programs, which means you  learn the technology skills that employers value most like Python, Data Science, Machine Learning, and more. In the past, I have shared best Python courses on Coursera and best Python courses on Udemy and in this article, I am going to share best online courses to learn Python on Udacity. But, before we get to the 10 best Udacity courses that will teach you everything you need to know about Python. let me tell you a little bit about what it really is.

How to format/parse dates with LocalDateTime in Java 8 - Example Tutorial

One of the common tasks in a Java project is formatting or parsing data to String and vice-versa. Parsing date means you have a String that represents a date like "2017-08-3" and you want to convert it into an object which represents the date in Java, like java.util.Date in pre-Java 8 world and LocalDate or LocalDatetime in Java 8 world. Similarly, formatting a date means converting a date instance into a String, for example, you have a Date object or LocalDatetime object and you want a String in dd-MM-yyyy format. Java 8 API provides good support for formatting and parsing dates.

Difference between Period and Duration class in Java 8? [Example]

What is the difference between Period and Duration class in Java is one of the popular Java 8 interview questions and has been asked too many of my readers recently. If you were also wondering the difference between Period vs Duration and when to use Period over Duration and vice-versa then you have come to the right place. Java 8 has two classes to represent differences in time like Duration and Period. The main difference between Period and Duration is that they represent the difference in different units, A Duration is used to calculate time difference using time-based values (seconds, millisecond, or hours) but Period is used to measure the amount of time in date-based values like days, months and year.

[Solved] How to Implement Fibonacci Series with Memoization in Java 8? ConcurrentHashMap Caching Example

Hello guys, if you are wondering how to solve the Fibonacci series problem with memorization in Java then you have come to the right place. In the past, I have shared recursive and iterative Fibonacci series solution and in this article, I am going to show you how you can improve your solution using a technique called memorization which uses a cache to store the intermediate results. This is a very useful technique to solve Dynamic Programming problems like the Knapsack problem. The good thing about Java is that it provides rich libraries which have classes like ConcurrentHashMap which can be used as a cache to store these intermediary results instead of re-computing them. This can drastically reduce the time to calculate the Nth Fibonacci number.

How to find number of days between two dates in Java 8 [LocalDate until() & between() Example ]

You can use the LocalDate.between() method to find the number of days between two dates in Java. This method is full proof and takes care of date-time nuisances like leap year and daylight saving time. Before Java 8, it was really difficult to calculate the number of days between two dates in Java. Though old Date and Calendar API provides methods to compare two dates like equals(), before(), and after(), no method can tell the exact difference in days or months between two dates unless you are using the joda-time library. All that is over now. You can now do better date-time arithmetic using Java 8 Date and Time API.

6 Subtle Date and Calendar Details to Learn before using Date in Java - Example Tutorial

Hello guys, to appreciate the brilliance of the new Date and Time API introduced in Java 8, you must remember the nasty problems you have earlier faced with Java's old Date and Calendar API Well, I have been using Java for the last 20 years and I have to face them so I thought to write this article to educate Java programmers about the shortcomings of old Java Date and Calendar API. Another reason for this article is that even though Java is ready with the new, shiny, and carefully designed Date and time API, your project is probably not. Most of the prominent organizations that use Java at large scales, like Investment banks, Insurance companies, major E-commerce giants, are quite reluctant to upgrade. There are many firms, both big and small that are still running on Java 5 and expect to migrate to Java 6 in a couple of years.

Inter Thread Communication in Java using wait() and notify() - Example Tutorial

Wait and notify methods in Java are used for inter-thread communication i.e. if one thread wants to tell something to another thread, it uses notify() and notifyAll() method of java.lang.Object. A classical example of the wait and notify method is a Producer-Consumer design pattern, where One thread produces and put something on the shared bucket, and then tell the other thread that there is an item for your interest in a shared object, consumer thread than pick than item and do his job, without the wait() and notify(), consumer thread needs to be busy checking, even if there is no change in the state of the shared object.

When to make a method final in Java? Example

Hello guys, if you are wondering when to make a method final in Java then you have come to the right place. Earlier, I have told you when to make a method static and when to make private and today, I will teach you when to make a method final in Java. The final keyword in Java is not as mysterious as volatile or transient, but still, it creates a lot of doubts in programmers' minds. I often receive questions like, When to make a method final in Java or When to make a method static in Java, later I answered in my earlier post. Questions like this are not trivial, knowing what a keyword does is just a small part of mastering that functionality. Similar to the real world, where knowing that a sword can cut a lot of things is not enough for a warrior to survive, you need to know how to use that and more importantly, use it effectively. 

What is Double Brace Initialization in Java? Example Initializing HashMap and List with values in Java

Double brace initialization is a Java idiom to initialize a Collection like a list, set, and map at the time of declaration. At times, you need a list of fixed elements e.g. supported products, supported currencies, or some other config, and on-the-spot initialization reduces the line of code and improves readability. Double brace initialization idiom becomes popular because there is no standard way to create and initialize Collection at the same time in Java. Unfortunately, unlike other JVM languages like Scala and Groovy, Java doesn't support collection literals yet. 

How to use Lock in Java? ReentrantLock Example Tutorial

Many Java programmers confused themselves like hell while writing multi-threaded Java programs like where to synchronized? Which Lock to use? What Lock to use etc. I often receive a request to explain how to use Locks and ReentrantLock in Java, so I thought to write a simple Java program, which is multi-threaded and uses a rather new Lock interface and ReentrantLock to lock critical section. Remember Lock is your tool to guard shared resources which can be anything like a database, File system, a Prime number Generator, or a Message processor. Before using Locks in the Java program, it’s also better to learn some basics. Lock is an interface from java.util.concurrent package. It was introduced in JDK 1.5 release as an alternative to the synchronized keyword.

How to implement Linear Search in Java? Example Tutorial

Hello guys, earlier, I have talked about how the binary search algorithm works and shared the code to implement the binary search in Java. In that article, someone asked me about is there any other search algorithm that exists? How can you search an element in the array if it's not sorted, and you cannot use the binary search algorithm? To answer his questions, I mentioned the Linear search algorithm, which is the predecessor of binary search. Generally, it is taught before the binary search algorithm because the binary search is faster than Linear search. However, never mind, you can still learn this useful algorithm to search for an item in the array or linked list.

How to use Sealed classes and Interface in Java? Example Tutorial

Hello friends! If you are wondering what is Sealed class in Java and whether you should use it or not and looking for a Sealed class tutorial then you have come to the right place. Earlier, I have shared Java Record Tutorial and Java CompletableFuture tutorial and today, I will explain you about another interesting Java feature. Yes, I am talking about Sealed classes in Java. This is a relatively new feature that was added in Java 15 as a preview feature. This was added as part of JEP 360 to provide more fined-grained inheritance control in Java. This can be better understood by an example. So, I am going to give you a situation and we will analyze this situation together. 

How to use Records in Java? Example Tutorial

Hello! Welcome, all again in the journey of Java. We are here today to learn a very interesting topic in Java: Records!  If you are wondering what is Record and how to use Record in Java then you have come to the right place. In this article, I am going to cover everything about the Record I know and will try to explain in simple words so that you know what is Records, what benefits it offers, and how you can use them. But before we dive in and understand what it is, let’s first understand what would happen without them. So, we would get an idea of the need and significance of Records. By the way, this is another article covering new Java features, earlier, I have covered Sealed ClassesCompletableFuturePhaser, and how to use var in Java. If you haven't read them already, you can check them to learn these useful Java features 

How to use Comparable Interface in Java? compareTo() Example

Hello, guys, today I am going to talk about one of the fundamental concepts in Java, defining the natural ordering of the objects like lexicographical order for String and numerical order for Number classes like Integer, Double, Float, etc. The compareTo() method is defined in the java.lang.Comparable interface. It is used to define the natural ordering of an object, for example String class override compareTo() to define the lexicographical order for String objects. Integer class override compareTo() to define the numeric ordering of integer objects.

5 Examples of Text Block and Multiline String in Java - Tutorial

While some programmers are troubled with frequent Java releases (it's actually hard to keep up), many are excited to see new features coming in Java every six months. I haven't been sharing a lot of new features lately, last I wrote about var from Java 10 and static factory from Java 9. Well, to be honest, I don't get much time to try out these new features and to publish articles on those, but a couple of new features from Java 12 and Java 13 caught my attention and I decided to give it a try and write something about them. So, the first feature in this series is the "Text block" of Java 13.

Java Serialization Example - How to Serialize and Deserialize Objects in Java?Tutorial

Serialization is one of the important but confusing concepts in Java. Even experienced Java developers struggle to implement Serialization correctly. The Serialisation mechanism is provided by Java to save and restore the state of an object programmatically. Java provides two classes Serializable and Externalizable in java.io package to facilitate this process, both are marker interfaces i.e. an interface without any methods. Serializing an Object in Java means converting it into a wire format so that you can either persist its state in a file locally or transfer it to another client via the network, hence it becomes an extremely important concept in distributed applications running across several JVMs.

[Solved] How to check if a Given Number is Binary in Java? Example

Today we will take a look at another simple programming exercise, write a program to check if a number is binary in Java. A number is said to be binary if it only contains either 0 or 1, for example, 1010 is a binary number but 1234 is not. You can not any library method to solve this problem, you need to write a function to check if the given number is binary, you can use basic constructs of Java programming language e.g. operators, keywords, control statements, etc. If you are a regular reader of Javarevisited, then you know that I love to share simple programming problems here.

Difference between Inheritance and Polymorphism in Java and OOP - Example

Both Inheritance and Polymorphism are key OOP concepts and similar to Abstraction and Encapsulation, they are also closely related to each other. Because of their similarities, many OOP programmers, especially beginners get confused between Inheritance and Polymorphism. Even though they are closely related and you need Inheritance to support runtime Polymorphism they are a totally different concept. Inheritance refers to the ability of classes or objects to inherit properties of other classes or interfaces. It means you can write code for common functionalities and reuse it at different places by just using Inheritance and not re-writing those codes again and again. For example, you can write code to

Solving ArithmeticException in Java? Integer and Floating point Arithmetic Example

I am starting a new series called Java Coding Quiz, in which I'll show you subtle Java concepts hidden in the code. This is an OCAJP or OCPJP style question but focused on teaching subtle details of the Java programming language. In today's puzzle, you will learn about one of the key concepts about how floating-point and integer arithmetic works in Java. This is a very important concept for any Java developer because Java behaves differently when the same operation is performed by different types of variables but of the same value.

Difference between Executor, ExecutorService and Executers class in Java

All three classes Executor, ExecutorService, and Executors are part of Java's Executor framework which provides thread pool facilities to Java applications. Since the creation and management of Threads are expensive and the operating system also imposes restrictions on how many Threads an application can spawn, it's a good idea is to use a pool of threads to execute tasks in parallel, instead of creating a new thread every time a request comes in. This not only improves the response time of the application but also prevent resource exhaustion errors like "java.lang.OutOfMemoryError: unable to create new native thread".

Top 50 Java 8 Stream, Lambda, and Functional Programming Interview Questions

Hello guys, if you are preparing for Java interviews and looking for some Java 8 Stream, Lambda Expression, and other Java 8 features then you have come to the right place. Earlier, I have shared 140+ Core Java interview questions and 20+ Spring Boot questions and in this article, I am going to share Stream, Lamba expression, and other Java 8 feature-based questions.  Java 8 features are now not remained as good to know features. They have been increasingly adopted by many organizations and most of the new development encourage developers to write code in Java 8 style to take full advantage of massive CPU power available in modern servers like HP 380 Gen 8 servers, also known as G8. 

Coursera Review - Is Machine Learning Specialization By Andrew Ng and DeepLearning.AI worth it?

Hello guys, if you are following Andrew Ng on Twitter then you may know that his popular free Machine Learning course from Stanford is now turning into full fledged Machine Learning specialization from both Stanford and DeepLearning.ai, which is a great new for all the people who want to learn Machine Learning in 2022. There are many people like me who got our first introduction to Machine Learning using that course and its no surprise that more than 5 million people have already joined this course. With this new specialization, Andrew Ng has provided one of the most authentic, comprehensive and Engaging Machine Learning resources for beginners. In the past, I have shared best Coursera courses to learn Machine LearningData Science, and Blockchain and in this article, I will share my 2 cents about this Machine Learning specialization course on Coursera.

how to fix the password issue for Maven in Eclipse? [Solved]

Most Java programmers use Maven in Eclipse via the M2EClipse plug-in, which gives one capability to build, run, and test Java application using Maven. I also use the M2Eclipse plugin for integrating Maven with Eclipse, but more often there are issues dealing with them like Maven not able to find certain archetypes, or maven not able to download Jar files from remote maven repository. Since I need to change the password often for security reasons like every 3 months, I do see a lot of maven issues in Eclipse related to building projects. Most of the time these are compilation errors that are caused because maven is not able to connect to remote maven central repository, even though you have updated password in settings.xml in the maven installation folder like C:\apache-maven-2.2.1\conf\settings.xml

Maven vs Gradle? Which one Java Developer Should Learn?

Hello guys, if you are looking for a quick introduction to Maven and Gradle then you have come to the right place. Earlier, I have shared the best Maven course and best courses to learn Gradle, if you haven't checked them, I suggest you can also look at them if you want to learn these tools in depth. Maven and Gradle are the two most popular build tools for Java applications. They manage dependencies and create artifacts.  How do they do that? They have a repository like a maven has Maven repository where the store every single Java library and depending upon which library you add to your project, they download that library + all the transitive dependency for those libraries automatically. 

Top 5 Courses to Learn Kali Linux in 2023 - Best of Lot

Kali Linux is an open-source Debian system based on Linux developed by the offensive security company for ethical hackers. It contains more than 400 tools categorized to make it easy for security researchers to analyze your network, test the system security, discover different vulnerabilities inside a web application, hide malware in apps, and target Android phones. If you want to learn Kali Linux and looking for the best online courses to learn Kali Linux on your own then you have come to the right place. Earlier, I have shared the best Ethical Hacking courses and Cyber Security Courses, and in his article, I am going to share the best Kali Linux courses for beginners. 

12 Advanced Spring Framework Courses for Experienced Developers in 2023 - Best of Lot

Hello guys, if you are a Java developer and want to learn Spring Framework in-depth and looking for some advanced Spring online courses to learn things like Spring Boot, Spring Cloud, Spring Data JPA, Spring Security, Spring MVC, etc then you have come to the right place. Earlier, I have shared the best courses to learn Spring Boot, Microservices, and Hibernate and JPA and in this article, I am going to share the best and advanced Spring Framework courses for experienced Java developers. There is no doubt that the Spring framework is probably the most important skill for Java developers, but just knowing Spring is also not enough. 

Top 10 Java Programming Books - Best of lot, Must Read

These top Java programming books are some of the good books to learn Java and I would say some of them are simply the best Java books ever published. Whenever a programmer starts learning Java programming language, the first question he asks is "Which book should I refer to learn Java?", or "What is the best book to learn Java for beginners?" or "Can you tell me some good books to learn Java?" .That itself says how important Java books are for programmers especially beginners.  Despite having so many free resources available in Java, like tutorials, online courses, tips, blogs and code examples, Java books have their own place because of two reasons:
  • They are written by programmers who are the authority in the subject
  • They cover the subject with more details and explanation.

5 Things Programmers Can Buy in Amazon Prime Day 2023 [Best Deals]

Hello guys, many of my friends and colleagues used to wait until November to buy books, gadgets, and other computer items to get the huge discount offered on Black Friday and Cyber Monday deals, but you don't need to wait that long. Amazon is bringing Black Friday to the summer with its annual Prime Day offers. The Amazon Prime day is nothing but a one-day (precisely one and half-day and this time full two-day) shopping extravaganza, where you will get huge discounts on thousands of Amazon products including books, games, gadgets, and other computer and electronics items. So, if you are looking to buy a new laptop, a new smartphone, or some fitness gadgets and watch then this is an awesome opportunity. 

Top 10 Udemy Courses to Learn Essential Skills for Programmers in 2023 - Best of Lot

There is no doubt that Udemy is one of the most popular e-learning platforms. It helps more people learn valuable skills like Programming, Coding, Web development, App development, Python, Java, C/C++, Data Science, Machine Learning, Node.js, React.js, JavaScript, and others, which helps them to get a job and career in technology. Even though Udemy has all kinds of courses, from Programming to Photography, from Music to Digital Media, in this article, we have compiled a list of the best Udemy Courses and certifications for Programmers and Developers.

10 Best Udemy Courses to Learn Python Programming in 2023 [UPDATED]

Hello guys, If you want to learn Python programming and looking for the best Udemy courses to learn Python online, then you have come to the right place. Earlier, I have shared the best Python courses and free Python courses for both beginners and experienced Python developers but In this article, I am going to share the top 10 Udemy courses to learn Python in 2023. This includes both hands-on and project-based courses where you will learn by doing, I mean you will actually build the projects using Python. This is the best approach to learning any new technology or skill, including Python. By the way, when it comes to learning online, Udemy is my go-to place because of affordable pricing and some high-quality courses.

Top 6 Free Courses to Learn Scala and Functional Programming in 2023 - Best of Lot

Scala is a powerful object-oriented and functional programming language long touted as the successor to Java or to replace Java. Well, that didn't happen in the last few years, but Scala has undoubtedly made a lot of progress and established itself as a scalable programming language for big things. If you are a social media user and know Twitter, then let me tell you that they are using Scala, which proves that Scala has all the tools you need to build a high-performance, scalable application like Twitter. Twitter is not the only company that is using Scala. If you look at Scala's website, you will find that IBM, Goldman Sachs, Verizon, and SAP use Scala to solve their problems.

Top 10 Ruby and Rails Online Courses for Beginners in 2023 - Best of Lot

Hello guys, If you want to learn Ruby Programming language or Ruby on Rails, a leading web development framework, then you have come to the right place. Earlier, I shared the best free Ruby courses as well best Python 3 courses and books, and today, I will share the best Ruby and Rails course for beginners. Ruby is one of the most popular web development programming languages, much like Python, PHP, and Java, and is used heavily for web development. Many startups and big organizations like Twitter use Ruby to build their website, and that's why there is a huge demand for Ruby developers. 

Top 5 Online Courses to Improve Email and Workplace Writing Skills in 2023 - Best of Lot

One of my readers emailed me a couple of days ago and asked If I could suggest something to improve his email writing skills? He says that he is very good at work and programming but sucks on writing emails, and because of that, he never gets the visibility he deserved, resulting in no promotion or career growth. This sounds to be a prevalent problem, especially among programmers whose native language is not English, and who have never attended any business or email writing course. In fact, it was a problem for me as well, but I slowly picked it up though I am still far behind with many people I know who have excellent email communication skills.

Top 5 Courses to learn iOS and Swift for Beginners in 2023 - Best of Lot

Hello guys, it's that time of the Year when we all start making our goals for better health, improving ourselves, and learning new things. Last Year, I focused mainly on the Web Development side and spent time teaching React, Angular, and Node JS, but this year, one of my goals is to explore the mobile world, particularly iOS and Android. At least that's a thought for now, and I am not sure how long I can go given the limited time I get to upgrade myself, but I'll try my best. Btw, suppose you also have the same goal and want to become an iOS developer in 2023. In that case, you should start your journey by learning iOS, Apple's Operating system, which runs on iPhone and iPad, and Swift 5, Apple's programming language for creating iOS apps.

Top 5 Courses to Learn JavaFX Online in 2023 - Best of Lot

Hello guys, if you want to learn Java FX and look for the best Java FX courses, you have come to the right place. Earlier, I have shared the best Java Programming programming courses, and today, I will share with you the best online courses to learn Java FX from scratch. Java FX is the latest and greatest way for creating a GUI application in Java. There was a time when AWT and Swing was very popular for developing GUI based application in Java. Still, slowly Java Swing lost that place to C#, which became the standard language for developing desktop GUI and AWS lost the battle with Swing.

3 ways to Learn Redux Framework in depth in 2023 - Best of Lot

The state is a very important part of React development. In simple words, state is a plain JavaScript object that controls the behavior of a React component. If you want to become a professional React developer, then you must understand how to use the state efficiently. React provides inbuilt support for managing state but when the application grows, managing state becomes difficult. So the global state is created for an entire application and to manage such a global state, third-party state management libraries are used.

Top 6 Free SQL Courses for Beginners to Learn Online in 2023 - Best of Lot

Hello guys, we are already in the second week of New year, and everyone is talking about their goals to improve them as a better person, a better programmer, or better health. If you have also made your goal, and one of them is to improve your SQL skill, you have come to the right place because I will share some of the free online courses to learn and master SQL this year. The list includes a free course from Udemy, a popular online portal to learn Oracle, PostgreSQL, and Microsoft SQL Server. Yes, I have tried hard to include free courses on different databases to choose the course you want. 

Top 5 Courses to Learn WordPress for Beginners in 2023 - Best of Lot

Hello guys, if you want to learn WordPress to create websites and start your career in web design and website development then you have come to the right place. WordPress is one of the most popular platform for website design and hosting all kind of websites like blog, e-commerce, simple website and more and learning Website is one of the best skill to acquire in 2023.  In the past, I have shared the best courses to learn HTMLCSSJavaScriptBootstrap, and Web development, and today I will share about the best online training courses to learn WordPress. WordPress is one of the easiest ways to create a website. It's also one of the most essential tools for web designers and web developers. If you know WordPress, you can work on different kinds of companies like startups and even multi-national. WordPress also allows you to do a lot of freelancing work.