HTML

Friday, February 26, 2021

Difference between wait() and join() methods in Java [Answered]

Though both wait() and join() methods are used to pause the current thread and have a lot of similarities they have different purposes. One of the most obvious differences between the wait() and join() method is that the former is declared in java.lang.Object class while join() is declared in java.lang.Thread class. This means that wait() is related to the monitor lock which is held by each instance of an object and the join method is related to the thread itself. The wait() method is used in conjunction with notify() and notifyAll() method for inter-thread communication, but join() is used in Java multi-threading to wait until one thread finishes its execution.

Thursday, February 25, 2021

Binary Tree InOrder traversal in Java without Recursion

I have been writing about different binary tree traversal algorithms and so far we have seen both pre-order and post-order algorithms to traverse a binary tree and today you'll learn about the in-order or sorted order algorithms. This is actually the second part of implementing the inorder traversal of a binary tree in Java, in the first part, I have shown you how to solve this problem using recursion and in this part, we'll implement the inorder traversal algorithm without recursion. Now, some of you might argue, why use iteration if the recursive solution is so easy to implement? Well, that's true, but the iterative solution is often regarded better as they are not prone to StackOverFlowError. Another reason why we are discussing the iterative solution here is because of technical interviews.

Tuesday, February 23, 2021

Top 12 Java Thread, Concurrency, and Multithreading Interview Questions For experienced Programmers

Java concurrency and thread interview questions answers
Multithreading is an important feature of the Java programming language, which means threads are also an important part of any Java interview. It's true and in fact, at beginners and freshers, level Thread interview questions in Java are one of the most difficult to answer. One reason for interview questions related to multithreading and concurrency being difficult is confusion around how multiple threads work together and the second is threads are genuinely a complicated topic to understand and use correctly.

Monday, February 22, 2021

Difference between CountDownLatch vs CyclicBarrier in Java Multithreading

Difference between CountDownLatch and CyclicBarrier in Java
Both CyclicBarrier and CountDownLatch are used to implement a scenario where one Thread waits for one or more Thread to complete their job before starts processing but there is one difference between CountDownLatch and CyclicBarrier in Java which separates them apart and that is, you can not reuse the same CountDownLatch instance once count reaches to zero and latch is open, on the other hand, CyclicBarrier can be reused by resetting Barrier, Once the barrier is broken.

Sunday, February 21, 2021

Wait, notify, and notifyAll Example in Java for Beginners

When should you use the wait() and notify method in Java is one of the many popular questions about the wait and notify methods from Java multithreading interview questions. One of the reasons for its popularity is that still a lot of Java programmers struggle to explain and write code using wait-notify methods.  Many Java developer only knows some facts about the wait and notify methods like that wait() and notify() are defined in the java.lang.Object class or you cannot call wait() without synchronization, which means without a synchronized block or synchronized method but doesn't really know when and how to use them.

Saturday, February 20, 2021

How to remove duplicate characters from String in Java? [Solved]

Hello all, how are you doing? It's been a long since I have shared a coding problem from the interview. The last one I discussed was about finding the Nth Fibonacci number, one of the popular dynamic programming problems. Nevermind,  today, you are going to learn about another popular coding problem.  How do you remove duplicate or repeated characters from String in Java is one of the frequently asked string based coding problems from Interviews. This problem is very similar to removing duplicate elements from an array which we have discussed in the past here after all String is a character array in Java. If you know how to solve that problem, you should be able to solve this one as well.

Wednesday, February 17, 2021

Producer Consumer Problem with Wait and Notify - Thread Example

The Producer Consumer Problem is a classical concurrency problem and in fact, it is one of the most powerful concurrency design patterns which is used in most multithreaded Java application. In the last article, I have shown you how to solve  Producer Consumer problem in Java using blocking Queue but one of my readers emailed me and requested a code example and explanation of solving the Producer-Consumer problem in Java with wait and notify method as well Since it's often asked as one of the top coding questions in Java. In this Java tutorial, I have put the code example of the wait notify version of earlier producer consumer concurrency design pattern. 

Tuesday, February 16, 2021

How to Create and Start Multiple Threads in Java? - Example

Hello guys, Multithreading is one of the biggest strengths of Java, which allows you to divide a task and execute faster by using more than one thread. In order to use multiple threads in Java, you need to first define the task which will be executed by those threads. In order to create those tasks, you can either use the Runnable or Callable interface. If you are just learning Java chose the Runnable interface, it's a simpler one, but if you are familiar with Java multithreading and want to leverage additional features offered by Callable like it can throw an exception and it can also return value, then go ahead and use the Callable interface. Once you have the task ready, you need to create an instance of the Thread class.

Monday, February 15, 2021

How to use PreparedStatement in Java - JDBC Example Tutorial

PreparedStatement is used to execute specific queries that are supposed to run repeatedly, for example, SELECT * from Employees WHERE EMP_ID=?. This query can be run multiple times to fetch details of different employees. If you use PreparedStatement like above then the database assists in query preparation, which is faster and more secure. Such kind of queries are compiled, and their query plans are cached at the database side to every time you execute it, you will get a faster response as opposed to using simple queries via Statement object, like SELECT * from Employees WHERE EMP_ID + emp_id.

Thursday, February 11, 2021

How to convert Date to LocalDateTime in Java 8 - Example Tutorial

The LocalDateTime class has introduced in Java 8 to represents both date and time value. It's local, so date and time are always in your local time zone. Since the java.util.Date has been widely used everywhere in many Java applications, you will often find yourself converting java.util.Date to LocalDate, LocalTime, and LocalDateTime classes of the java.time package. Earlier I have shown you how to convert Date to LocalDate and today, I am going to teach you how to convert Date to LocalDateTime in Java 8. The approach is the same. Since the equivalent class of java.util.Date in new Date and Time API in java.time.Instant, we first convert Date to Instance and then create LocalDateTime instance from that Instant using System's default timezone.

Sunday, February 7, 2021

Top 40 Core Java Interview Questions Answers from Telephonic Round [UPDATED]

Here is another post about preparing for Java Interviews, this time we will take a look at 40 core Java questions from the telephonic round of Java Programming interviews. Phone interviews are usually the first step to screen a candidate after selecting his resume. Since it's easy to call a candidate than to schedule a face-to-face interview, book rooms, and arrange for a meeting, a telephonic round of interviews is quite popular nowadays. There were days only one telephonic round of interview was enough but nowadays, it's almost two and three rounds of phone interviews with different team members before you get a chance for face-to-face interviews. 

Saturday, February 6, 2021

How to Find Large Files and Directories with Size in Linux? [find + du Example]

One of the common problems while working in Linux is to find large files to free some space. Suppose, your file system is full and you are receiving an alert to remove spaces or if your host is run out of space and your server is not starting up, the first thing you do is find the top 10 largest files and see if you can delete them. Usually, old files, large Java heap dumps are good candidates for removal and freeing up some space. If you are running Java applications like core Java-based programs or web applications running on Tomcat then you can remove those heap dump files and free some space, but the big question is how do you find those? How do you know the size of the biggest file in your file system, especially if you don't know which directory it is? We'll try to find answers to some of those questions in this article.

Thursday, February 4, 2021

Top 15 Microservices Interview Questions with Answers for Java Developers

Hello guys,  if you are preparing for Java interviews then preparing for Microservice architecture is a good decision but there are not many places where you can find Microservice interview questions, so I thought to share some common Microservices questions from Java interviews. If you are a regular reader then you may know that I have been sharing spring interview questions regularly like I shared spring boot questions last year and this year, I have shared spring cloud questions and spring data jpa questions so far. You can use those articles to prepare well for any Java and Spring boot interviews, but I also suggest spending some time learning core spring concepts as those are very important.

Wednesday, February 3, 2021

Top 10 Android Interview Questions Answers for Java Programmers

Hello guys, if you are preparing for an Android app developer interview and looking for some Android interview questions then you have come to the right place. Earlier, I have shared free Android courses for beginners, and in this article, we will explore some of the most frequently asked Android interview questions. Android is very hot nowadays as its one of the top operating systems for mobile and smartphones and a close rival to Apple's iOS. Android application developer job is in demand as well. I have also seen a couple of Java questions in an Android interview as well. It means it's better to prepare some Java questions as well. 

Tuesday, February 2, 2021

Top 10 Tricky Java interview questions and Answers

What is a tricky question? Well, tricky Java interview questions are those questions that have some surprise element on them. If you try to answer a tricky question with common sense, you will most likely fail because they require some specific knowledge. Most of the tricky Java questions come from confusing concepts like method overloading and overriding, Multi-threading which is really tricky to master character encoding, checked vs unchecked exceptions, and subtle Java programming details like Integer overflow. The most important thing to answer a tricky Java question is the attitude and analytical thinking, which helps even if you don't know the answer. 

Monday, February 1, 2021

11 JDBC Interview questions answers in Java - 2 to 4 years experienced programmer

Hello guys, if you are preparing for Java developer interviews then you may know that the JDBC Interview question forms one of the important sections in Java Interviews. Similar to multithreading, Collection framework and Garbage collection interview question, JDBC question must be prepared by any Java programmer. Most of the questions from JDBC or Java database connectivity comes from API and basic architecture of JDBC which also involves JDBC drivers. A good understanding of JDBC API along with database basics like transactions also, help to do well in JDBC interviews.