Java 8 Stream filter() + findFirst Example Tutorial

Suppose, you have a list of prime numbers and you need to find the first prime number which is greater than a given number? How do you find it? Don't tell that you will loop through the list and check each element and return the first element which is greater than the given number. Well, that's right but that's not what you should do in Java 8. That's good for Java 7 or earlier version but Java 8 offers you many better alternatives and one of them is Stream. You can use the Stream class along with filter() and findFirst() methods to find out an element based upon a Predicate, a functional interface for defining a condition which returns a boolean.

Top 22 Array Concepts Interview Questions Answers in Java

An array is one of the fundamental data structures and most of the other advanced data structures like lists, hash tables are built using arrays.  Good knowledge of fundamental data structures like the array, linked list, a binary tree is not just essential for writing better code but also doing well on Programming Job interviews. Array-based questions are quite popular in Java interviews. There are two types of questions you will find, first which are based upon array implementation in Java, and second which are based upon how to use an array data structure to solve some coding problems. The first type of question is quite popular in the telephonic round of Java interviews and the second is usually asked on written tests and face-to-face interviews.

How to add and remove Elements from an Dynamic Array in Java? Example Tutorial

Java beginners often ask how to add new elements to an array in Java? or how to remove elements from an array in Java? is that possible in Java? Well, no, it's not possible in Java because arrays length cannot be changed once created. This means neither you can add new elements nor you can remove an old one from an array in Java. All you can do is reassign values to a different bucket. For example, if you have a string array of length 3 like {"java", "is", "great"} then you can just replace the individual index to make it like {"Python", "is", "great"} by replacing "java" with "Python" at first index, but you cannot add or remove elements.

Top 5 Spring Cloud Annotations in Java with Examples

If you are developing a Java application for Cloud, then you should learn Spring Cloud, a great framework and extension of the popular Spring framework, which can help you to develop a cloud-native Java application. Spring Cloud provides several necessary services required for a cloud-based Java application and Microservices like configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, a control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state, etc.

Difference between array and Hashtable or HashMap in Java

A couple of days back someone asked me about the difference between an array and a hashtable, though this is a generic data structure and programming question, I'll answer it from both a general programming perspective as well on Java perspective where Hashtable is not just a data structure but also a class from Java Collection API. Even though both array and hashtable data structure are intended for fast search i.e. constant time search operation also known as O(1) search, the fundamental difference between them is that array require an index while hash table requires a key which could be another object. 

Top 5 Free MongoDB and NoSQL courses for Beginners to Learn in 2021 - Best of Lot

If you want to learn MongoDB in 2021, one of the most popular NoSQL databases,s and are looking for free resources like free tutorials and free online MongoDB courses to start with, you have come to the right place. Earlier, I have shared the 10 free full-stack development courses, and today, I will share the 5 best free online courses to learn Mongo DB online. These courses are created by experts and made free for educational purposes. Thousands of students have already joined these free Mongo DB courses, and you can also do the same to learn this in-demand skill and further boost your resume for cutting-edge jobs. 

3 Ways to convert a Map to List in Java 8 - Example Tutorial

Hello guys, when you convert a Map to List in Java 8 or before, you have three choices like you can get a list of keys from Map, a List of values from Map, or a List of entries from Map, which encapsulates both keys and values. The API doesn't provide these methods because Map doesn't guarantee any order and the List interface guarantees ordering, like insertion order. Hence, JDK API provides an equivalent method to convert a Map to Set, like keySet() will return a set of keys and entrySet() will return a set of entries.

How to Remove Objects From ArrayList while Iterating in Java - Example Tutorial

One of the common problems many Java Programmers face is to remove elements while iterating over ArrayList in Java because the intuitive solution doesn't work like you just cannot go through an ArrayList using a for loop and remove an element depending upon some condition. Even though java.util.ArrayList provides the remove() methods, like remove (int index) and remove (Object element), you cannot use them to remove items while iterating over ArrayList in Java because they will throw ConcurrentModificationException if called during iteration. The right way to remove objects from ArrayList while iterating over it is by using the Iterator's remove() method.

Top 5 Linux Courses from Udemy, Coursera, and Pluralsight for Beginners in 2021 [UPDATED] - Best of Lot

Hello guys, if you want to learn Linux operating systems and command lines and look for the best Linux courses, you have come to the right place. In the past, I have shared some free Linux courses and bash scripting courses for programmers and developers, and many of you asked for more comprehensive online Linux courses to learn Linux in-depth, which motivates me to write this article. In this article, you will find the best Linux online training courses from Udemy, Pluralsight, Coursera, and edX, my favorite online learning platforms. 

9 JSP Implicit Objects and When to Use Them

If you are new to JSP then your first question would be what are implicit objects in JSP? Well, implicit objects in JSP are Java object which is created by Servlet containers like the tomcat or Jetty during translation phase of JSP, when JSP is converted to Servlet. These objects are created as local variables inside the service() method generated by the container. The most important thing about the implicit objects is to remember that these objects are available to any JSP developer inside the JSP page and they can do a lot of things with implicit objects and expression language which was only possible with scriptlet earlier. That's why they are known as implicit objects. 

How to implement PreOrder traversal of Binary Tree in Java - Example Tutorial

The easiest way to implement the preOrder traversal of a binary tree in Java is by using recursion. The recursive solution is hardly 3 to 4 lines of code and exactly mimic the steps, but before that, let's revise some basics about a binary tree and preorder traversal. Unlike array and linked list which have just one way to traverse, I mean linearly, the binary tree has several ways to traverse all nodes because of its hierarchical nature like level order, preorder, postorder, and in order. Tree traversal algorithms are mainly divided into two categories, the depth-first algorithms, and breadth-first algorithms. In depth-first, you go deeper into a tree before visiting the sibling node, for example, you go deep following the left node before you come back and traverse the right node.

Is Java a Pure Object Oriented Programming Language?

Hello guys, today, I am going to discuss one of the oldest questions related to Java, whether Java is a pure object-oriented language or not? The short answer is no. My answer is based on the fact that in a pure object-oriented language everything is an object and there are many things in Java that are not objects like primitive data types like boolean, char, short, int, long, float, double, different kinds of arithmetic, logical and bitwise operator like +, -. *, /, &&, || etc. There are only a few pure OO programming languages are Smalltalk and Eiffel, If there is more, I may not know but Smalltalk is often touted as the purest form of an object-oriented language.

How to reverse a singly linked list in Java without recursion? Iterative Solution Example

Hello guys, reverse a linked list is a common coding problem from Programming Job interviews and I am sure you have seen this in your career, if you are not, maybe you are a fresher and you will going to find about this very soon in your next technical interview. In the last article, I have shown you how to use recursion to reverse a linked list, and today, I'll show you how to reverse a singly linked list in Java without recursion. A singly linked list, also known as just linked list is a collection of nodes that can only be traversed in one direction like in the forward direction from head to tail. Each node in the linked list contains two things, data and a pointer to the next node in the list.

10 Best Free Data Structure and Algorithms Courses in Java and C++ 2021 [UPDATED]

Algorithms and Data Structure are two of the most fundamentals and essential topics from Computer Science, which is used everywhere in software development. I firmly believe that a good knowledge of these two topics is also crucial to become a better programmer because a person who has a good understanding of algorithms and data structures can make thoughtful choices and write programs that can handle changes better and perform well. They are also essential to crack coding interviews at top tech companies like Google, Microsoft, Amazon, Facebook, and Apple, which puts a lot of emphasis on candidate's ability to use existing data structures and algorithms to solve complex problems they have never seen before.

How to find 2nd, 3rd or kth element from end in a singly linked list in Java [Solved] - Example

Hello guys, today, I am going to discuss one of the important linked list based coding problems from interviews - how to find the Kth element from the end? This question is also asked as to how do you find the 3rd element from the last of a singly linked list in one pass or write a Java program to find the 5th element from the tail of a given linked list in one iteration. In this article, you will learn the programming technique so that you can solve any variant of this problem, I mean the Kth node from the tail problems and some linked list-based challenges. The difficulty in this question is that you need to solve the problem in one iteration or one pass. This means you cannot traverse the linked list again. I mean you cannot go till the end then traverse back to the Kth element.

6 Advanced Comparator and Comparable Examples in Java 8 for Sorting ArrayList Objects By Fields

The JDK 8 release has completely changed the way you compare objects and sort them in Java. The new features of the Java 8 language e.g. lambda expression and method reference have made it easier to implement both Comparator and Comparable interface, as you don't need an Anonymous class for inline implementation. Now, you can create Comparators in just one line by using lambdas and method reference as we'll see in this article. Other features like providing default and static methods on interfaces have also made a huge difference when it comes to Comparator. They helped Java API designers to redesign and evolve existing interfaces, which wasn't possible earlier without breaking existing clients of those interfaces.

Top 5 Courses to learn MERN Stack in 2021 - (MongoDB, Express.js, React.js, and Node.js)

The popularity of the MERN stack development has grown significantly in recent years. The MERN stack is one of the two popular JavaScript stacks, along with the MEAN stack, and used to develop single-page dynamic web applications.

MERN stands for MongoDB, Express.js, React.js, and Node.js.
  • MongoDB: A popular NoSQL database. It stores data in JSON format.
  • Express.js: A flexible and minimal web framework for Node.js.
  • React.js: A JavaScript library used to create user interfaces.
  • Node.js: A runtime environment used to execute JavaScript outside the browser.

How to use Randam vs ThreadLocalRandom vs SecureRandom in Java? Example Tutorial

Hello guys, one of the common tasks for Java developers is to generate an array of random numbers, particularly in game development. For example, if you are coding for dice-based games like Ludo or Snake and Lader then you need to generate a random number from 1 to 6 to simulate dice behavior. The same goes for other dice-based games. There are many cases where you need to generate random numbers and an array of random numbers. In some cases, duplicates may be allowed while other duplicates are not permitted.  

How to implement Linear Search Algorithm in Java? Example tutorial

In the last article about searching and sorting, you have learned the binary search algorithm and today I'll teach you another fundamental searching algorithm called Linear search. Linear search is nothing but iterating over the array and comparing each element with the target element to see if they are equal since we search the array sequential from start to end, this is also known as sequential search or linear search. It is very slow as compared to binary search because you have to compare each element with every other element and is definitely not suitable for a large array. It's practically useful only in the case of a small array of up to 10 to 15 numbers. In the worst case, you need to check all elements to confirm if the target element exists in an array or not.

How to Convert String to LocalDateTime in Java 8 - Example Tutorial

Hello guys, today, I will talk about a common problem while working in a Java application, yes you guessed it right, I am talking about String to Date conversion in Java. I had discussed this before (see the Date to String) when Java 8 was not out, but with Java 8, I don't see any reason to use old date and time API, and hence I am writing this post to teach you how to convert String to Date in Java 8 or beyond. Suppose you have a date-time String "2016-03-04: 11:01:20" and you want to convert this into a LocalDateTime object of Java 8 new date and time API, how do you do that? Well, if you have worked previously with String and Date then you know that you can parse String to Date in Java.

How to use Stream.filter method in Java 8? Example Tutorial

In the last couple of Java 8 tutorials, you have learned how to use map(), flatMap(), and other stream methods to get an understanding of how Java 8 Stream and Lambda expressions make it easy to perform the bulk data operation on Collection classes like List or Set. In this Java 8 tutorial, I am going to share how to use the filter() method in Java 8, another key method of the Stream class.  This is the one method you will always be used because it forms the key part of the Stream pipeline. If you have seen some Java 8 code, you would have already seen this method a couple of times.

Top 5 Online Courses to learn PyTorch and Keras for Deep Learning in 2021 - Best of Lot

Hello guys, if you want to learn PyTorch and Kearas from scratch and looking for the best PyTorch and Keras online courses, then you have come to the right place. In the past, I have shared the best machine learning courses and best TensorFlow courses, and today I will share the best Keras and Pytorch courses for beginners and experienced programmers. PyTorch and Keras are two deep learning libraries developed by two big companies Facebook and Google, aiming to facilitate the creation of deep learning applications like face recognition and self-driving cars, and so on.

How to reverse bits of an integer in Java? [LeetCode Solution]

Hello guys In this Java article, you will learn how to reverse bits of an integer in Java. This is one of the common coding problems which is often asked during phone rounds of technical interviews on companies like Amazon, Google, and Microsoft. If you have appeared in any programming interviews then there is a good chance that you might have already seen this problem before. If you know the solution then you are in a good place but if you don't know the solution then don't disappoint as many experienced Java developers also struggle to solve this problem.

6 Best Free Blockchain Courses and Certifications for Beginners to Learn in 2021

Hello guys, if you want to learn Blockchain development and are looking for some free Blockchain courses, you have come to the right place. Earlier, I have shared my favorite and best blockchain courses for programmers, and a lot of you asked for free online courses to learn Blockchain, so today, I am going to share the best free Blockchain development courses you can join in 2021. Blockchain is one of the most in-demand technologies and one skill that you should learn in 2021. It will not only help in your career but also raise your profile. This is one thing I have highly recommend programmers to learn this year. 

10 Examples of Stream API in Java 8 - count + filter + map + distinct + collect() Examples

The Java 8 release of Java Programming language was a game-changer version. It not only provided some useful methods but totally changed the way you write programs in Java. The most significant change it brings in the mindset of Java developers was to think functional and supported that by providing critical features like lambda expression and Stream API, which takes advantage of parallel processing and functional operations like filter, map, flatMap, etc. Since then, a lot of Java developers are trying their hands to learn those significant changes like lambda expression, method reference, new Date and Time classes, and, more importantly, Stream API for bulk data operations.

How to debug Java 8 Stream Pipeline - peek() method Example Tutorial

Hello guys, I have been writing about some important methods from Java SE 8  like map(), flatMap(), collect(), etc for quite some time, and today I'll share my experience with another useful method peek() from class. The peek() method of the Stream class can be very useful to debug and understand streams in Java 8. You can use the peek() method to see the elements as they flow from one step to another like when you use the filter() method for filtering, you can actually see how filtering is working like lazy evaluation as well as which elements are filtered.

5 Best Django Online Courses for Beginners to Learn in 2021

Hello guys, if you want to become a Python web developer and looking for the best online courses to learn Django, Flask, and Python web development, then you have come to the right place. In the past, I have shared the best Python courses and the best Flask courses, and today, I will share the best course to learn everything about Python web development. You may know that Python is a multi-purpose programming language meaning that you can use it in different fields such as GUI application, artificial intelligence, and web application, and much more, just to name a few.

Can you make an Abstract Class or Method Final in Java? Example

No, you cannot make an abstract class or method final in Java because the abstract and final are mutually exclusive concepts. An abstract class is incomplete and can only be instantiated by extending a concrete class and implementing all abstract methods, while a final class is considered complete and cannot be extended further. This means when you make an abstract class final, it cannot be extended hence it cannot be used and that's why the Java compiler throws a compile-time error when you try to make an abstract class final in Java. In short, an abstract class cannot be final in Java, using both abstract and final modifiers with a class is illegal in Java. 

Difference between Binary Tree, Binary Search Tree, Balanced Tree (AVL and Red Black Tree)?

The Tree data structure is one of the essential data structures, but unfortunately, many programmers don't pay enough attention to learning Trees, particularly advanced tree data structures like balanced trees like AVL and Red-Black tree. Many of them think that knowing just array and the linked list is enough for programming interviews, but when they face questions about a tree, like the difference between binary tree and binary search tree, or the difference between binary search tree and a self-balanced tree-like AVL tree or Red-Black tree, they become speechless.

How to use static initializer block and instance initializers in Java - Example tutorial

In Java, you can initialize member variables or fields in the same line you declare, in the constructor, or inside an initializer block. There are two types of initializer blocks in Java, static initializer block to initialize static variables and instance initializer block to initialize non-static fields. As the name suggests, the main difference is their purpose, instance initializer block if for instance variables, and static initializer block is for static variables. Another key difference between them is the time of execution. 

How to Calculate Next Date and Year in Java | LocalDate and MonthDay Example Tutorial

Hello guys, if you are wondering how to calculate the next premium date, next birthday, or exact date for the next Christmas holiday in Java then you have come to the right place. Earlier, I have shared 20+ examples of Date and Time in Java, and in this article, I will show you how you can use the LocalDate and MonthDay class from the new Java 8 Date and Time package to calculate the next or previous date in Java. This new API is very well structured and you have classes to represent different Date concepts, for example, you can use LocalDate to represent a Date without time components like the next premium date or employee joining date or birth date. 

How to Reverse an Array in place in Java? Example Solution

It's relatively easy to reverse an array if you have the luxury to use another array, but how would you reverse an array if a temporary buffer is not allowed? This is one of the testing array interview questions, which often proved tricky for Java and other beginner Programmers. But, don't worry, I'll tell you how you can solve this problem without losing your cool. Well, you can also reverse an array in place without using an additional buffer. If you know how to access array elements and how to loop over an array in Java using traditional for loop, you can easily solve this problem without using additional space or in-place as described in many Algorithms books and courses, and on Coding interviews.

5 Free Courses for Google Cloud Professional Architect Certification [2021] - Best of Lot

Hello guys, if you are preparing for Google Cloud Professional Architect certification and looking for free online training courses, then you have come to the right place. In the past, I have shared the best courses to learn Google Cloud and certification courses to pass cloud engineer, data engineer, and cloud architect certifications. Today, I am going to share free GCP Cloud Architect certification courses for beginners experienced cloud professionals. This is one of the most difficult and prestigious exams, similar ot the AWS Solution Architect and Azure Technology Architect (AZ-300) exam; once you pass this exam, you will have sufficient knowledge and skills to propose a Google cloud-based solution very in-demand skill. 

3 ways to ignore null fields while converting Java object to JSON using Jackson? Example

Ignoring null fields or attribute is a one of the common requirement while marshaling Java object to JSON string because Jackson just prints null when a reference filed is null, which you may not want. For example, if you have a Java object which has a String field whose value is null when you convert this object to Json, you will see null in front of that. In order to better control JSON output, you can ignore null fields, and Jackson provides a couple of options to do that. You can ignore null fields at the class level by using @JsonInclude(Include.NON_NULL) to only include non-null fields, thus excluding any attribute whose value is null.

Top 5 Courses to learn Scrapy with Python in 2021 - Best of Lot

Hello guys, web scraping is one of the useful skills, and you can use it for many different projects. For example, you can use web scraping to find the cheapest flight between the two countries, find the cheapest hotels and holiday packages. Python makes it easy to scrape data from the website and store it. Many built-in tools can do web crawling and scraping, and one of the best tools is Scrapy. This tool is a free and open-source tool written in python for web scraping and crawling purposes, and you can use it to extract data from any website.

5 Differences between an array and linked list in Java

The difference between an array and a linked list is one of the frequently asked data structure and algorithm interview questions and you might have seen it before on your telephonic or face-to-face interview. It is also a very popular question during practical exams in Computer Science degree courses like B.E. and B.Tech. It's very simple and easy to answer but you just can't afford to miss this question in an interview. Both array and linked list are two of the most popular and fundamental data structures in Computer Science and Programming, and Java supports both of them.

What is difference between final vs finally and finalize in Java?

Hello guys, final, finally, and finalize are three confusing keywords, modifiers, and methods in Java. They sound similar, but they are for different purposes. For example, the final keyword is a modifier in Java. When you use the final keyword with a class, it becomes a final class, and no one can extend this like String is final in Java. When you use the final modifier with a method, then it cannot be overridden in a subclass, and when you use the final keyword with a variable, it becomes a constant, i.e. its value cannot be changed once assigned.

How to convert ArrayList to HashMap and LinkedHashMap in Java 8 - Example Tutorial

One of the common tasks in Java is to convert a List of objects, like a List<T> into a Map, I mean Map<K, V>, where K is some property of the object and V is the actual object. For example, suppose you have a List<Order>, and you want to convert it into a Map, e.g. Map<OrderId, Order>, how do you that? Well, the simplest way to achieve this is iterating over List and add each element to the Map by extracting keys and using the actual element as an object. This is exactly what many of us do in the pre-Java 8 world, but JDK 8 has made it even simpler.

How to code Binary Search Algorithm using Recursion in Java? Example

Hello guys, In the last article, we have seen the iterative implementation of binary search in Java, and in this article, you will learn how to implement binary search using recursion. Recursion is an important topic for coding interviews but many programmers struggle to code recursive solutions. I will try to give you some tips to come up with recursive algorithms in this tutorial. In order to implement a recursive solution, you need to break the problem into sub-problems until you reach a base case where you know how to solve the problem like sorting an array with one element. Without a base case, your program will never terminate and it will eventually die by throwing the StackOverFlowError.

5 Free Google Cloud Developer Certification Courses in 2021 - Best of Lot

If you are preparing for Google Cloud Professional Cloud Developer certification and looking for free Google cloud courses to learn online then you have come to the right place. In the past, I have shared the best courses to learn Google Cloud as well as certification courses to pass cloud engineer, data engineer, and cloud architect certifications, and today, I am going to share free Google Cloud Professional Cloud Developer certification exam courses for both beginners and experienced IT  professionals. This is one of the best exams for a Software developer who wants to learn Google Cloud Platform from a developer's point of view. 

Post Order Binary Tree Traversal in Java Without Recursion - Example Tutorial

In the last article, I have shown you how to implement post-order traversal in a binary tree using recursion, and today I am going to teach you about post order traversal without recursion. To be honest, the iterative algorithm of post-order traversal is the toughest among the iterative pre-order and in-order traversal algorithm. The process of post-order traversal remains the same but the algorithm to achieve that effect is different. Since post-order traversal is a depth-first algorithm, you have to go deep before you go wide. I mean, the left subtree is visited first, followed by the right subtree, and finally, the value of a node is printed.

Post order traversal Algorithms for Binary Tree in Java with example

In the last couple of articles, you have learned about pre-order and in-order tree traversal algorithms in Java, and today, you will learn about the post-order traversal in a binary tree. It is the toughest of all three tree traversal algorithms and programmers generally struggle to implement this when asked in a coding interview, hence it makes sense to understand and practice this algorithm before going for the interview. The post order traversal is also a depth-first algorithm because you go deep before you visit other nodes on the same level.

Top 5 Free Courses to Learn React in 2021 - Must Join, Best of Lot

React.js, React JS, or React is one of the most popular frameworks or Javascript libraries for building user interfaces. It's backed by Facebook, and it's often viewed as an alternative to the tremendous Angular framework by Google. React is also very flexible, fast, easy to learn, and fun to work with. It is designed to make the process of building modular, reusable user interface components simple and intuitive and that's why most of the modern GUI and web applications are build using the React framework. It is developed at Facebook and it focuses on the 'View' aspect of MVC in web applications. The component-based development is one of the biggest advantages of the React library which is both rich and extensible.

7 Examples to Sort One and Two Dimensional String and Integer Array in Java | Ascending, Descending and Reverse Order

Sorting array is a day-to-day programming task for any software developer.  If you have come from a Computer Science background then you have definitely learned fundamental sorting algorithms like the bubble sort, insertion sort, and quicksort but you don't really need to code those algorithms to sort an array in Java because Java has good support for sorting different types of array. You can use Arrays.sort() method to sort both primitive and object array in Java. But, before using this method, let's learn how the Arrays.sort() method works in Java. This will not only help you to get familiar with the API but also its inner workings.  This method sorts the given array into ascending order, which is the numeric order for primitives and defined by compareTo() or compare() method for objects.

How to prepare Oracle Certified Master Java EE Enterprise Architect (1z0-807, 1Z0-865, 1Z0-866) - OCMJEA6 Exam

The OCMJEA 6 certification is one of the most difficult, time-consuming, and tiresome Java certifications. Still, it was also the one that made me learn and grow professionally. This certification consists of 5 phases:

Phase 1: Compulsory Course

At this point, the candidate is required to take at least one official Oracle course from Java at any partner company. You can complete this course during certification - before, during, or after.

If you already have experience in Java and architecture, leave to take the course at the end. If not, use the classes to gain knowledge for the test by doing them before. There is a complete grid of Java courses for the candidate to acquire the necessary know-how for this certification.

How to use Record in Java? Example

A Java record is a special kind of java class that is used as a 'data carrier' class without the traditional 'Java ceremony' (boilerplate). This represents an immutable state that is passing immutable data between objects. The Java Record was introduced with Java 14, and it is a preview feature because it must be enabled before it can be used. Records received via a database query, records returned from a remote service call, records read from a CSV file, and other use cases can all benefit from Java Record instances.

3 Ways to change Embedded Tomcat Server Port in Spring Boot Application - Example

If you know Spring Boot really simplifies the Java web development by embedding essential libraries as well as a tomcat server to run Java web applications. By default, this tomcat server listens on port 4588, and for any reason, if you want to change, then Spring boot provides several configuration options to achieve that. For example, I wanted tomcat to listen on port 8080 because port 80 is forwarded to 8080 in our Linux machine, and we wanted our clients to provide our client with a clean URL without a port.

How to print all leaf nodes of a Binary Tree in Java without Recursion - Example

In the last article, you have learned how to print all leaf nodes of a binary tree in Java by using Recursion, a useful technique to solve binary tree problems and in this article, we'll answer the same question without using Recursion. Why should we do this? Well, it's a typical pattern on a programming job interview to solve the same problem using both Recursion and Iteration. Since some questions are easy to solve using recursion like linked list problems, binary tree-based problems, tower of Hanoi, or Fibonacci series but their non-recursive solution is comparatively tricky, the interviewer tests candidates against this shift in the algorithm.

Top 5 Free Database and SQL Query Courses for Beginners to Learn Online in 2021 - Best of Lot

Hello guys, I have been sharing some free programming resources e.g. books and courses in this blog for quite some time. Earlier I have shared free courses on Java, Maven, Spring, and Data Structure and Algorithms and today I'll share some of the free online training courses to learn SQL and Database. Why you should learn SQL? Well, it's one of the must-have skills for programmers, application developers, and IT professionals. Like Linux, this is one skill that is going to serve you longer than any other programming language, framework, or library. 

How to Check is given String is a Palindrome in Java using Recursion

In this tutorial, you will learn how to check if a string is a palindrome in Java using Recursion. A String is nothing but a collection of characters like "Java," and String literals are encoded in double-quotes in Java. A String is said to be a palindrome if the reverse of String is equal to itself like "aba" is a palindrome because the opposite of "aba" is also "aba", but "abc" is not a palindrome because the reverse of "abc" is "cba" which is not equal. Recursion means solving a problem by writing a function which calls itself. In order to check if String is a palindrome in Java, we need a function that can reverse the String.

5 Free Ethical Hacking courses for Beginners to Join in 2021 - Best of Lot

Hello folks, if you want to learn Ethical Hacking and looking for free online courses, then you have come to the right place. Earlier, we have shared the best Cyber Security Courses, and today, we are doing share free Ethical hacking courses for you. Most of us have even a little bit of knowledge about the subject or industry that would be ideal if you start a career in that field, but the problem for most people is finding the right course or program that help you master these skills and become professional in the field and click on this article likely shows that you are interested in ethical hacking.

Top 5 Free Apache Maven eBooks for Java Developers

If you are working in Java for a couple of years, you surely know about Maven, the most popular tool to build Java applications. Recently I had shared 10 things about Maven Java developers should know, (if you have read it yet, you can read it here) and I receive a lot of good feedback about how useful those plugins and Maven, in general, are for Java developers. This motivated me to write more stuff about Apache Maven, and then I thought about sharing some of the free Maven courses and ebooks Java developers can use to learn Maven. 

Top 4 Free Microsoft SQL Server Books - PDF Download or Online Read

Hello Guys, if you want to learn SQL Server and looking for free resources then you have come to the right place. Earlier, I have shared free SQL and database courses and today, I am going to share some of the excellent database and SQL server books that are freely available on the internet for reading online or download as PDF. If you have been reading this blog then you know that I love books, I love to read books, and I love to collect books, that's why I have a significant online and offline library. Many people question me, do I really find to read all the books which I share? Well, I don't read all books page by page, unless and until it's something like Effective Java or Clean Code

How to check if strings are rotations of each other in Java? String Rotation Example Solution

String-based algorithmic questions are very popular in Java interviews e.g. checking if two String is the anagram of each other (see), or checking if given String is a palindrome (see), or just finding permutations of given String (see). One of such popular String-based interview questions is about to check if two Strings are a rotation of each other in Java. In order to solve this question, you should know what is String rotation? Well, A string is made of characters and you just rotate the String around any character like "programming" will become "ingprogramm" if we rotate the String on the trailing character 3 times.

4 Best Books to Learn Web Service in Java - SOAP and RESTful

If you are a Java developer and want to learn how to develop Web Services in Java, both SOAP and RESTful, but confused about where to start, then you have come to the right place. In this article, I am going to share some of the best books to learn about both SOAP and RESTful web services in Java. If you are not familiar with Web Services, it's a way to expose the services provided by your application to other developers and applications. For example, if your system offers weather information, then the user can go and check whether manually by looking at the Web GUI built using HTML, CSS, and JavaScript. Still, by exposing the same information using Web services, you allow a programmer to display as they want.

Difference between @SpringBootApplication vs @EnableAutoConfiguration annotations in Spring Boot? Example

Even though both @SpringBootApplication and @EnableAutoConfiguration can be used to enable the auto-configuration feature of Spring Boot, there is a subtle difference between them. The @SpringBootApplication does much more than what @EnableAutoConfiguration does. It's actually a combination of three annotations: @Configuration, which is used in Java-based configuration on Spring framework, @ComponentScan to enable component scanning of components you write like @Controller classes, and @EnableAutoConfgiuration itself, which is used to allow for auto-configuration in Spring Boot application.

Top 5 Online Data Science and Machine Learning Degree Programs to Join in 2021- Best of Lot

Hello guys, I have been sharing some online degree programs you can take online for the last couple of weeks as more and more people are looking for online technical degree programs. Earlier, I have shared the Top 5 Computer Science degrees you can earn online. Today, I will share the top 5 Data Science and Machine learning degrees you can earn online from the world's reputed universities.  Data Science is the way or the process of extracting insights and useful information from your data to understand different things and turn that data into a story in the shape of graphs and a dashboard that anyone can understand and by using many different programming languages like Python and R. But imagine if you can earn an online degree in this topic, that's what we are covering in this article.

Top 5 Courses to Learn Responsive Web Design in 2021 - Best of Lot

Hello folks, Responsive web design is one of the essential skills to become a front-end web developer, a web designer, and even a full stack developer. If you are interested in learning Responsive web design and looking for the best online training courses, then you have come to the right place. In the last few articles, I have shared the best online courses to learn UI/UX design, HTML 5, CSS 3, and Photoshop, and in this article, I will share the best online courses to learn Responsive web design from sites like Udemy, Pluralsight, Coursera, and other popular online portals.  

What is the cost of Oracle Java Certifications - OCAJP, OCPJP, OCEWCD, OCPJD?

One of the frequently asked questions about Oracle Java certifications, formerly known as Sun Certified Java programmer like OCAJP, OCPJP, OCEWCD, OCMEJA, etc. is about the cost of certification. Many of my readers often ask what the cost of OCAJP  like OCAJP 8 or OCAJP 11 and  OCPJP like OCPJP 8 and OCPJP 11 is? Is there any discount available? What are the fees of Java 8 certifications? How much Java architect exam cost? Etc. I have answered many of them one to one via Facebook and Email in the past, but after so many such requests, I decided to write a blog post about it.

5 Best Free Course to learn Microservices in Java with Spring Boot and RxJava in 2021

Hello Java programmers, if you want to learn Microservice architecture and look for free Microservice resources like free online courses, you have come to the right place. Earlier, I have shared the best Microservice courses for Java programmers to build Microservice using Java and the Spring framework, and today, I will share some free courses to learn Microservice in Java using Spring Boot and the Spring Cloud framework. If you don't know, Microservices is a modern architecture that goes along nicely with cloud computing and makes deployment, scaling, and even development easier. 

Top 3 Free Struts Books for Java EE developers - Learn Online, PDF download

Jakarta Struts is one of the most popular MVC frameworks to create a Java web application. Struts 1.0 had ruled the world in the early 2000 era before Spring MVC took over. Still, there are lots of projects written in Struts that need active maintenance, and that's why Struts developers are still in demand. It has not become anything like COBOL, but the latest version of Struts 2.0 is a capable web MVC framework with dependency injection and has a sizable community behind it. It has close competition with Spring MVC, but given the demand for Struts developers, it's still a good technology to learn if you are looking for a job in a Java web development position.

Java Program to find Armstrong numbers with Example

Armstrong number Example in Java
How to check if a number is an Armstrong number or not? or write a Java program to find Armstrong's number? This is a common Java interview question asked on-campus interviews and fresher-level interviews. This is also a popular Java programming exercise on various schools, colleges, and computer courses to build programming logic among Students. An Armstrong number is a 3 digit number for which the sum of cube of its digits is equal to the number itself. 

How to Control HTTP Caching in Java Web application using Spring MVC Framework

One of the standard requirement in a secure Java web application is to disallow the back button of the browser or invalid the session if the user hit the back button of the browser. You might have seen this behavior while doing online banking or net banking, almost all the banks don't allow you to use the browser's back button. Your session gets terminated as soon as you hit the back button, and you have to log in again to do any transaction. Btw, have you ever checked some situations on your Servlet and JSP-based Java web application, like, if you pressed the back button of your browser after logging in, what happened? You will find that the browser takes you to the previous page.

Top 40 Binary Tree Coding Interview Questions for Programmers

Hello guys, if you are preparing for coding interviews and want to master tree-based questions then you have come to the right place. A tree is one of the most important data structures because it allows you to store hierarchical data as opposed to an array and linked list which allows storing linear data. That's why knowledge of tree data structure is very important from an interview point of view. A lot of programmers and my readers have been asking me to share some binary tree-based coding interview questions, just like I have done for the array, linked list, string, software design, patterns, hash table, and data structure in general. 

Top 50 Java Coding Interview Questions and Solutions

Hello guys, if you are learning to code and programming, or preparing for a programming job interview and looking for some practice material then you have come to the right place. Earlier, I have shared the best string, array, linked list, and binary tree coding problems and In this article, I am going to share some of the most common Java coding and programming problems for beginners. These are the problems, I have solved myself to learn to program and develop a coding sense and these are the ones that keep coming on Java coding interviews. By going through these coding problems you will not only learn Java but also prepare yourself for Java interviews. 

Insertion Sort Algorithm in Java with Example

Insertion sort is another simple sorting algorithm like Bubble Sort. You may not have realized but you must have used Insertion sort in a lot of places in your life. One of the best examples of Insertion sort in the real-world is, how you sort your hand in playing cards. You pick one card from the deck, you assume it's sorted, and then we insert subsequent cards in their proper position. For example, if your first card is Jack, and the next card is Queen then you put the queen after Jack. Now if the next card is King, we put it after the queen, and if we get 9, we put it before jack.

Top 5 Next.js and React.js Framework Courses to learn in 2021 - Best of Lot

If you are using JavaScript and React or follow web development news then you may know about Next.js, a popular React framework that helps in server-side rendering which improves the user experience of page load ties. Using Server-side rendering also gives you an edge on SEO with a more easily indexable and crawlable website out of the box. Next.js is touted as the next big thing in the web development world and 2021 may be a good time to learn Next.js. If you want to learn Next.js and looking for some excellent resources like books, tutorials, courses, and guides then you have come to the right place. In the past, I have shared the free React courses and books for beginners and In this article, I am going to share some of the best online training courses to learn Next.js from scratch.

10 Examples of an Array in Java

Along with the String, the array is the most used data structure in Java. In fact, String is also backed by a character array in Java and other programming languages. It's very important for a Java programmer to have good knowledge of array and how to do common things with array e.g. initialization, searching, sorting, printing array in a meaningful way, comparing array, converting an array to String or ArrayList, and doing some advanced slicing and dicing operation with an array in Java. Like my previous tutorials 10 examples of HashMap in Java, I'll show you some practical examples of an array in Java. If you think, any important operation is not included, you can suggest their examples and I'll add them to this list.

Difference between VARCHAR and NVARCHAR in SQL Server

Hello guys, if you are confused between VARCHAR and NVARCHAR data types of SQL Server and wondering what is the difference between VARCHAR and NVARCHAR, or you have been asked this question on technical Interviews and you couldn't answer then you have come to the right place. There is a subtle difference between these two character data types in SQL Server, while both supports variable length, the VARCHAR data type is used to store non-Unicode characters while NVARCHAR is used to store Unicode characters. It also takes more space than VARCHAR. 

Spring HelloWorld Example in Java using Annotation and Autowiring

Spring framework has gone a couple of releases since I last share the Spring hello world example with XML configuration. In this article, I am going to explain to you how to create a Spring hello world example with Spring 4.2 release and by using Annotation for dependency injection and autowiring. So no more XML files to specify bean dependencies. It's a simple program that shows how you can use the Spring framework to create Services that are loosely coupled. The example will show you the basic concept of dependency injection by creating a simple Java application that greets the user.

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

Hello guys, welcome to another post with another array-based coding problem. In the last article, we've learned about finding missing numbers in the array with duplicates, and today we'll solve the problem of rotating an array by left or right by a given number. For example, suppose an integer array {1, 2, 3} is given and it was asked to rate this array to the left by 3 then the result array will look like {2, 3, 1} because it was rotated twice on left. Similarly, if you are asked to rotate the same array twice by right then you'll get {1, 2, 3}, the same array is back. 

How to implement Merge Sort Algorithm in Java - Example Tutorial

The merge sort algorithm is a divide and conquers algorithm. In the divide and conquer paradigm, a problem is broken into smaller problems where each small problem still retains all the properties of the larger problem -- except its size. To solve the original problem, each piece is solved individually; then the pieces are merged back together. For example, imagine you have to sort an array of 200 elements using the bubble sort algorithm. Since selection sort takes O(n^2) time, it would take about 40,000-time units to sort the array. Now imagine splitting the array into ten equal pieces and sorting each piece individually still using selection sort. Now it would take 400-time units to sort each piece; for a grand total of 10*400 = 4000.

What is Variable and Method Hiding in Java - Example Tutorial

If Java, if you are not careful you can possibly hide both methods and variables of the superclass. Now you must be wondering what does it mean by hiding a variable or method in Java? A field or variable is said to hide all fields with the same name in superclasses. Similarly, a static method with the same name in a subclass can hide the method of the superclass. This can lead to subtle bugs, especially if you are expecting a different method to be called. In this article, I'll show you examples of both variables and methods hiding in Java so that you can understand and avoid them in the future.

How to implement Comparator and Comparable in Java with Lambda Expression & method reference? Example

Hello guys, After Java 8 it has become a lot easier to work with Comparator and Comparable classes in Java. You can implement a Comparator using lambda expression because it is a SAM type interface. It has just one abstract method compare() which means you can pass a lambda expression where a Comparator is expected. Many Java programmers often ask me, what is the best way to learn lambda expression of Java 8?  And, my answer is, of course by using it on your day to the day programming task. Since implementing equals(), hashcode(), compareTo(), and compare() methods are some of the most common tasks of a Java developer, it makes sense to learn how to use the lambda expression to implement Comparable and Comparator in Java.

Difference between List <?> and List<Object> in Java Generics - Example

There is No doubt that Generics is one of the most confusing topics in Java, and you can easily forget concepts and rules, especially if you don't code Java every day. For example, both List<?> and List<Object> looks similar there is a subtle difference between them, the List<?> is basically a list of any type, you can assign a list of String like List<String> or list of Integer i.e. List<Integer> to it. You see the point; it uses the unbounded wildcard <?>, which means any type. It provides it the much needed Polymorphism requires while writing Generic methods. 

3 ways to convert String to JSON object in Java? Examples

It's very common nowadays to receive JSON String from a Java web service instead of XML, but unfortunately, JDK doesn't yet support conversion between JSON String to JSON object. Keeping JSON as String always is not a good option because you cannot operate on it easily, you need to convert it into a JSON object before you do anything else e.g. retrieve any field or set different values. Fortunately, there are many open-source libraries which allows you to create JSON object from JSON formatted String e.g. Gson from Google, Jackson, and json-simple. In this tutorial, you will learn how to use these 3 main libraries to do this conversion with step-by-step examples.

Java - Difference between getClass() and instanceof in equals() method?

You might have seen both getClass(), and instanceof operator in Java can be used in the equals() method to verify the type of the object you are checking for equality. Do you know what the difference is between using getClass() vs instanceof operator in Java? What would be the consequence of using one over the other in the equals() method? This is one of the tricky Java interview questions, which some of you might have encountered. There is a very subtle difference between getClass() and instanceof operator, which can cause potential issues with respect to the equals() method. 

Top 5 Free Amazon Web Services or AWS Courses to Learn in 2021- Best of Lot

Hello guys, if you are thinking about learning cloud technologies or cloud computing, and looking at the various cloud providers like AWS, GCP, or Azure, then you are going in the right direction. The future lies with Cloud, and it's essential for every developer to learn about cloud computing solutions. When we talk about Cloud, the first thing that comes to mind is AWS, the biggest Cloud Computing platform, and that's why I suggest a lot of developers learn it. If you want to learn Amazon Web Services, popularly known as AWS, and looking for some excellent resources like books, courses, and tutorials, then you have come to the right place.

How to Read or Parse CSV files with Header in Java using Jackson - Example Tutorial

Hello guys, today I am going to show you how to read a CSV file in Java with a simple example of Jackson API. For a long time, I only knew that Jackson can be used to parse JSON but later realized that you can also use it to parse or read CSV files in Java. The Jackson DataFormat CSV library allows you to read a CSV file in just a couple of lines and it's really powerful and feature-rich. For example, you can read a CSV file with a header or without a header. You can even read a tab-delimited text file like CSV. It's also highly configurable and allows you to define a columns separator to read a text file with any delimiter. You can even use it to directly convert the CSV data into Java objects, just like we do while reading JSON String in Java.

Java 8 StringJoiner Example - How to join multiple Strings with delimiter in Java?

While everyone was looking at the lambda expression and Stream API, JDK quietly sneaked some of the exciting methods on its API. There are a lot of hidden gems on JDK 8 and I have uncovered many of them already in this blog and today we'll talk about one of such gems which you can use in your day-to-day programming activities like joining much String together. The Java 8 has added a new class called StringJoiner to join Strings. The java.util.StringJoiner can be used to join any number of arbitrary String, a list of String, or an array of String in Java. You can choose any delimiter to join String like comma, pipe, colon, or semi-colon. This class also allows you to specify a prefix and suffix while joining two or more String in Java.

Top 5 Free Google Cloud Platform Courses for Beginners in 2021 - Best of Lot

Hello guys,  If you also want to learn Google Cloud Platform in 2021 and are looking for some free online Google Cloud training courses and materials to start your GCP journey, you have come to the right place. Earlier, I have shared the free Google Cloud Developer certification courses. Today, I will share free online courses from Udemy and Coursera, which you can learn from the Google Cloud Platform. If you don't know, Google Cloud Platform is the massive Cloud platform for Google, one of the three biggest public cloud platforms along with AWS and Microsoft Azure

Top 5 Spring Security Online Training Courses for Java Developers in 2021

Security is one of the most important aspects of a modern web application, be it a Java web application, .NET, or writing using any other web technology. In the Java world, Spring Security rule the security space. It's one of the rare frameworks which provided many security features, like authentication, authorization, session management, remember me, and several other useful features out-of-the-box. Since there was no competition for Spring security and it does its job very well, it soon becomes the de-facto standard for implementing security in both Java web applications, REST APIs, and core Java applications. The rise of the Spring framework certainly helps it to cement its place as well.

Can You Run Java Program Without a Main Method? [Interview Question Answer]

Hello guys, the first thing Java programmers learn is that they need a main method to run, but when they go to any Interview or college viva and ask can run a Java program without a main method, they are surprised like hell. Well, there are actually different types of execution models available in Java; for example, Applets, which run on the browser don't have the main method. Instead, they have life-cycle methods like init(), start() and stop(), which controls their execution. Since Applet is a Java program, you can answer this question is Yes. Similarly, we have Servlet, which runs in a Servlet container, comes as bundled in a web server like Tomcat, or Jetty.

Top 10 Free Courses to learn Full Stack Development in Java Online in 2021 - Best of Lot

Hello guys, if you want to become a full-stack Java developer and are looking for free online Java Full-stack development courses to kickstart your career, you have come to the right place. Earlier, I have shared the best Java full-stack development courses, and today, I will share 10 of the free online courses you can join to become a full-stack Java developer. The long journey of becoming a full-stack Java developer is not easy. You need to know all the details, from the front end to the backend. Not only these, but you also need to know how things function in databases and connectivity.

How to Remove an Element from Array in Java with Example

There is no direct way to remove elements from an Array in Java. Though Array in Java objects, it doesn't provide any methods to add(), remove(), or search an element in Array. This is the reason Collection classes like ArrayList and HashSet are very popular. Thanks to Apache Commons Utils, You can use their ArrayUtils class to remove an element from the array more easily than by doing it yourself. One thing to remember is that Arrays are fixed size in Java, once you create an array you can not change their size, which means removing or deleting an item doesn't reduce the size of the array. This is, in fact, the main difference between Array and ArrayList in Java.

Can you make a class static in Java? Example

This is one of the tricky questions in Java because there is no straightforward. Yes and No answer here. You cannot make a top-level class static in Java, but Yes, you can make a nested class static in Java. In fact, it is even advised (see Effective Java) to prefer a nested static class in Java to normal inner classes. Now, the question comes what is a top-level class, and what is a nested class in Java? Well, you can declare multiple classes in a single Java source file. A class is said to be the top-level if it is not inside any other class, and a class that is inside another class is known as a nested class. You can create a nested class inside another top-level or another nested class in Java. This is the class that can be static in Java.

How to create a String or Integer Array in Java? Example Tutorial

There are several ways to create an array in Java, for example, you can declare the array without initializing it, or you can create and initialize the array in the same line. If you want to make an array with values, then you need to first decide which type of array you want to create? e.g., do you want a String array, which can contain String objects like "abc," "def," or do you want to create an int array that contains int values like 10, 20, etc. In Java, you can create an array of any type, including primitives like byte, int, long, and objects like String, Integer, and other user-defined objects. Let's some code to make a new array in Java.

How to remove duplicates from Collections or Stream in Java? Stream distinct() Example

Hello guys, if you wonder how to remove duplicates from Stream in Java, don't worry. You can use the Stream.distinct() method to remove duplicates from a Stream in Java 8 and beyond. The distinct() method behaves like a distinct clause of SQL, which eliminates duplicate rows from the result set. The distinct() is also a standard method, which means it will return a new Stream without duplicates, which can be used for further processing. Like other methods of Stream class, I mean, map(), flatmap(), or filter(), distinct() is also lazy, and it will not remove duplicate elements until you call a terminal method on Streams like collect or forEach.  

How to Reverse String in Java with or without StringBuffer Example

Reverse String in Java
There are many ways to reverse a given String in Java. For example, you can use rich Java API to quickly reverse the contents of any String object. Java library provides StringBuffer and StringBuilder class with the reverse() method which can be used to reverse String in Java. Since converting between String and StringBuffer or StringBuilder is very easy it's the easiest way available to reverse String in Java. But, in a coding interview, you may not be allowed to use the JDK API methods to solve this problem. That's why, writing a Java program to reverse String in Java without StringBuffer is one of the popular Java String interview questions, which requires you to reverse String by applying logic and by not using API methods.

What is double colon (::) operator in Java 8 - Example

Hello guys, if you are new to the Java 8 style of coding and wondering what is those double colon(::) in the code then you have come to the right place. In this article, I will explain to you the double colon operator and what it does in Java 8. The double colon (::) operator is known as the method reference in Java 8. Method references are expressions that have the same treatment as a lambda expression, but instead of providing a lambda body, they refer to an existing method by name. This can make your code more readable and concise.