HTML

How to swap two Integers without using temporary variable in Java?

One of the oldest trick questions from a programming interview is, How do you swap two integers without using temp variable? This was first asked to me on a C/C++ interview and then several times on various Java interviews. The beauty of this question lies both on the trick to thinking about how you can swap two numbers without the third variable, but also problems associated with each approach. If a programmer can think about integer overflow and consider that in its solution then it creates a very good impression in the eye of interviewers.

String Rotation in Java - How to check if strings are rotations of each other or not

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 trailing character 3 times.

How to do Inter process communication in Java? Example Tutorial

Hello guys, in the past, I have shown you how to do inter-thread communication in Java using wait-notify, and today, I will teach you how to do inter-process communication in Java. There are many ways to do inter-process communication Java, you can use Sockets, both TCP and UDP, you can use RMI, you can use web services, or you can use the memory-mapped file. The socket is the most common way of achieving inter-process communication if two processes are in two different hosts and connected via a network. RMI and WebService can also be used for similar purposes, but the last one, inter-process communication using memory-mapped files, is particularly useful if you are communicating with other processes in the same host, sharing the same memory and file system.

Top 40 Perl Programming and Scripting Interview Questions and Answers for Programmers

Hello guys, if you have been working as a professional Software developer then you may have heard about Perl, one of the most powerful scripting languages. Perl is really great when it comes to creating reports, write scripts to analyze text, and connect to DB, load data and generate reports. Perl is even more important for support professionals, business analysts, and IT professionals who need to work in the field of operations. That's why Perl questions are quite common during Software developer and IT support interview, especially if the Job description mention Perl or you have added Perl as a skill in your resume or LinkedIn Profile.

How to Find Top Two Maximum Number from Integer array in Java

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

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 e.g. 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 giving him the option to use the library method which can make this question trivial. Now, how do you solve this problem? If you are familiar with an array data structure then it would be easy for you. Since String is backed by a character array, you can use the same in place algorithm we have used to reverse an array in place.

How to Find Missing Number in a Sorted Array in Java

Today's coding problem is not very new, it's an age-old classic Programming interview Question. You have a sorted array containing n - 1 unique number starting from 0 to n - 1. There is only one number missing in this range and you need to find that out. I mean you need to write a Java method to find the missing number and print its value in the console. Some of you might have seen this question before, but if you have not been asked this question before, what is the first approach comes into your mind to solve this question? Since only one number is missing, many programmers come up with the approach of iterating over the array, and comparing each element with the expected one like the first element should be 0, the second element should be 1, and so on.

10 Must Read Books for Experienced Programmers and Software Engineers

Hello guys, In this article, I am going to share some good books for the experienced programmer which can help them to become an expert. Learning never stops but once you become a professional programmer and spent a couple of years doing professional programming, you need to make some effort to reach the next level i.e. to become an expert programmer. Continuously doing the same stuff and not analyzing will not make you better. This is where these books can help you.

How to deal with java.net.SocketException: Connection reset Exception in Java

Hello guys, from the past few months, I have been writing about different socket related errors on Java application, and today I am going to talk about another common socket related exception in Java -  java.net.SocketException: Connection reset Exception. There is no difference between exceptions thrown by the client and server. This is also very similar to the java.net.SocketException: Failed to read from SocketChannel: Connection reset by a peer but there is some subtle difference. The difference between connection reset and connection reset by peer is that the first means that your side reset the connection, the second means the peer did it. Nothing to do with clients and servers whatsoever

5 Ways to implement Singleton Design Pattern in Java

This article introduces the singleton design pattern and its 5 implementation variations in Java You will learn different ways to implement a singleton pattern and also understand the challenges with creating a singleton class like thread-safety issues and serialization issues.

Problem
At most one instance of a class must be created in an application.

Solution
That class (singleton) is defined including its own instance, and the constructor must be private.


3 Ways to Reverse an Array in Java - Coding Interview Question

Hello guys, today we are going to see another common coding question from interviews - how do you reverse an array in Java? This is a popular array-based coding problem and often asked programmers to check if they can code or not. Well, there are multiple ways to solve this problem. You can reverse array by writing your own function, which loops through the array and swaps elements until the array is sorted. That's actually should be your first approach to coding interviews. Later you can impress the interviewer by a couple of other tricks, which is specific to the Java development world. For example, you can reverse an array by converting an array to ArrayList and then use this code to reverse the ArrayList.

Nth Highest Salary Example in MySQL and SQL Server - LeetCode Solution

Nth Highest Salary in MySQL and SQL Server - LeetCode Solution
---------------------------------------------------------------
Write a SQL query to get the nth highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1  | 100    |
| 2  | 200    |
| 3  | 300    |
+----+--------+

For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.