Thursday, October 31, 2019

When to use intern() method of String in Java?

The String.intern() method can be used to deal with the String duplication problem in Java. By carefully using the intern() means you can save a lot of heap memory consumed by duplicate String objects. A String object is said to be duplicate if it contains the same content as another string but occupied different memory location e.g. str1 != str2 but str1.equals(str2) is true. Since String object consumes a large amount of heap memory in average Java application, it makes sense to use the intern() method to reduce duplication and take advantage of String pool feature provided by Java. You can use intern() method to intern a String object and store them into String pool for further reuse.

Wednesday, October 30, 2019

How to use EXISTS Clause in SQL? A Real World SQL Query Example using EXISTS

Hello Guys, you might have heard about how useful the EXISTS clause is helpful in writing sophisticated queries. Still, at the same time, I have also seen that many programmers struggle to understand and use EXISTS and NOT EXISTS clause while writing SQL queries.  If you are one of them, then you have come to the right place. Today you will learn how to use the EXISTS clause in SQL by picking up a real-world example and an excellent SQL exercise from the LeetCode. Suppose that a website contains two tables, the Customers table, and the Orders table. Can you write an SQL query to find all customers who have never ordered anything?

Sunday, October 27, 2019

What is the best Book to Learn Java for C and C++ Programmer?

In the last 2 decades, many Java programmers started programming with C and C++, but the situation is changed now, you have more choices like you can choose Python, or you can even start with Java. It seems Academia prefers Python in the USA and Java in India, but there are still many programmers who know C and C++ and want to learn Java for one or other reasons. I often receive emails from my readers about book recommendation, and recently, a couple of them asked me to suggest the best Java books for C and C++ programmers. I can relate those beginners to myself because I have also gone through the same phase, but those days, the university textbooks are our only source to learn new things. We didn't have broadband, and unlimited access to the Internet and eBooks was not popular at that time, but things have changed.

Monday, October 21, 2019

Top 5 Websites to Learn Java Online for FREE - Best of lot

Begin the author of a Java blog, I often receive questions like how to improve my coding skills?,  or how do I learn to code in Java?, or I am having difficulty solving programming problems, please help, etc. This is mostly from programmers who have just started programming or a graduate with a programming degree or even some programmers with a year or two in Job. Like many other things in the world, to improve coding, you need to code, code, and code - and to develop programming, you need to write a program, and that's where many of these programmers fail. In 90% cases, they simply don't write enough programs to develop programming logic and code sense and, if without too much experience at data structures and algorithms, if they attempt problems given on sites like LeetCode, HackerEarth, TopCoder or Project Euler, they fail miserably.

Sunday, October 20, 2019

How to implement Command Design Pattern in Java with Example

Hello guys, it's been a long since I have shared a Java design pattern tutorial. I did share some courses to learn design patterns but haven't really talked about a particular design pattern in depth. So, today, we'll learn one of the important design pattern, which is often overlooked by Java developers. Yes, I am talking about the Command Pattern which can help you write flexible, loosely coupled code for implementing actions and events in your application. In simple words, the command design pattern is used to separate a request for an action from the object which actually performs the action. This decoupling between Invoker and Receiver object provides a uniform way to perform different types of actions. This decoupling is achieved using a Command object, which is usually an interface with methods like execute()

Saturday, October 19, 2019

How to Remove a Key, Value, or Entry from an HashMap in Java 8 - Example Tutorial

In the last article, I have shown how to remove key/value pairs from a map in Java based upon some conditions like remove all entries where values are greater than some values. I have told you that you must use the Iterator's remove() method for removing mapping while iteration to avoid ConcurrentModificationException, but that's not required anymore in Java 8. From JDK 8 onwards, you can selectively remove mapping without iterating over Map. The JDK 8 API has added several new methods to existing interfaces e.g. java.util.Collection, java.util.Map, Comparator etc because the interface can now contain concrete methods in form of static and default methods.

Friday, October 18, 2019

Top 5 Data Science and Machine Learning Courses to Learn Online - Best of Lot

Many programmers and Computer Science graduates are moving towards Data Science and Machine learning hoping for better pay and career opportunity and there is a reason for it. Data Scientist and Machine Learning Specialist have been ranked the number one job on Glassdoor for last a couple of years and the average salary of a data scientist is over $120,000 in the United States according to Indeed. Data Science is not only a rewarding career in terms of money but also provides the opportunity to solve some of the world's most interesting problems.  IMHO, that's the main motivation many good programmers are moving towards Data Science, Machine Learning, and Artificial Intelligence.

Difference between StringJoiner vs String.join in Java 8 with Examples

Joining multiple String literals or object into one is a common programming requirement and you will often find situations where you need to convert a list of String or a Collection of String into a CSV String for your application. For a long time, JDK API has no way to join multiple String literals or objects together, which forces programmers to write hacks like looping through all String objects and manually joining them using String concatenation to create the final, joined String. Even though this approach worked, it was filled with errors and hacks like you need to be careful not to add delimiter before the first element and after the last element, which often caused issues, particularly in case of beginners and junior Java developers.

Wednesday, October 16, 2019

What is a Functional interface in Java 8? @FunctionalInterface Annotation Examples Tutorial

The Functional interface is one of the most important concepts of Java 8 which actually powers lambda expression but many developers don't put enough effort to understand it and spend time learning lambda expression and Stream API without first understanding the role of the functional interface in Java 8. Unless you know what is a functional interface and how lambda is related to it, you can't use powerful features of Java 8 like Lambda expression and Stream API. Without knowledge of functional interface, you won't be able to understand where you can use a lambda in the code but also you will struggle to write lambda expression the method is expecting, hence, it's important to have a good understanding of functional interface in Java 8.

Tuesday, October 15, 2019

How to Convert a Lambda Expression to Method Reference in Java 8?

If you have been coding in Java 8 then you may know that using method reference in place of lambda expression makes your code more readable, hence it is advised to replace lambda expression with method reference wherever possible. But, the big question is, how do you find whether you can replace a lambda with method reference? Yes, it's not that easy, especially if you have been using Java 8 only for a couple of months and struggling to get the functional programming concepts and idioms sorted in your head. Sometimes, IDEs like IntelliJ IDEA and Eclipse does offer some hints to convert lambda expression to method reference but it does make sense to learn the logic behind it, otherwise, it won't make sense.

Monday, October 14, 2019

Top 5 Books and Courses to Crack Oracle's Java SE 11 Certification | OCAJP 11 1Z0-815 and OCPJP 11 1Z0-816, 1Z0-817

Hello guys, if you are preparing for the OCAJP 11 (1Z0-815)  or OCPJP 11 (1z0-816) exam and looking for some advice on preparation then you have come to the right place. The Java SE 11 Certification is one of the toughest of Java certification at the developer level. It's much harder than OCAJP 8, it's predecessor, and some of the programmers who have attempted it calling it even harder than the professional-level certification like OCPJP 8. In order to crack Java SE 11 certification, you need to prepare hard, but, at the same time, you also need to know which areas you should focus on. What topics should you spend more time on and which books and courses can help you to learn those essential topics?

Saturday, October 12, 2019

The OCAJP 1Z0-808 - Best Books and Mock Exams for Java 8 OCA Certification

From the last couple of months, I have been helping a few developers to prepare for Java 8 associate certification with exam code 1Z0-808, also known as OCAJP 8. From my experience, both for preparing for Sun certification and helping other developers to get Java certified, I can say that two keys to be successful in Oracle Java SE certification are choosing an excellent study guide/course and buying one or two top quality mock exam simulators. When I say success, it doesn't mean just passing the exam but scoring above 90% because passing score 65% is not very difficult to achieve and anybody can pass OCAJP 8 by just a couple of month of practice but to score 90% and above is not that easy, you need to prepare and prepare hard.

Wednesday, October 9, 2019

How to implement Binary Search in Java without Recursion - Iterative algorithm

This week’s task is to implement a binary search in Java, you need to write both iterative and recursive binary search algorithm. In computer science, a binary search or half-interval search is a divide and conquer algorithm which locates the position of an item in a sorted array. Binary search works by comparing an input value to the middle element of the array. The comparison determines whether the element equals the input, less than the input or greater. When the element being compared to equals the input the search stops and typically returns the position of the element. If the element is not equal to the input then a comparison is made to determine whether the input is less than or greater than the element.

5 Free Data Structure and Algorithms Books in Java Programming

In the last article, I have shared some of the best data structure and algorithms books for programmers, but those were not free. After that article, I received some feedback about how about sharing free data structure and algorithm books? Fair enough, everybody loves free eBooks, courses and PDFs, don't you? In the past, I have shared a list of free Java programming books, so I had some idea. I did some more research on the internet and checked my collection as well. Fortunately, there are a couple of good Data Structure and Algorithm books which are available for free as a PDF download or for online reading, which is what I am going to share with you all today.

Tuesday, October 8, 2019

How to find the 3rd (kth) Node from end or tail in a linked list in Java

Hello guys, the problem to find the 3rd element from the end in a singly linked list or Kth node from the tail is one of the tricky but frequently asked linked list problems in Programming job interviews. I know you can easily solve this problem by moving from tail to head or in the reverse direction but the main challenge here is to solve the problem in just one pass. That means, you can not traverse the linked list again and you cannot traverse backward because it's a singly linked list. So what do you think? Isn't this problem challenging? Well, I did struggle when I saw this problem very first time but once you understand the logic and some tricks to solve a linked list based problem like Recursion then it would be easy for you, and that's what you will learn in this article.

Monday, October 7, 2019

Top 20 String Algorithm Questions from Coding Interviews

In this article, we are going to see top 20 String based coding interview question and their solution to help programmers better prepare for interviews. The string is one of the most important data structure and available in almost every programming language like Java, C, C++, Python, Perl, and Ruby. Though there implement differ the essence remains same like String is NULL terminated character array in C but String is an object in Java, again backed by character array. The string is also available on weekly typed languages like Python and Perl.  This is why you will always find some String based coding question on programming interview.

Sunday, October 6, 2019

2 Ways to Check if a String is Rotation of Other in Java - Algorithms

Write a program to check if one String is a rotation of another String is a common coding problem you will find on programming job interviews.  A String is said to be a rotation of another String, if it has the same length, contains the same characters, and they were rotated around one of the characters. For example,  String"bcda" is a rotation of "abcd" but "bdca" is not a rotation of String "abcd". One of the simplest solutions to this interesting problem is first to check if two String has the same length, if not then one String cannot be the rotation of another. If they are of the same length then just create another String by concatenating first String with itself, now check if second String is a substring of this concatenated String or not, if yes, the second String is a rotation of first.

Friday, October 4, 2019

Top 5 Books to learn REST and RESTful WebServices for Java Programmers

The REST framework has now become the standard way to develop Web Services on the Internet. It's no more SOAP, who used to rule the world for the last two decades. The SOAP and XML went very well together in the past decade but it seems now REST and JSON have overtaken then and doing even better, thanks to the rise of JavaScript for both frontend and backend development. Since Java is also one of the most popular languages to develop backend services, there is a lot of demand for Java developers who know web services and can implement and expose existing SOAP-based services into REST style, light-weight web services.

Tuesday, October 1, 2019

How to use filter + map + collect + Stream in Java? Example Tutorial

Hello guys, many of my readers emailed me to write a post about the map and filter function of Java 8 because they found it difficult to understand and use. Even though I have previously blogged about both map() and filter(), I am writing this post again to explain the concept in more layman's language for a better understanding of my readers and fellow Java developers. The map() function is a method in Stream class which represents a functional programming concept. In simple words, the map() is used to transform one object into another by applying a function.