Tuesday, May 31, 2022

How to use Queue Interface in Java? Example Tutorial

The JDK provides an implementation of several data structures in the Java collection framework like ArrayList is a dynamic array, LinkedList represents a linked list, HashMap represents a hash table data structure, and Queue interface represent queue data structure. Btw, If you are not familiar with data structure itself, then you can also see Introduction to Data Structures & Algorithms in Java, an excellent course to start with the essential data structure in Java. The Queue data structure allows you to process elements in the first in first out order, and that's why it is also known as a FIFO data structure. 

How to Convert Date to LocalDate in Java 8 - Example Tutorial

Hello guys, if you want to learn how to convert old Date to new LocalDate in Java 8 then you have come to the right place. Earlier, I have shared 10 examples of LocalDate in Java 8, and in this article, I am going to teach you how to convert Date to LocalDate in Java. you may know that JDK 8 introduced the new Date and Time API, which has got a new set of shiny date classes like LocalDate, LocalTime, etc, but you still have a lot of code written against java.util.Date? In order to work with that code, you should know how to convert java.util.Date to java.util.LocalDate in Java. 

Monday, May 30, 2022

How to Search an Element in Java Array with Example? ArrayUtils Tutorial

find an index of the object in Array
While programming in Java, many times we need to check if a String array contains a particular String or an integer array contains a number or not. Though array is an object in Java but it does not provide any convenient method to perform searching elements or finding elements. Sometimes you even need an index of an item stored in Array, unfortunately, Java API does not provide any direct method. Thanks to Open Source Apache Commons provides a utility class called ArrayUtils which allows you to check for an Item in Array, find its index in the array, find its lastIndex in Array and perform several other common operations. 

[Solved] How to Find Repeated Characters in a given String with count in Java? Example

This is another interesting coding problem or programming exercise for beginner programmers. How do you find repeated or duplicate characters in a given String and their count? You can solve this coding problem in any programming language of your choice like Java, Python, Ruby, or even JavaScript. I'll explain the logic and solution which is easy to implement in the above programming languages and I'll provide code in Java, which is my favorite programming language.  In order to solve this problem, You need to first check if a String contains any duplicate characters or not, and then if it contains any duplicate letters then find out how many times they appear in the given input String.

Sunday, May 29, 2022

[Solved] How to solve a coin change problem in Java? Example

The coin change problem is one of the popular coding interview question and knowing how to solve this problem can help you during coding interview. It's also useful to learn a couple of tricks and data structure. This problem somewhat has to do with arrays, so we shall be discussing what an array is, But before we dive into this. we need to understand the problem. We are about to solve a coin problem by determining how many possible ways an amount can be paid. Suppose, Mary is a Businesswoman who deals with coin change. 

Saturday, May 28, 2022

How to print a Right Triangle Pattern in Java - Example Tutorial

Hello Java Programmers, here we are back again with a pattern based exercise. In the past, I have shared article on how to print pyramid pattern of stars in JavaLeft Triangle Star Pattern, and Pyramid pattern of alphabets, and in this article, I will show you how to print a right triangle start pattern in Java.  Pattern based exercises are great way to learn programming and coding as it encourage you to use logic and use essential programming constructs like loop and arrays. 

Friday, May 27, 2022

10 Linux Books Every Programmer Should Read

Computer and Technology related books get outdated so fast. You might be better off getting a Linux magazine subscription. The fact that the basics rarely change would also help keep the texts relevant.


1) Understanding the Linux Kernel (Bovet & Cesati), 3rd Edition
This book talks about very specific data structures and OS algorithm implementations at they pertain to the 2.4 Linux kernel. Not sure what you are getting at. 3rd edition is 2006 ;)

2) Linux kernel development

3) Linux in a Nutshell - 1997

Linux, In a Nutshell, is great, see about getting more of the O'Reilly books if you want good reference books.

4) Linux Bible Paperback 8th Edition
by Christopher Negus (Author), Christine Bresnahan  (Contributor)

5) UNIX and Linux System Administration Handbook (4th Edition) Paperback – July 24, 2010
UNIX and Linux System Administration Handbook is an absolute must-have for any sysadmin or Linux systems engineer.

6) RHCSA/ RHCE Red Hat Linux Certification: Exams (Ex200 & Ex300) (Certification Press) Paperback – June 17, 2011
by Michael Jang (Author)

7) The Linux Programming Interface

The Linux Programming Interface: A Linux and UNIX System Programming Handbook (Michael Kerrisk) I've found The Linux Programming Interface to be one of the best in-depth books I've ever tried to read on Linux. Only issues with it are it's not too hands-on, so it's a bit difficult to retain, and maybe the price, bit would have to say it's still totally worth it. 

The only problem is its size, 1500+ pages might look intimidating, so use it on a need basis, more like a reference book. Instead of focusing on size, focus on what looks interesting, as this isn't the kind of book you read back-to-back and it's more helpful in using to figure out what you don't know you don't know.

8) Unix Shell Programming (3rd Edition), by Stephen Kochan (old bell labs employee)

9) The Linux Command-Line.
Have a look at The Linux Command-Line. The book focuses on novice users and the extended version is free for download.

10) Bash Guide, which I used to read
Books on bash would be useful as well since bash plays an important role in Linux.

That's all about some of the best book to learn Linux and Shell Programming.

Thursday, May 26, 2022

[Solved] How to convert Decimal to Binary Number in Java? Example Tutorial

Hello guys, how are you doing? I have been sharing a lot of programming interview questions and coding problems for practice in this blog. Earlier, I have shared 21 String programing questions, 100+ data structure questions, and 20 System design questions and this week's programming exercise is to write a program to convert a decimal number to binary in Java. It's a simple exercise for beginners who have just started learning the Java programming language. Decimal numbers are base 10 numbers, which means there are exactly 10 digits to represent a number, starting from 0 to 9, on the other hand, the binary number system has just two digits 0 and 1, which is known as bits. 

[Solved] How to find all pairs which add up to a given value in an Integer Array in Java? Example

Hello guys, if you are preparing for programming job interview then you know that the problem of finding all pairs which adds up to a given value in a give array is a popular array based coding question. This question is also known as Two sum problem because you need to find pair of two elements in the array whose sum is equal to given number. For example, you have given an array of integers with values {1, 2, 3, 4, 5, 6} and you need to find all the pairs whose sum is equal to 5. In this case, there are two such pairs (1, 4) and (2, 3) so your program needs to print them into console. 

3 Difference between multi-threading and multitasking? [Answered]

Hello guys, what is the difference between multithreading and multitasking is a common Java interview questions. If you are also wondering what it the real difference between them as they sound similar the continue reading this article and you will find the answer. In the programming world, there are two main ways to improve the throughput of a program,  by using multi-threading and by using multitasking. Both take advantage of parallelism to efficiently utilize the immense power of the CPU and improve the throughput of your program. Actually, multi-threading is nothing but thread-based multitasking. 

Wednesday, May 25, 2022

How to convert String to Date in Java? Example Tutorial

Hello guys, if you are wondering how to convert a String to Date object in Java then you have come to the right place. Data type conversion is one of the most common tasks in programming and every Java  programmer must know how to convert one type to another type. There are many times when you will be required to convert a String to LocalDate or java.util.Date object mostly in a different format like dd-MM-yy or yyyy-MM-dd or simply yyyy MM dd. For example, clients pass dates as String to the Server or sometimes we read Date related data from CSV file. Java provides API for parsing String to date using DateFormat class, though Java's Date and Time API is severely criticized, it is also the most used Date and Time format solution. 

What is difference between start and run method of Thread in Java? Answer

Hello guys, what is the difference between calling start() vs run() method in Java multithreading is a popular core Java interview questions and if you are wondering the subtle difference between two then you have come to the right place. In this article, I will answer this question and show you an example as well. If you remember, a Thread is started in Java by calling the start() method of java.lang.Thread class, but if you learn more you will find out that the start() method internally calls the run() method of the Runnable interface to execute the code specified in the run() method in a separate thread. 

Monday, May 23, 2022

Top 10 Tough Core Java Interview Questions Answers for Programmers

tough core Java interviews questions and answers
What is a tough core java interview question? Why do people look for tough Java questions before going for an interview? well, I don't think I need to answer these tough questions because it's pretty natural to prepare for tough questions even if you are not expecting tough questions from core Java. If you are prepared for the tough and tricky Java interview question then you feel more confident and answer other Java interview questions with confidence. 

Difference between Self and Equi Join in SQL - INNER Join example MySQL

The main difference between Self Join and Equi Join is that In Self Join we join one table to itself rather than joining two tables. Both Self Join and Equi Join are types of INNER Join in SQL, but there is a subtle difference between the two. Any INNER Join with equal as join predicate is known as Equi Join. SQL Joins are the fundamental concept of SQL similar to correlated and noncorrelated subqueries or using group by clause and a good understanding of various types of SQL join is a must for any programmer.

Saturday, May 21, 2022

2 Ways to solve FizzBuzz in Java? [Example]

Hello guys, if you are learning to code or preparing for interviews and looking how to solve the FizzBuzz problem in Java then you have come to the right place. Earlier, I have shared 75 programming exercises and in this article, I will teach you how to solve the FizzBuzz problem in Java. FizzBuzz is one of the most frequently asked questions on programming interviews and used to filter candidates on Coding interviews who can't code. It looks extremely simple but it's tricky for those programmers or coders who struggle to structure their code or lack the ability to convert a simple algorithm into code. 

Wednesday, May 18, 2022

How to Find Highest Repeating Word from a File in Java [Word Count Solution]

Hello guys, if you are looking for a Java program to print the word and their count from a given file then you have come to the right place. Earlier, I have shared 100+ Data Strucutre and Algorithms Problems from interviews and in this article, I will show you how to find worlds and their count from a given file in Java. How to find the word and their count from a text file is another frequently asked coding question from Java interviews. The logic to solve this problem is similar to what we have seen in how to find duplicate words in a String, where we iterate through string and store word and their count on a hash table and increment them whenever we encounter the same word. 

How to Check if Given Number is Prime in Java - With Example

Hello guys, today, we are going to discuss one of the most common programming exercises for beginners is, write a program to check if a given number is prime or not? There are many ways to check if a number is prime or not, but the most common of them is the trial division, which is what we will see in this tutorial. In my opinion, these kinds of programs are their first steps towards algorithmic understanding. You first come up with a solution, which is driven by the fact that prime numbers are natural numbers, that are not divisible by any positive number other than 1 and themselves. Then, you write a for loop to check every number, starting from 1 to a given number, to see if the given number is divisible by any positive number or not. This leads you to the solution.

Monday, May 16, 2022

[Solved] How to Find 2 Largest Number from Integer Array in Java with Example

Hello guys, I have been sharing a lot of Programming interview questions and coding problems to learn programming better which is appreciated by you guys. In this post, I have come with other simple programming problems for Java beginners. I love to share short programming problems because they help in developing programming sense. Many people will argue against simple problems like prime numbers, palindrome, and factorial, but I really find them useful, especially for beginners. A beginner is far away to solve a complex data structure problem or even more complex problems like those that appear in TopCoder or other programming sites. Programmers learn gradually and they need the joy of doing something and seeing results much quicker than any other. Small success motivates them.

Sunday, May 15, 2022

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

Saturday, May 14, 2022

[Solved] How to Check If a Given String has No Duplicate Characters in Java? Unique Example

Hello guys, if you are looking to solve the classic problem "checking if a String has all Unique characters" or not then you have come to the right place. Earlier, I have shown you how to reverse String in place, and in this article, I will show you how to check for unique and duplicate characters in String.  You need to write a program to determine if a given string has all unique characters or not. For example input= "Java" then your function should return false because all characters are not unique, and if the input is "Python" then your program should return true because all characters in Python are unique.

How to Find Greatest Common Divisor of two numbers in Java - [ Euclid's algorithm GCD Example]

How to find the Greatest Common Divisor of two numbers in Java
Simple Java program to find GCD (Greatest Common Divisor) or GCF  (Greatest Common Factor) or HCF (Highest common factor). The GCD of two numbers is the largest positive integer that divides both the numbers fully i.e. without any remainder. There are multiple methods to find GCD, GDF, or HCF of two numbers but  Euclid's algorithm is very popular and easy to understand, of course, only if you understand how recursion works. Euclid's algorithm is an efficient way to find the GCD of two numbers and it's pretty easy to implement using recursion in the Java program. According to Euclid's method GCD of two numbers, a, b is equal to GCD(b, a mod b) and GCD(a, 0) = a.

Thursday, May 12, 2022

How to Convert a Stream to List, Set, and Map in Java? Example Tutorial

Hello guys, if you are wondering how to convert a Java Stream to Java Collections like List, Set and Map then you have come to the right place. Earlier, I have shared free Java Courses for beginners and in this article, I am going to share examples to convert Stream to ArrayList, LinkedList, HashSet, TreeSet, LinkedHashSet, TreeMap, HashMap, and ConcurrentHashMap in Java. These are easy-to-follow examples and suitable for both beginners and experienced Java programmers.  In Java 8, Stream is one of the most important classes as it allows a lot of useful functional operations like filter, map, flatmap, etc on a collection of objects. Hence, going forward converting a Collection to Stream, performing operations, and then converting the result back to different Collection classes like List, Set, and Map will be a common task. 

How to solve Two Sum Array Problem in Java? Example

Hello guys, if you have been solving data structure and algorithms problems or been through a couple of coding interviews then you might be familiar with the classical "Two Sum" problem. It's one of the classical coding problems of finding two numbers in a given array whose sum is equal to a given target number. It's a good problem to learn how array data structure works and programming basics like loops, conditionals, and operators. It's also good for developing your problem-solving skills and coding sense, which will help you in the long run. This is also a popular Leetcode problem and is commonly asked in coding interviews to both beginners and intermediate programmers.

Wednesday, May 11, 2022

How to calculate sum of all numbers in a given array in Java [Example]

Hello guys, if you are thinking about how to calculate the sum of all numbers in a given integer array then you have come to the right place. Earlier, I have shared 75 programming questions from the interview and in today's coding problem, you will learn how to write a program to calculate the sum of array elements in Java. As part of this coding problem, you need to write a method that will accept an integer array and it should return the total sum of all the elements. The array could contain both positive and negative numbers but only decimal numbers are allowed. 

[Solved] 2 Ways to Find Duplicate Elements in a given Array in Java - Example

Hello guys, today, you will learn how to solve another popular coding problem. You have given an array of objects, which could be an array of integers and or an array of Strings or any object which implements the Comparable interface. How would you find duplicate elements from an array? Can you solve this problem in O(n) complexity? This is actually one of the frequently asked coding questions from Java interviews. There are multiple ways to solve this problem, and you will learn two popular ways here, first the brute force way, which involves comparing each element with every other element, and other which uses a hash table-like data structure to reduce the time complexity of the problem from quadratic to linear, of course by trading off some space complexity.

Tuesday, May 10, 2022

Top 5 Practice Tests for Google Cloud Professional Cloud Architect Certification Exam

If you are looking for any exam courses to values your skills in the Google Cloud Professional Cloud Architect certification then you are in the right place. Clicking on this article link shows that you are very curious to study more about Google Cloud Professional Cloud Architect certification and as well as taking and succeed in the exam to get your Google Cloud Professional Cloud Architect certification.

Sunday, May 8, 2022

[Solved] How to reverse a String in place in Java? Example

One of the common Java coding interview questions is to write a program to reverse a String in place in Java, without using additional memory. You cannot use any library classes or methods like StringBuilder to solve this problem. This restriction is placed because StringBuilder and StringBuffer class define a reverse() method which can easily reverse the given String. Since the main objective of this question is to test the programming skill and coding logic of the candidate, there is no point in giving him the option to use the library method which can make this question trivial. 

How to check if Array contains given Number or String in Java [ Linear Search vs Binary Search]

Hello guys, one of the common coding questions from Java interviews is how to test if an Array contains a certain value or not? This is a simple question, but sometimes interview pressure makes candidates nervous. In this article, you'll learn how to solve this problem using different approaches. Since an array in Java doesn't have any inbuilt method for searching values, interviewers prefer to ask this question, to see how a candidate deals with such a situation. If you have good knowledge of Java API, then you will immediately come to know that there are alternatives available like using the binarySearch() method of Java Java .util.Arrays class or taking advantage of ArrayList contains method by first converting your array to ArrayList.

How to send HTTP Request from a Java Program - Example Tutorial

If you are thinking is it possible to send an HTTP request from a Java program and if yes, how to send a simple HTTP GET request in Java, then you have come to the right place. In this article, I'll show you how you can use the HttpURLConnection class from the java.net package to send a simple HTTP request in Java. But, first, let me answer your first question, is it possible to send an HTTP request in Java? Yes, it's possible and you can send any kind of HTTP request like GET, POST, PUT, DELETE, HEAD, or PATCH. The java.net package provides a class called HttpURLConnection, which can be used to send any kind of HTTP or HTTPS request from Java program.

Saturday, May 7, 2022

Difference between static initializer block vs instance initializers in Java? Example

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 validate phone numbers in Java? Google libphonenumber library Example Tutorial

Hello guys, if you are wondering how to validate if a given number or string is a valid phone number in a Java application then you are not alone. It's a common requirement to validate phone numbers for a Java web application, much like validating email addresses. Unfortunately, Java doesn't provide any built-in method to carry out this kind of common validation, I would love to have a validation package in Java, but don't worry there must be an open-source library to cover this deficiency, right? Yes, there is Google's phone number library which allows you to validate any phone number both international, USA specific, or any country-specific.

How to convert String to int or Integer data type in Java? Example Tutorial

Hello guys, if you are wondering how to convert a String variable to int or Integer variable in Java then you have come to the right place. Earlier, I have showed how to convert Integer to String in Java and today, you will learn about how to convert String to int or Integer variable in Java. There are 3 main ways to convert String to int in Java, first, by using the constructor of Integer class, second, by using parseInt() method of java.lang.Integer, and third, by using Integer.valueOf() method. Though all those methods return an instance of java.lang.Integer, which is a wrapper class for primitive int value, it's easy to convert Integer to int in Java. 

3 ways to Convert Integer to String in Java [Example]

Hello guys, this is the second part of the String to Integer data type conversion tutorial in Java, in the first part you have learned how to convert String to Integer, and in this article, you will learn the opposite i.e. convert from Integer to String. Actually, you can apply all the tricks, which I had told you before about converting long to String, and autoboxing will take care of converting int to Integer in Java. But, if you care for performance and believe in not using auto-boxing when not needed then there are still a couple of ways that directly converts an Integer object to a String like the Integer.toString() method, which returns a String object and doesn't have any auto-boxing overhead. Let's see a couple of more ways to convert an Integer to a String in Java.

Difference between private and final class, method, and variables in Java?

Hello guys, one of the common questions among Java beginners is what is the difference between a private and final keyword in Java? The confusion arises because they are very similar and used in a similar context. For example, you can make a class, a method, and variable final as well as private. Both put some kind of restriction like you cannot override a final method in Java and the private method is not even accessible outside the class, so obviously you cannot override it. 

What is InstanceOf keyword in Java [Example Tutorial]

The Java programming language and JVM are full of hidden gems and even though I am using Java for more than a decade I still get surprised by features that I didn't know for quite some time like shutdown hook, covariant method overriding, and JVM option to refresh DNS cache.  The instanceof operator is also one of the rarely known features of Java, It is used to check if an object is the instance of a particular class or not. It returns true if the object is an instance of the class, otherwise, returns false. You might have seen usages of the instanceof keyword in Java while overriding the equals() method. Since for checking equality of two instances, the first step is to verify whether they are the instance of the same object or not, you can use the instanceof operator there.

Difference between trustStore vs keyStore in Java SSL

If you are confused between truststore and keystore and looking to find what exactly they mean then you have come to the right place. Earlier, I have shared free Java courses and today, I am going to tell you the difference between trustStore and keyStore in Java. Both trustStore and keyStore are important but confusing concepts and constantly tormented Java developers when they connect to servers using SSL. The main difference between trustStore vs keyStore is that trustStore (as the name suggest) is used to store certificates from trusted Certificate authorities(CA) which are used to verify certificate presented by Server in SSL Connection while keyStore is used to store the private key and own identity certificate which program should present to other parties (Server or client) to verify its identity.

Friday, May 6, 2022

SQL Join Tutorial - How to use JOIN Multiple Tables in SQL query? MySQL Example

Hello guys, if you are wondering how to join multiple tables in SQL to produce a combine result which contains columns from all tables but not sure how to do it then you have come to the right place. SQL Join is one of the basic concepts while working in databases or tables but yet less understood and most confusing topic for beginners and even intermediate developers. I compare Joins in SQL with Recursion in programming in terms of confusion because I have found that these two topics are special in their nature and you can't get it right with casual reading until you understand the concept and its various well. Things get worse when the table locked due to such SQL Join queries which were fired without knowing how much time it would and how big the result set could be. 

Thursday, May 5, 2022

Difference between Primary and Foreign keys in SQL [Answer]

The database is a collection of tables and a table is the collection of rows or records. A primary key is the data to uniquely identify a row in the table. For example, if an Employee table has millions of rows and emp_id is a primary key then it can uniquely identify that row. You can use this primary key to retrieve (SELECT) the row, update the row, and delete the row. In SQL, a table can have only one primary key but it can contain more than one column. There are two types of primary key, a simple primary key, and a composite primary key.

When to use TRUNCATE vs DELETE command in SQL?

While working with the database we often need to delete data, sometimes to create more space, sometimes just remove all data to make the table ready for the next day's transaction, or sometimes just selectively remove stale data. SQL provides a couple of handy commands to remove data e.g. truncate, delete and drop. The last one is a bit different because instead of removing data it just deletes the table. What is the difference between truncate and delete command in SQL or when to use truncate vs delete is one of the most frequently asked SQL interview questions?