String Rotation in Java - Write a Program 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 e.g. "programming" will become "ingprogramm" if we rotate the String on trailing character 3 times. A k-rotation on a string takes the trailing k characters of the string and attaches it to the beginning of the string in the same order. You can rotate the String either in the clock wise (right from the top) or anti-clockwise(left from the top). The string can also be rotated in one go e.g. "123456" will become "456123" if we rotate 456 to the left around character "3".

3 Spring Certification Books - Best of Lot, Must Read

Books, Study guides, and mock exams are some of the important resources to prepare for Spring certifications. In the last article, I have shared some of the best Spring certification guides for Spring Core and Spring web certifications and today I'll share some of the best books to learn Spring frameworks from the certification perspective. If you are preparing for Spring certifications then these books will help you to learn Spring better. It's also true that more and more experienced and intermediate Java developers have started preparing for Spring certifications to make themselves more marketable. In a challenging and competitive environment like today's, Spring is one the essential skills for Java developer. The Spring certifications make you valuable in the eye of employers and help you to get both job and career growth.

How to Sort Map by values in Java 8 using Lambdas and Stream - Example Tutorial

In past, I have shown you how to sort a HashMap by values in Java, but that was using traditional techniques of pre-Java 8 world. Now the time has changed and Java has evolved into a programming language which also has the power of functional programming. How can you take advantage of that fact to do your day to day task e.g. how do you sort a Map by values in Java using lambda expressions and Stream API. That's what you are going to learn in this article. It will serve two purposes, first, it will tell you a new way to sort a Map by values in Java, and, second and more important it will introduce you to essential Java 8 features like lambda expression and streams.

Top 5 Spring Certification Study Guides for Core, Web, and Enterprise Integration Exams

Ever since Pivotal has announced that Spring training is not mandatory for becoming Pivotal certified Spring developer, more and more experienced Java programmers, who have been using Spring for years are preparing for the exam. This is obvious because the expensive Spring training, which cost around 32000 USD in the USA and most of the western nations and around 50,000 INR in India was the biggest hurdle on getting Spring certified. Even though training is the best way to prepare for certification because it is totally focused on certification exam and you will cover all topics there, it is not affordable for most of the Java developers around the world. Now, the cost of Spring certification has just reduced to 200 USD from the whopping 3200 USD it cost earlier.

Can you make an abstract class/method final in Java?

No, you cannot make an abstract class or method final in Java because abstract and final are the mutual exclusive concept. An abstract class is incomplete and can only be instantiated by extending a concrete class and implementing all abstract methods, while a final class is considered as complete and cannot be extended further. This means when you make an abstract class final, it cannot be extended hence it cannot be used and that's why Java compiler throws a compile time error when you try to make an abstract class final in Java. In short, an abstract class cannot be final in Java, using both abstract and final modifier with a class is illegal in Java.

Solving org.springframework.beans.factory.BeanCreationException: Error creating bean with name X [Java Spring]

If you are using Spring framework in your Java application and getting this error during startup it means Spring is not able to initialize the bean X and add into its application context, Why? There could be multiple reasons e.g. a typo on spring bean name. Let's take a closer look at the stack trace to find out the real reason:

BeanInstantiationException: Could not instantiate bean class [X]: No default constructor found; nested exception is java.lang.NoSuchMethodException: X.()

Here X is the class, which is declared as Spring bean. The error clearly says that default constructor is not present in class X. By default, Spring will try to instantiate beans by calling the default or no-argument constructor and if it doesn't find the default, no-argument constructor then it is not able to initialize the bean and hence it throws the BeanInstantiationException during startup, the real reason is also appended into stack trace as NoSuchMethodException.

Grep Command example to List only Filenames with Matching String in Linux

The grep command from Linux is one of the powerful commands to find files containing some text, but when you use grep it not only print the file name but also the line which is containing the matching text. This is ok for most of the situations but sometimes you only want to grep to show filename and line and not the matching text e.g. when you are searching for some configuration e.g. database hostname across all configuration files in your application host. Since many files contain the database references, it's possible that you might get a lot of data on output, so if you are only interested in all the files containing matching text, you can use grep -l option. This option of grep only shows filenames which contain matching text.

How to sort an ArrayList of Objects using Comparator in Java 8 - Ascending and Descending Order

There are a lot of examples of Sorting ArrayList in Java on the internet, but most of them use either String or Integer objects to explain sorting, which is not enough, because in real world you may have to sort a list of custom objects e.g. your domain or business objects like Employee, Book, Order, Trade etc. In order to sort an ArrayList of objects, you need two things, first a class to provider ordering and a method to provide sorting. If you know about ordering and sorting in Java then you know that Comparable and Comparator class is used to provide the ordering for objects. The Comparable interface provides natural order e.g. lexicographic order of String or name for Employees, while Comparator is used to provide custom order. It gives you the flexibility to sort your objects on the parameter you want e.g. you can sort a list of Coupon objects on the percentage discount, expiry dates, or based upon the total cost.

How to Prevent Browsers from Caching Static Contents using Spring MVC Framework

One of the common requirement in a secure Java web application is to disallow back button of browser or invalid the session if the user hit the back button of the browser. You might have seen this behavior while doing online banking or net banking, almost all the banks don't allow you to use the browser's back button. Your session gets terminated as soon as you hit the back button and you have to log in again to do any transaction. Btw, Have you ever checked some situation on your Java web application like, if you pressed the back button of your browser after logging in, what happened? You will find that browser takes you to the previous page. This happens because your browser usually doesn't send another GET request to the server. Instead, it views the web page from locally cached responses. This is called browser caching/HTTP caching, it could happen not only on a login page but on any page. This behavior is actually controlled by the Cache-Control header of HTTP response.

How to Remove Entry (key/value) from HashMap while Iterating? Example Tutorial

Can you remove a key while iterating over HashMap in Java? This is one of the interesting interview questions as well as a common problem Java developer face while writing code using HashMap. Some programmer will say No, you cannot remove elements from HashMap while iterating over it. This will fail fast and throw concurrent modification exception. They are right but not completely. It's true that the iterator of HashMap is a fail-fast iterator but you can still remove elements from HashMap while iterating by using Iterator's remove() method. This is the same technique which we have used in past to remove elements while iterating over a List in Java. The key here is not to use the remove() method from Map or List interface to avoid java.util.ConcurrentModfiicationException in Java.

39 Java J2EE Support Engineer Interview Questions with Answers

I have shared many posts about Java interview question in the past but nothing, particularly for support engineer perspective. Since there are a lot of L1 and L2 support job exists in BFSI (Banking, Finance, and Insurance Industry) and they are also for the longer term, I decided to write this post. When you go for a support engineer role, especially for Java application be it to core Java or Java EE application, Interviewer expects you know basics of Java and can start/stop the application, see log files, alert developers, and other aspects of the support e.g. opening conference bridge to solve production issues, communicating to stakeholders, and involving right peoples. In this article, I will share questions to help with technical aspects e.g. the essential skills you need to clear a support engineer interview.

5 Difference 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 very popular question during practical exams on Computer Science degree courses e.g. B.E. and B.Tech. It's very simple and easy to answer but you just can't afford to miss this question on 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. One of the traits of a good programmer is extensive knowledge of data structure and algorithm and that's why it's very important for you to learn the difference between array and linked list data structure and understand when to use an array over linked list and vice-versa. Though this discussion is valid from C/C++ and other programming language perspective, I'll give you examples and explanation in Java.

Can you make a class Static in Java?

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 top level if it is not inside any other class and a class which is inside another class is known as nested class. You can create nested class inside another top level or another nested class in Java. This is the class which can be static in Java.

Counting Sort in Java - Example

The Counting sort algorithm, like Radix sort and bucket sort, is an integer based algorithm (i.e. the values of the input array are assumed to be integers). Hence counting sort is among the fastest sorting algorithms around, in theory. It is also one of the few linear sorting algorithm or O(n) sorting algorithm. It's quite common in Java interviews nowadays to ask, whether do you know any O(n) sorting algorithm or not. If you face this question in future, you can mention Radix sort, bucket sort, or counting sort algorithms.  How does counting sort algorithm works? Well, counting sort creates a bucket for each value and keep a counter in each bucket. Then each time a value is encountered in the input collection,  the appropriate counter is incremented.

99 Angular JS Interview Questions for Web Developers

The AngularJS is one of the popular JavaScript frameworks, I think most popular after jQuery, with the core goal of simplification. It allows building dynamic, single page web apps (SPAs) using JavaScript and supports the Model View Controller (MVC) programming structure. It has used widely and even big companies like Google, Virgin America, and HBO are using Angular JS to build their site. The demand for web developers is on all time high and there is a huge demand for developers who understand modern JavaScript frameworks e.g. Angular JS, jQuery, Facebook's React JS etc. The Angular JS is Open-source, front-end JavaScript framework which is developed by Google, it mainly competes with Facebook's ReactJS framework.

What is the use of DispatcherServlet in Spring MVC? Interview Question

How DispatcherServlet works internally in Spring MVC or What is the role of DispatcherServlet in Spring is some of the frequently asked Spring MVC Interview Question. You might have seen them already during your Java web development interview. In this article, I'll answer these question by explaining What is DispatcherServlet and its importance in Spring MVC. The DispatcherServlet is one of the important components of Spring MVC web framework and acts as a Front Controller. Similar to other Java web framework, Spring MVC also uses a front controller to receive all incoming request and delegates to other components for further processing e.g. Spring MVC controllers which are annotated using @Controller annotation and ViewResolvers e.g InternalResourceViewResolver class.

Difference between Correlated and Non-Correlated Subquery in SQL

The correlated subquery is one of the tricky concepts of SQL. It's similar to recursion in programming which many programmers struggle to understand, but like recursion, it also offers the unique capability to solve many SQL query based problems e.g. second highest salary problem where you need to compare one row of the table to another row. It gives you a different kind of power. The main difference between a regular, non-correlated and correlated subquery in SQL is in their working, a regular subquery just run once and return a value or a set of values which is used by outer query, but correlated subquery runs for each row returned by the outer query because the output of the whole query is based upon comparing the data returned by one row to the all other rows of the table. That's why it is also very slow and generally avoided until you don't know any other way to solve the problem.

10 Books to Prepare Technical Programming/Coding Job Interviews

If you are preparing for a technical interview on software development sector and looking for some great books to boost your preparation, you have come to the right place. In this article, I am going to share some of the best programming/coding interview books to prepare well for any software development jobs. These books are enough to crack even the toughest of the job interviews at Google, Microsoft, or Amazon. They provide excellent coverage of all essential topics for programming job interviews e.g. data structure and algorithms, system design, algorithm design, computer science fundamentals, SQL, Linux, Java, Networking etc.

10 points about lambda expressions in Java 8

The Lambda expression is one of the important features of Java 8 but if you look from a developer's point of view, it is nothing but a way to pass code to a method in Java. Technically, it's an expression where you can define parameters and then the code which uses those parameters, similar to a method in Java, but you don't need to write boilerplate code e.g. method name, return type, argument type etc. Most of those details are inferred by compiler and JVM from the context in which lambda expression is used. Some of you question, why lambda expression was introduced in the first place? Is it just the replacement of Anonymous class? Well, the lambda expression is more than that because it also introduces functional programming in Java.

Now, Java has best of both world i.e. Object oriented programming and Functional programming which means you can write even more scalable and robust, mission critical application in Java.

10 points about final modifier in Java

Here are some important details about final modifier in Java:

1) The final is a modifier in Java, which can be applied to a variable, a method or a class.

2) When a final modifier is used with a class then the class cannot be extended further. This is one way to protect your class from being subclassed and often sensitive classes are made final due to security reason. This is also one of the reasons why String and wrapper classes are final in Java.

3) When the final keyword is used with a method that it cannot be overridden in Java, which means you cannot override the logic of the method in the subclass. This is also done to protect the original logic of method.

Top 10 REST API and RESTful Web Services Book for Java Web Developers - Part 1

In recent years, REST has become the standard style for developing web services, also known as RESTful Web Services. These web services take advantage of REST principles, which leverages all goodness of HTTP to provide scalable and robust web services. As a Java web developer, it's high time that you get familiar with the REST concepts and the REST style of developing web services in Java, also known as RESTful web services and nothing is better than to start with a good book. I often receive request about which book should I read to learn REST? or what are some best books to learn to develop RESTful Web services in Java etc? In this article, I will suggest some books which will teach you both designing a REST API and developing RESTful web services in Java.

Is it Possible to take Spring Certification without training course?

It wasn't possible until last month to take Spring certification without mandatory training course but from 10th May 2017 onwards, you can take Spring Certification without training course. Yes, you read it correctly, it's possible to become Spring certified developer without spending USD 3200 on mandatory Spring training e.g. Core Spring training or Spring Web Application Developer training. For years, Pivotal, company behind Spring framework ensured that a Java developer can only get Spring certification by first going to into a 4-day training run by Pivotal and its partner around the world. Even though training can be taken at classroom or online, the high cost of training was the main hindrance for Java developers who were interested in doing Spring certifications.

Difference between var, val, and def in Scala

This is one of the frequently asked questions from Scala interviews. Even though both var and val keyword is used to declare variables in Scala there is a subtle difference between them. A var is a variable. It’s a mutable reference to a value. Since it’s mutable, its value may change through the program lifetime. On the other hand, val keyword represents a value. It’s an immutable reference, meaning that its value never changes. Once assigned it will always keep the same value. It’s similar to a final variable in Java or constants in other languages. It's also worth to remember that the variable type cannot change in Scala. You may say that a var behaves similarly to Java variables.

10 Free Java 8 Certification Sample Questions - OCAJP8 and OCPJP8 - 1Z0-808 and 1Z09 dumps

If you are preparing for Oracle Java SE 8 Certifications e.g. OCAJP8 and OCJP8, also known as exam 1Z0-808 and 1Z0-809 and looking for some free practice tests then you have come to the right place. In this article, I am going to share some of the best OCAJP 8 and OCPJP 8 mock tests available for free of cost online, so that you can check your speed and accuracy before the real exam. These tests are not just useful for Oracle's Java OCA and OCP certification but also for upgrade exams like OCJP 8 upgrade exams with code 1Z0-810 and 1Z0-813, upgrade to Java SE 8 from Java 6 and prior version. Many of these practice tests are like web simulator where you need to solve a relatively small number of questions within 45 to 60 minutes. The web simulator also includes timer so that you can finish these free mock tests on time.

Binary Tree 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 same but the algorithm to achieve that effect is different. Since post-order traversal is a depth-first algorithm, you go deep before you go wide. The left subtree is visited first, followed by right subtree and finally the value of a node is printed. This is the reason why the value of root is printed last in the post-order traversal algorithm.

How to Prepare for Java Certifications like OCAJP, OCPJP, or OCEJWCD?

No doubt that Oracle's Java certification is one of the most valuable certification for IT industry and helps you to get a better job, a better pay, and a better rise in your current salary. It also improves your recognition and job prospects because many big clients demands certified Java programmers for their mission critical applications. Because of huge popularity and usefulness, many Java developers and computer science graduate aspire for Java certifications. I often receive queries like, what is the best way to prepare for Java certifications like OCAJP or OCPJP? or I am already coding in Java, do I need to prepare explicitly for this exam to do well or my Java development experience is enough? I have 5 years of experience in Java, do I need to prepare for OCAJP 8 or OCPJP 8 exam? etc.

Top 5 Books Java 8 Certifications - 1Z0-808 (OCA) and 1Z0-809 (OCP)

In order to become a Java 8 Certified developer, you need to pass two exams, the OCAJP 8 exam with code 1Z0-808 and the OCPJP8 exam with code 1Z0-809. You will not be a Java SE 8 certified programmer if you just pass the OCAJP8 exam. In order to prepare for both these exams, you need to choose a good study guide and a good mock exam simulator, apart from writing programs on daily basis. Since there are a lot of demand for Java 8 certified professionals across the world, it seems to be a good opportunity to change your career path by learning Java 8, if you are doing some boring IT work and wants to become an application developer. The Java certifications will provide you both knowledge and competitive edge over other candidates who are applying for same Java developer job.

Top 10 Free Python Programming Books - Download PDF or Read Online

Every Programmer loves free eBook, even more, if it comes from renowned technical book publishers like Oreilly or Manning. In the last article, I have shared some of the best free Java programming books and today I am going to share some of the equally best free Python Programming books. These books are not illegal copies which are uploaded into the internet, but they are the legal copies, made free by their author and publishers. Though these are not full-fledged books but concise eBooks, they are very informative and comprehensive enough to learn things like Data Science and Functional programming in Python.

How to convert JSON String to Java Object - Gson/JSON Deserialization Example

In the last article, you have learned how to convert a Java object to JSON String and in today's article, you will learn the opposite, i.e. converting a JSON String to Java object. The first example was known as JSON serialization example and this one is known as JSON deserialization because we are creating a Java object from a String. The idea is very similar to classical Serialization in Java where you convert a Java object to another binary format which can be transported over the network or can be saved in the disk for further usage. That's why the process of converting a Java object to JSON is known as serialization and converting a JSON document to Java object is known as De-Serialization. You can use any JSON library to perform serialization and de-serialization e.g. Jackson Databind, Gson, or Json-simple.  In this program, I'll show you how to use Gson to create a Java object from given JSON String.

How to convert Java object to JSON String - Gson Java/JSON Serialization Example

If you are a Java or Android developer and learning JSON to support JSON format for your project and looking for a quick and simple way to convert your Java object into json format then you have come to the right place. In this article, I'll teach you how to convert a Java object to JSON document using Google's Java library called Gson. This library allows you to convert both Java object to JSON String and a JSON document to Java object. So, let's first do some serialization. Serialization in the context of Gson means mapping a Java object to its JSON representation. In the real world, the data can be really complex with lots of attributes and nested with composed object but for now, we'll start with a class which just contain few value attributes e.g. String, int and boolean.

Java Program to calculate Perimeter/Circumference of Circle

One of the common programming exercise for beginners is to write a program to calculate the perimeter or circumference of a circle in Java. This exercise is not just common in Java but also on other programming language courses e.g. C, C++ or Python. I first did this exercise on C++ long ago, but that time the joy of a working program was something different. I was quite happy to see my program compiled without error and can print the correct circumference after entering radius. That program taught me how to take input from a user and how to display output into the console, I didn't know about how to create methods to encapsulate code. For us, only main method matters at that time. Anyway, let's focus on the job in hand i.e. how to find the circumference of Circle of given radius. You have to accept radius from the user and show the output to console.

4 Differences between ISNULL vs COALESCE in SQL Server

Even though both ISNULL() and COALESCE() function provides alternate values to NULL in SQL Server e.g. replacing NULL values with empty String, there are some key differences between them, and the key difference between them is that  COALESCE() is a standard function but ISNULL() is a SQL Server specific, which means it's not guaranteed to be supported by other database vendors like Oracle, MySQL or PostgreSQL. But, perhaps the most important difference between them is that COALESCE is more flexible and powerful than ISNULL(). With ISNULL(), you can only provide one alternate value but with COALESCE you can provide more than one e.g. if col1 IS NULL then take value from column2, if that is NULL then take the default value. Btw, that's not the only differences, there are three key differences between ISNULL() and COALESCE() which we will explore in this article.

How to convert Java 8 Stream to Array or ArrayList - Example Tutorial

It's relatively easy to convert a Stream to an array in Java 8 by using the toArray() method of java.util.Stream class. By using this method you can convert any type of Stream to a corresponding array e.g. a Stream of Strings can be converted into an array of String, or a Stream of integers can be converted into an array of Integers. The Stream.toArray() method is also overloaded, the one which doesn't take any parameter returns an Object[] which might not be very useful, particularly if you want to convert Stream of T to array of T. On the other hand, the overloaded version of toArray(IntFunction[] generator) returns an array containing the elements of this stream, using the provided generator function to allocate the returned array, as well as any additional arrays that might be required for a partitioned execution or for resizing.

SOAP and RESTful - Best Books to Learn Web Service in Java

If you are a Java developer and want to learn how to develop Web Services in Java, both SOAP and RESTful, but confused on where to start, then you have come to the right place. In this article, I am going to share some of the best books to learn about both SOAP and RESTful web services in Java. If you are not familiar with Web Services, it's way to expose the services provided by your application to other developers and application. For example, if your system provides weather information then the user can go and check whether manually by looking at the Web GUI built using HTML, CSS, and JavaScript, but by exposing the same information using Web services, you allow a programmer to display as they want.   A programmer can invoke your web service from a smartphone application and show weather related information in a weather app. The web service really makes your services more accessible and opens a new way to show the information to different users.

How to add JAR file in Eclipse Project Build path - External dependency

In this Java Eclipse tutorial, I will show you two ways to add external JAR files in Eclipse Java projects. Many times we need to use external JAR files in our Java application for different needs e.g. for general purpose you may use Google Guava or Apache Commons. If you are using Spring or Hibernate framework then you need their JAR files as well. In order to use any third-party library or framework, we have to add their JAR files in the classpath, to compile and run our Java programs. Since Eclipse is the most popular IDE for developing Java applications, it's important to know how you can add external JARs into your Java project's build path. For example, suppose, you have downloaded Apache commons JAR file from the internet and wants to add that file to your Java project. In order to use classes and methods from that library, your project must reference those and this is what we will learn here.

Top 10 OCAJP and OCPJP Exam Simulators for Java Certifications

There is no doubt that exam simulators play an important role in preparing for any Java certification e.g. OCAJP, OCPJP, OCEJWCD,   OCMJEA exams. In fact, they are one of the most important pillars because choosing a good exam simulator with a good book is generally the success mantra of many Java certification aspirants. The exam simulators prepare you well for exams by presenting the level of questions you can expect in real exams. They provide the much needed practice in exam like environment to gauge your speed and accuracy. I have personally seen the difference of 30% in score between people who do a lot of mock exams and who just goes without practicing mock exams. Candidates make more mistakes when they first took exams and by participating in mock tests, you train your mind to do fewer mistakes. They also help you to better handle the time pressure of real exam.

2 Best Books to Learn Hibernate for Java Developers

Hibernate is the leading ORM (Object to relational) framework in Java world used to implement persistence layer of enterprise Java applications. It was one of the first Java frameworks on ORM persistence and exists even before the Java Persistence API was introduced. It has since then implement JPA interfaces and you can use Hibernate as one of the JPA implementation. In fact, it is one of the most popular JPA implementation in Java world. I receive a lot of email about books and tutorial to learn Hibernate, especially from intermediate Java developers, who has a couple of years of experience in Java but new to Hibernate. It is also a very useful skill to have on your resume because they are a lot of companies who are using Spring and Hibernate to developer enterprise Java application. So if you are looking for a job in Java world, particularly as Java web development role learning both Spring and Hibernate can help you to get your dream job.

12 Advanced Java programming books for Experienced developers - Part 2

This is the second part of 12 must read advance Java programming books for intermediate and experienced Java programmers. In the first part, I have shared books to learn and master concurrency, performance, design patterns, and Java collection framework. In this part, I will talk about more advanced concepts e.g. security, Java 8, best practices etc. As an experienced Java developer, a lot is expected from you. Junior developers look at you for guidance and project managers look at you to solve problems and bail them out at key junctures. If you don't have solid knowledge of the various aspect of software development, testing, deployment, and documentation, you won't be able to do your job properly and rise in your career.