HTML

How to get first and last element of a linked list in Java

Hello guys, in today's post I will teach you how to get the first and last element of a linked list in Java. This is a common coding problem but we will see it from different angles. In Java, you don't need to write and create your own LinkedList, there is a built-in class called java.util.LinkedIn and you can use that class whenever you need a linked list data structure. This class provides method getFirst() and getLast() to retrieve the first and last element from a linked list. In this article, I will show you how to use that method to get the first and last node from a given linked list.

Fixing ReferenceError: $ is not defined in jQuery - Solution and Tips

"ReferenceError: $ is not defined" is one of the common JavaScript error which comes when you try to use $, which is a shortcut of jQuery() function before you load the jQuery library like calling $(document).ready() function. "ReferenceError: XXX is not defined" is a standard JavaScript error, which comes when you try to access a variable or function before declaring it. Since jQuery is also a JavaScript library, you must first include the declaration of the jquery function or $() before you use it.

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.

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

Hello guys, if you are new to 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 which 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.

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, 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 List interface guarantee 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.

5 differences between an array and linked list in Java

The difference between an array and linked list is one of the frequently asked data structure and algorithm interview question 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 structure in Computer Science and Programming, and Java supports both of them.

Can you add static or private methods on Java interface?

Well, prior to Java 8, it wasn't possible to add non-abstract methods in Java but nowadays you can add non-abstract static, default, and private methods in Java interface. The static and default methods were supported as part of interface evolution in Java 8 and you can add private methods on an interface from Java 9 onwards. Since long, many Java programmers feel that there is no real use of an interface, well that's completely wrong, given how interface allows you to write generic, decoupled code, most of those sentiments come from no implementation on the interface.

Can you make a class static in Java? Interview Question

This is one of the tricky questions in Java because there is no straight forward. 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 than 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 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 String array, which can contain String objects like "abc," "def," or do you want to create an int array which contains int values like 10, 20, etc. In Java, you can create an array of any type, including both 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.

10 things about float and double data types Java developer should know

Hello guys, float and double are two fo the important data types in Java, but many developers don't pay enough attention to these two data types, resulting in writing poor code with subtle bugs. To be honest, they are not easy to use because of the complexity with floating-point calculation but knowing even simple things like the maximum, and minimum limit of float and double data types and how to compare float and double variables can go a long way in eliminating bugs which are not obvious.

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

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 you need to know how things function in databases and connectivity. This process involves a lot of detailed studies; so we have picked the courses that can help you along the way. These courses are picked after taking reviews from professionals and learners alike. These courses that we have listed are best in their respective domain to provide you in-depth and practical knowledge where ever necessary.

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

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 Free Big Data Courses to Learn Hadoop, Spark Online - Best of Lot

If you want to learn Big Data technologies in 2020 like Hadoop, Apache Spark, and Apache Kafka and you are looking for some free resources e.g. books, courses, and tutorials, then you have come to the right place. In this article, I am going to share some of the best free online courses to learn Hadoop and Spark from Udemy and Pluralsight at your own pace. I personally like to start with FREE resources before I have enough knowledge to choose the right book or enroll in a little expensive course. It's also my passion to surf the web to find great free resources and share it with you guys.

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.

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

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

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.

Java 8 - Map and Reduce Example

Hello folks, the map-reduce concept is one of the powerful concepts in computer programming, particularly on functional programming which utilizes the power of distributed and parallel processing to solve a big and heavy problem in a quick time. From Java 8 onwards, Java also got this powerful feature from the functional programming world. Many of the services provided on the internet like Google Search are based on the concept of the map and reduce. In map-reduce, a job is usually split from the input data-set into independent chunks which are processed by the map tasks in a completely parallel manner. The framework then sorts the outputs of the map operation, which are then supplied to the reduce tasks.

Top 5 Free Courses to learn Machine Learning and Deep Learning in 2020

Hello guys, if you want to learn Machine learning and Deep learning in 2020, and looking for the best online courses and tutorials then you have come to the right place. In this article, I am going to share some of the best free classes to learn Machine learning and Deep learning online. Btw, If you are thinking to learn Data Science, Machine learning, or Deep learning then you are not alone, more and more people are starting with these advanced skills around the world. Though, I have seen a lot of interest from Indian engineers in machine learning and Artificial intelligence space. They are totally caught up with the craze of developing programs that can recognize numbers, alphabets, vehicles, and several other image scanning stuff.

Top 5 Free and Best courses to learn JDBC API (Java Database Connectivity) - Best of Lot

Hello guys, If you are a Java programmer and looking for some free and best JDBC courses to start learning database access in Java, then you have come to the right place. In this article, I am going to share some of the free and paid online JDBC (Java Database Connectivity) courses from popular sites like Udemy and Pluralsight to give you a head-start in your long journey of writing real-world Java application which interacts with the database. Since Data is the utmost important part of any Java application, it's imperative to have a good knowledge of how to interact with the Database from Java application, and JDBC is the first step in that direction.

Java 8 Stream.distinct() Example - How to remove duplicates from Collections/Stream in Java

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, like map() or filter(), distinct() is also lazy, and it will not remove duplicate elements until you call a terminal method on Stream.  The actual processing of Stream pipeline starts only after calling terminal methods like collect() or forEach().

Top 5 Free Servlet, JSP, and JDBC Courses for Java Web Developers - Best of Lot

If you are a Java developer working on a Java JEE projects like a Java Web application running on Tomcat or Glassfish, or you want to get into that by learning server-side technologies like Servlet, JSP, and JDBC, then you have come to the right place. In this article, I will share some free online courses to learn Servlet, JSP, and JDBC at your own pace. If you want to become a rockstar Java web developer, then you must have a good understanding of these essential web technologies before you learn frameworks like Spring and Hibernate. These frameworks work on top of these basic technologies, and if you don't know them, then you would often struggle to debug and troubleshoot problems in the real world.

Learn Binary Tree, Binary Search Tree, Balanced Tree (AVL and Red Black Tree) in 5 Minutes

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 difference between binary search tree and a self-balanced tree-like AVL tree or Red-Black tree, they become speechless.

Post Order 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.

Top 5 Free HTML and CSS Courses to Learn Frontend Web Development in 2020- Best of Lot

HTML and CSS are two pillars of web development, they are used to create web pages you see every day. HTML provides the structure to your web page, and CSS gives them the style to look better. If you want to become a front-end web developer or web designer, then a good knowledge of HTML and CSS is a must. Even though modern-day web development is all about framework and library, like  Angular and React, you still need to know HTML and CSS to understand what's going on and troubleshoot any issue you face while developing a web application. Btw, JavaScript is another pillar of web development, but we'll not discuss this article. I have already shared some good books and courses to learn JavaScript before

Top 10 Courses to Learn Data Structure and Algorithms in Java - Free and Best

Hello guys, In the past, I have shared a lot of useful resources like books and tutorials to learn Data Structure and Algorithms for both beginners and experienced programmers. I have also shared a lot of Data Structure and Algorithmic interview questions like this and their solutions in Java. Still, I have got continuously queries about excellent online courses to learn Data Structure and Algorithms in Java. Even though the topics are completely independent with the programming language, Java developer definitely likes the online courses which teach Data Structure and Algorithms in Java, and that's why my recent post about best algorithms courses, which includes algorithms courses from JavaScript and Python didn't impress my readers.

How to combine two Map in Java? Example Tutorial

You can combine two maps in Java by using the putAll() method of java.util.Map interface. This method copies all the mappings from one Map to another, like, if you call it like first.putAll(second), then all mappings from the second Map will be copied into the first Map. This means if the first map contains 5 elements and the second map contains 10 elements or mapping, then the combined map will contain 15 or fewer mappings. In the case of duplicate keys, the value is overridden or updated from the second map.

What is difference between Heap and Stack Memory in Java JVM

One of the many traits of a good programmer is how well he understands the fundamentals and if you want to check the fundamentals of Java programmer than asking the difference between heap and stack memory is a good choice. Even though both are part of JVM and both consumer's memory allocated to the Java process, there are many differences between them like Heap memory is shared by all threads of Java application but Stack memory is local to each thread. Objects are created in heap memory but method frames are stored in Stack memory, and the size of heap space is much bigger than the small size of Stack in Java.

How to Reverse an Array in place - Java Coding Problems with 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.

3 Ways to convert java.util.Date to java.time.LocalDate in Java 8 - Example, Tutorial

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

Java 8 Stream + Map Examples - Functional Programming and Coding

The map is a well known functional programming concept that is incorporated into Java 8. Map is a function defined in java.util.stream.Streams class, which is used to transform each element of the stream by applying a function to each element. Because of this property, you can use a map() in Java 8 to transform a Collection, List, Set, or Map. For example, if you have a list of String and you want to convert all of them into upper case, how will you do this? Prior to Java 8, there is no function to do this. You had to iterate through List using a for loop or foreach loop and transform each element. In Java 8, you get the stream, which allows you to apply many functional programming operators like the map, reduce, and filter.

What is Overloading, Overriding, Hiding, Shadowing and Obscuring in Java and Object-Oriented Programming?

Hello guys, today, I am going to explain a couple of fundamental object-oriented programing concepts in Java like Overloading, Overriding, Hiding, Shadowing, and Obscuring. The first two are used in the context of a method in Java while the last three are used in the context of variables in Java. Two methods with the same name and same class but the different signature is known as overloading and the method is known as an overloaded method while a method with the same name and same signature but in parent and child class is known as overriding. On the other hand,  Hiding is related to overriding since the static and private method cannot be overridden, if you declare such methods with same name and signature in parent and child class then the method in the child class will hide the method in the parent class.

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 many of us do it in pre-Java 8 world, but JDK 8 has made it even simpler.

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.

How to code Binary Search Algorithm using Recursion in Java

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

How to copy elements of one array to another array in Java - Arrays.copyOf and Arrays.copyOfRange Example

There are multiple ways to copy elements from one array in Java like you can manually copy elements by using a loop, create a clone of the array, use Arrays.copyOf() method or System.arrayCopy() to start copying elements from one array to another in Java. Even though both allow you to copy elements from source to destination array, the Arrays.copyOf() is much easier to use as it takes the just original array and the length of the new array. But, this means you cannot copy subarray using this method because you are not specifying to and from an index, but don't worry there is another method in the java.util.Arrays class to copy elements from one index to other in Java, the Arrays.copyOfRange() method. Both methods are overloaded to copy different types of array.

7 Examples to Sort An Array in Java

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 it's inner working.  This method sorts given array into ascending order, which is the numeric order for primitives and defined by compareTo() or compare() method for objects.