5 ways to redirect a web page using JavaScript and jQuery

When an HTTP request for one page automatically goes to another page then it is called a redirection. The redirection of a web page is used for different reasons e.g. redirecting to a different domain e.g. when you move your website from one URL to another URL or redirecting to a more recent version of a page you are looking at it. There are many ways to redirect a web page and different web technologies provide different ways e.g. Java provides sendRedirect() and forward() method for redirection. The redirection can also be divided into two categories, client side and server side. In client side, redirection client is responsible for routing request to another URL but in server side redirection, its server's job to redirect to a new page.

How to find all files containing specific text in Linux? Use grep command

One of the most common task while working in programming projects is finding files containing some specific text e.g. you have your application deployed in Linux server and you are migrating your database from one server to another. Now, you want to file all config files and scripts which are referencing your old database using the hostname or IP address, so that you can replace them with an alias. Well, you should always use an alias to connect to the database or any other system, but sometimes it happens you have to use hostname. Anyway, how do you find all those files containing hostname in your Linux machine? Well, the grep command is here to help you.

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.