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 2022? Is Blockchain Architectecture 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 2022 - Best of Lot

Hello guys, if you want to learn Web Development in 2022 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 webdev courses from sites like Udemy and Coursera which anyone can join free to learn essential Web development skills in 2022. 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 2022 - Best of Lot

Hello guys, if you want to learn Spring Framework and Spring Boot in 2022 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.

How to check if a given Tree is a Binary Search Tree in Java? Example Tutorial

Hello guys, if you are preparing for a coding interview then you may know those binary tree problems are not easy to solve on coding interviews and I have seen many candidates struggling to do post-order traversal and checking if a given binary tree is a binary search tree or not. If you want to succeed in the coding interview, you need to prepare well on binary trees in general. One way to prepare better is solving common binary tree coding problems like this one, where you need to find if the given tree is BST or not. There are a lot of things that would tell us if a tree is a binary search tree. But before we get to that, we need to understand what a binary tree is.

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.

How to fix java.lang.OutOfMemoryError: unable to create new native thread in Java [Solution]

It's been a long time since I write any Java Error or Exception troubleshooting tutorial so here we are. In this post, we will take a look at the "java.lang.OutOfMemoryError: unable to create new native thread" error which is a rate but quite possible in multithreading Java applications. This is another Java OutOfMemoryError that comes when JVM hits the native thread limitation allowed to be open by one process and not able to create any more new threads. Since each Java thread is associated with the OS thread, when OS refuses to provide a new thread, JVM throws OutOfMemoryError. It's rarely you will see common Java applications throwing this error but it's common when multiple application is using the same Java process e.g. WebServer Tomcat and a significant number of threads are allocated due to high load.

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.

Java Program to Multiply Two Matrices - Matrix Multiplication Example

How to write a Java program to multiply two matrices in Java is a very good programming exercise to get familiar with the two-dimensional array in Java. this example teaches about how to multiply arrays, how to access elements from a multi-dimensional array, how to pass them to a function etc. Since the matrix is a natural representation of a multi-dimensional array in Java, they are often used to illustrate real word matrix exercises e.g. the calculating sum of two matrices or calculating the difference of two matrices, etc.

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. 

[Solved] How to find and Print Armstrong number between 0 and 9999 in Java? Example

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153 is an Armstrong number, since 1**3 + 5**3 + 3**3 = 153, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. Along with usual beginner exercises like calculating factorial, reversing a string, or calculating prime numbers, this is a good exercise to build programming logic. It teaches you basic programming techniques of how to use the operator for something which is not obvious.

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.

jQuery Tutorial - How to modify multiple HTML elements in one line? Example

jQuery allows you to modify multiples elements in one go, you can modify attributes, text, or color of multiple HTML elements by executing just one line of jQuery code. In this jQuery tutorial, I will show you how to modify multiple <li> elements in one go. In our example, we have a couple of <li> tags to display sub-headings, now we will change them in one go using jQuery. If you look at our HTML, we have an ordered list <ol> to display the top 10 programming languages, each of them is an <li> item. We also have one button, "Click Me", which will when clicked, change all <li> item's text to "jQuery is the new Boss". Here is the jQuery code, which does that.

How to get Id of an HTML and DOM object in jQuery? Example Tutorial

As a page author, the id of an HTML element is something you should know. Still, there are scenarios when the page is automatically generated, or maybe some form elements are generated by using frameworks like JSF. In that case, what do you do if you want to find an id attribute of some elements in the page programmatically? How do you find those ids using jQuery? There are several ways to solve this problem, a couple of them in this article itself.  The jQuery API provides many methods to get any attribute or property, including the id of an HTML element programmatically. 

How to create a React application using Redux and Redux hooks? React Mini Project Example Tutorial

Redux is the most popular state management library. It is often used with React apps that are huge in size and state are shared among multiple components. Redux is a complex library to understand and even more complex to implement. It was even more complex and complicated before the introduction of react-redux hooks. Earlier, the connect method provided by Redux was used to connect React with the Redux store. Using connect method with other methods such as mapstatetoprops was complicated. But with the introduction of react-redux hooks, it is easy to use redux with redux. In this article, we will discuss what are react-redux hooks and how to use them with React.

What are React and Redux Hooks? How to use Hooks in React.js? Example Tutorial

Hello guys, if you want to learn about Hooks in React.js like useState, useSelector, useEffect, and useDispatch then you have come to the right place. In the past, I have shared the best React courseswebsites, and books and in this article, I am going to show you what is React hooks and how they make coding and statement management easier in React.js. If you remember, React came out in 2013 and since then, it has become one of the biggest players in the front-end development community. Today, React's demand is more than any other framework or library. There are several reasons for its popularity. React is flexible, easy to learn, programmer-friendly, and most importantly, it's high performing. 

How to use props in React.js? Example Tutorial

If you have ever worked with React, you definitely know what components are. A react application is made of several components and that is why components in React are defined as the building blocks of the application. In simple terms, a component is a class or function that can accept input and return a piece of code that defines a UI. Every React component can have input. These inputs are known as props. Props stand for properties and they are optional. A component works fine without props but they are one of the most useful parts of React.

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.

What is state in React.js? Example Tutorial

Hello guys, I have just started a new series, React for Java developers and I am going to publish React tutorials and examples to teach React.js, one of the most popular frontend libraries to Java developers. Since most full-stack Java development is happening on React and Spring Boot, it makes sense for Java developers to learn React.js. In the past, I have also shared both best React courses and books, as well as The React Developer RoadMap, which provides all the tools, libraries, and resources you need to become a proficient React Developer. 

Difference between let, var, and const variables in JavaScript? Example Tutorial

Hello guys, if you want to understand the difference between var, let, and const in JavaScript then you have come to the right place. Earlier, I have shared the best books and JavaScript courses for beginners and in this article, I will tell you the difference between varlet, and const and when to use them. They are three different ways to declare variables in JavaScript. The var is the classic and old way to declare variables in JavaScript and it can declare both local and global variables, while let and const are new ways to declare variables in Java and they have block scope, I mean they are only visible in the block they are declared. let is used to declare local variables while const is generally used to declare constants, I mean variable whose value doesn't change once initialized. 

7 jQuery Selectors Examples for Beginners - Tutorial

jQuery selectors are like CSS Selectors, which allow you to find or select an element from the DOM tree. When HTML pages loaded in a browser like Chrome, Firefox, or Internet Explorer, the browser creates a tree-like structure is known as Document Object Model or DOM. JavaScript and jQuery allow you to play with this DOM i.e. selecting elements from DOM, traversing through DOM, going from one element to another, selecting a list of elements from DOM, adding or removing elements from DOM, etc.

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.

Difference between SubStr vs SubString function in JavaScript - Tutorial Example

JavaScript provides two similar-looking String manipulation functions, substr and substring, though both are used to get a substring from a String, there is a subtle difference between substring and substr method in JavaScript. If you look at their signature, both substr(to, length) and substring(to, from) both take two parameters, but substr takes the length of the substring to be returned, while substring takes end index (excluding) for substring. This main difference will be more clear when we will see a couple of examples of using substr and substring in JavaScript code.

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 20 HTML Interview Questions with Answers for 1 to 3 Years Experienced

Hello guys, if you are preparing for web developer interview then you must prepare for HTML questions. HTML, CSS, and JavaScript is the backbone of web development and that's why every web develop is supposed to have good  knowledge of these three technologies. In the past, I have shared JavaScript Interview Questions and CSS Interview questions and today, I will share 20 HTML Interview Questions with answers for web developer interview. If you have done web development work then most likely you already know answers of these question but if you feel lacking then you can always go through these best HTML online courses to learn and revise concept in depth. 

Top 20 Machine Learning Interview Questions with Answers

Hello guys, if you are preparing for Machine Learning Interviews and looking for common Machine Learning questions then you have come to the right place. Earlier, I have shared 35 Python Interview Questions and 20 AI Interview Questions and in this article, I am going to share 20 Machine Learning Interview Questions with answers. If you have gone through a Machine learning course or have worked in Machine Learning for a few months then you should know answer to all of these questions but if you struggle to answer them then I suggest you to revise concepts by going through these best Machine Learning courses for beginners. They are great to learn and revise important Machine Learning concepts. 

Top 25 Vue.js Interview Questions and Answers for 1 to 2 Years Experienced

Hello guys, if you are preparing for Vue.js interviews and looking for some frequently asked Vue.js questions from interviews then you have come to the correct place. Earlier, I have shared React.js Interview questions and JavaScript questions and in this article, I am going to share common Vue.js Interview questions for 1 to 2 years experienced web developers. With the success of libraries like React.js, developers around the globe are leaning more towards such flexible technologies. Though full-fledged frameworks like Angular are also popular and widely used, developers want flexibility.

Top 20 PostgreSQL Interview Questions with Answers

Hello guys, if you are preparing for Postgres Interview or a Java development role where PostgreSQL skills are needed but not sure how to prepare, what to prepare etc and looking for PostgreSQL Interview questions with answers then you have come to the right place. Earlier, I have shared 50 SQL Phone interview questions and 6 SQL Query questions and in this article, I am going to share frequently asked PostgreSQL questions with answers. You can use these questions and answers to prepare well for your Job interview and you can also learn essential PostgreSQL concepts by going through these questions.

Top 10 Free NFT (Non Fungible Tokens) Courses for Beginners in 2022 - 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. 

[Solved] How to Count Negative Numbers in a Sorted Matrix? [Amazon Coding Interview Question]

Hello guys, earlier I shared a list of Google Coding Interview questions, and today, I am going to share with you an interesting coding problem which was asked on Amazon, how to count total negative numbers in a given matrix where rows and columns are sorted in increasing order. Again, I found this coding problem while surfing on the internet, It wasn't actually asked to me or my reader, so I can't vouch that it's actually an Amazon Interview question. Though, I really expect it to be because it's an interesting problem and the optimal solution is not so easy but with the internet, you never know.

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.

How to Rotate an Array to Left or Right in Java? Example - LeetCode Solution

Hello guys, rotating an array in Java is a common coding problems which are often used to teach beginners coding as well used during interviews to check candidate's programming and data structure skills. This problem may look easy but its not that easy, especially if you are not coding regular. In order to rotate an array of n elements to the right by kth index, you need to rearrange the item in such a way that the array will start from k + 1the element.  For example, with n = 7 and k = 3, the array [1, 2, 3, 4 ,5, 6, 7] is rotated to [5, 6, 7, 1, 2, 3, 4]. See, it looks like you pick the the 4th element and rotated the array in right direction. The problem becomes even more interesting when interviewer ask you to rotate the array by left or right and in place. Could you do it in-place with O(1) extra space?

How to Transpose a Matrix in Java? Example Tutorial

Hello guys, if you are wondering how to transpose a matrix in Java then you have come to the right place. Matrix related coding problems are great way to learn multi-dimensional array and nested loop and they are good programming exercise for beginners. In the past, I have taught you how to multiply matrices in Java and how to add/subtract matrices in Java, and in this article, I will show you how to create transpose of a given matrix in Java, but before that let's first understand what is transpose of a matrix means and how do you transpose a matrix in maths? Well, a transpose of a matrix is nothing but a matrix whose rows and columns are reversed. 

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.

10 Best Udacity Courses For Python Developers in 2022

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.