Top 5 Free Java Courses for Beginners to learn Online

We all love free resources, don't you? There was a time when I buy a lot of books when I was preparing for my engineering entrance exam but I only ended up buying books not reading them. Afte that I changed my habit to first try to read a book on loan or trying free resource and only buying when I really need. When I started my programming journey, mostly I learn from free resources e.g. free courses and books and there I developed the passion to collect free resources as well.  I agree that paid resources are often better than free resources e.g. books and courses but if you are just starting your journey, it's the free resource which you should try first. Once you have some background and interest, you should consider buying a proper book or courses for comprehensive learning.

Top 5 Books to learn Database design and Modelling for Programmers and DBAs of All level

The database design and modeling are one of those topics which rarely gets the attention they deserve, especially at the start of the project, but once things have gone out of hand then everybody talks about that. Comments like - this database are designed poorly, it is not performing well, you cannot add a new column easily etc becomes very common. The most problem with database design is that it is mainly done by application developers e.g. Java or C++ developer who knows SQL but they are not the expert of how to design tables and schema. The Database admins or DBAs know database and SQL better than application programmers but they focus on the admin part of the database rather on application part e.g. designing tables and relations between them, which is left to the application developer.

The Most Simple trick to Loss Weight - Buy A Digital Weight Machine and Check Your Weight Daily

You must be wondering why I am sharing a weight loss or physical fitness tip in my Java programming blog? Well, after reading Soft Skills: The software developer's life manual by John Sonmez, a software developer, and life coach, I found that fitness is very important for programmers and it's about time we should take it seriously.  In general, programmers and IT professionals are not the most physically active persons and hence the easy target for the life-threating disease like heart-attack and diabetic. I started my weight loss journey last year, achieved something but lost it again due to busy work schedule. In this article, I am going to share some of my experience, starting with the most simple trick to lose weight, which worked for me and helped me to lose 8Kg in 3 months.

Grokking Algorithms By Aditya Bhargava - Book Review - Best Algorithm book for Beginners

I have read many books on data structures and algorithms e.g. Introduction to Algorithms by Thomas H. Corman and Algorithm design manual by Steve S. Skiena, so when I come to know about this book, I thought, just another book on algorithms, but I was wrong. This is not just another book on algorithms but one of the most interesting books you will ever read on Algorithms and Data structure. Let's accept it, data structure and algorithms is interesting but at the same time they are very complex and hard to understand, especially, if not explained very well and that's where this book rocks. It explains things in very easy language and most importantly with a context, which helps to understand the topic better.

Spring Framework Certification FAQ - Frequently asked Questions Answers

If you are a Java developer, working in Spring framework and thinking to become a certified Spring professional but couldn't to do it in the past due to expensive mandatory training provided by Pivotal and its partners then there is a good news for you. From 10th May 2017, Pivotal made the Spring Core training optional for appearing to Spring certification exam, which means, now, it's not mandatory to take Spring training for Spring certifications (see here). Similar to Oracle's Java certifications, you can become a Pivotal certified Spring Professional by just buying the exam vouchers and scheduling your exam online using examlocal.com from anywhere in the world.

Clean Code by Uncle Bob - Book Review - Must read for Software Engineers

Even though, the Clean Code book has been released many years ago and there are lots of good reviews already available, I couldn't resist to write my own experience about this great book. I came across this book many years ago but since then I have read it multiple times and I have recommended it to my readers, students, and fellow developers. It is one of those books which make you feel that why didn't you come across it earlier, I felt the same when I first learned about this book. The Clean Code is all about writing good quality code and how do you judge the quality of code? Well, you won't appreciate good until you have seen bad code and that's what this book do.

Jackson JSON Parsing Error - UnrecognizedPropertyException: Unrecognized field, not marked as ignorable [Solved]

While parsing JSON string received from one of our RESTful web services, I was getting this error "Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "person" (class Hello$Person), not marked as ignorable". After some research, I found that this is one of the common error while parsing JSON document using Jackson open source library in Java application. The error messages say that it is not able to find a suitable property name called "person" in our case, let's first take a look at the JSON we are trying to parse, the class we are using to represent the JSON document and the error message itself.

Error Message:
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "person" (class Hello$Person), not marked as ignorable (4 known properties: , "id", "city", "name", "phone"])

Effective Java, 3rd Edition Coming soon - Covers JDK 7, 8, and 9 -Must Read for Java Programmers

Hello guys, I have an interesting news to share with you today. After a long wait of almost 10 years, Effective Java 3rd edition is finally coming this year, hopefully, December 2017. The Effective Java 2nd Edition was released in May 2008 and updated for Java SE 6, but it been, good 10 years now and there is a lot of interest from Java developers around the world for Effective Java 3rd edition after Java SE 8 release and I am very happy to inform you guys that, finally, all our wishes are granted and Effective Java 3rd edition is set to arrive this year. It will not only cover Java 9 release but also all the changes from Java 7 and Java 8.

Differences between @RequestParam and @PathVariable annotations in Spring MVC?

The Spring MVC framework, one of the most popular frameworks for developing a web application in Java world also provides several useful annotations to extract data from the incoming request and mapping the request to controller e.g. @RequestMapping, @RequestParam, and @PathVariable. Even though both @RequestParam and @ParthVariable is used to extract values from the HTTP request, there is a subtle difference between them, which makes them a useful question from interview and spring certification point of view. We'll examine the subtle difference between @RequestParam and @PathVaraible in this article. As the name suggests @RequestParam is used to get the request parameters from URL, also known as query parameters, while @PathVariable extracts values from URI.

Can a non static method access static variable/method in Java?

"Can a non-static method access a static variable or call a static method" is one of the frequently asked questions on static modifier in Java, the answer is, Yes, a non-static method can access a static variable or call a static method in Java. There is no problem with that because of static members i.e. both static variable and static methods belongs to a class and can be called from anywhere, depending upon their access modifier. For example, if a static variable is private then it can only be accessed from the class itself, but you can access a public static variable from anywhere. Similarly, a private static method can be called from a non-static method of the same class but a public static method e.g. main() can be called from anywhere.

Clean Architecture by Uncle Bob Martin - Book Review - Must read for Programmers

Hello Guys, today, I am very excited to talk about a new book (Clean Architecture: A Craftsman's Guide to Software Structure and Design) from one of my favorite author of programming books, you guessed it right, Uncle Bob. The same Uncle Bob (aka Robert Martin) who brought you the Clean Code and Clean Coder has been at it again. It's been a long time since I last read an Uncle Bob and somehow I wasn't aware of this book. It comes to me as a surprise yesterday when one of the colleagues mentioned it and I didn't take time to realize that I need to buy and read this book. I just cursed myself that why I didn't know about this book before, it is still new but given I love to read his books, it's just a miss for me.

Top 4 Books to learn Oracle PL/SQL Programming - Best, Must Read

In last summer, I had worked on a Java project which was using Oracle database at their backend. The project was a mix of Java code with Oracle PL/SQL stored procedures, where Stored procedures were quite big and complex to read. I had not worked on Oracle for a couple of years and almost forget whatever I knew before. So, to revise, update and re-learn and I looked over some of the books I remember would help me. In the search, I also find lots of their used books on Oracle PL/SQL which are both interesting to read as well as provide a great wealth of information to any programmer. These books are from application developer's perspective and not for DBAs.

DispatcherServlet of Spring MVC - 10 things Java Developer should know

If you have worked with Spring MVC then you should know what is a DispatcherServlet? It's actually the heart of Spring MVC, precisely the C of MVC design pattern or Controller. Every single web request which is supposed to be processed by Spring MVC goes through DispatcherServlet. In general, its an implementation of Front Controller Pattern which provides a single point of entry in your application. It handles all incoming requests. It is also the bridge between Java and Spring and DispatcherServlet like any other Servlet is declared in the web.xml with a URL pattern enough to map every single web request to DispathcherServlert.

Java 8 - Sorting HashMap by values in ascending and descending order

In the last article, I have shown you how to sort a Map in Java 8 by keys and today, I'll teach you how to sort a Map by values using Java 8 features e.g. lambda expression, method reference, streams, and new methods added into the java.util.Comparator and Map.Entry classes. In order to sort any Map e.g. HashMap, Hashtable, LinkedHashMap, TreemMap, or even ConcurrentHashMap, you can first get set of entries by using the entrySet() method and then you can get the stream by calling the stream() method. The entrySet()  method returns a Set which inherit the stream() method from the java.util.Collection class. Once you got the stream, you can just call the sorted() method which can sort all Map.Entry objects available in Stream using a Comparator.

Difference between @RestController and @Controller Annotation in Spring MVC and REST

The @RestController annotation in Spring MVC is nothing but a combination of @Controller and @ResponseBody annotation. It was added into Spring 4.0 to make the development of RESTful Web Services in Spring framework easier. If you are familiar with the REST web services you know that the fundamental difference between a web application and a REST API is that the response from a web application is generally view (HTML + CSS + JavaScript) while REST API just return data in form of JSON or XML. This difference is also obvious in the @Controller and @RestController annotation. The job of @Controller is to create a Map of model object and find a view but @RestController simply return the object and object data is directly written into HTTP response as JSON or XML.

What does the InternalResourceViewResolver do in Spring MVC?

The InternalResourceViewResolver is an implementation of ViewResolver in Spring MVC framework which resolves logical view name e.g. "hello" to internal physical resources e.g. Servlet and JSP files e.g. jsp files placed under WEB-INF folder. It is a subclass of UrlBasedViewResolver, which uses "prefix" and "suffix" to convert a logical view name returned from Spring controller to map to actual, physical views. For example, if a user tries to access /home URL and HomeController returns "home" then DispatcherServlet will consult InternalResourceViewResolver and it will use prefix and suffix to find the actual physical view which is integral to a web application. For example, if prefix is "/WEB-INF/views/" and suffix is ".jsp" then "home" will be resolved to "/WEB-INF/home.jsp" by InternalResourceViewResolver.

How to Remove key value pairs or Entries from HashMap in Java 8

In the last article, I have shown how to remove key/value pairs from a map in Java based upon some conditions e.g. remove all entries where values are greater than 10$. I have told you that you must use the Iterator's remove() method for removing mapping while iteration to avoid ConcurrentModificationException, but that's not required anymore in Java 8. From JDK 8 onwards, you can selectively remove mapping without iterating over Map. The JDK 8 API has added several new methods to existing interfaces e.g. java.util.Collection, java.util.Map, Comparator etc because the interface can now contain concrete methods in form of static and default methods.

How to enable/disable an element using jQuery and JavaScript? Example

Sometimes we need to enable and disable input elements e.g. text box, radio buttons or checkbox, how can we do it dynamically without loading the page? Well, we can use JavaScript, particularly jQuery to do this. An element can be disabled in HTML by setting disable property to true and enabled again by setting disabled=false. By using jQuery, we can grab the element we want to enable or disable and change this property by using prop() or attr() function, depending upon which version of jQuery you are using. prop() function was added in jQuery 1.6 and its the standard way to deal with properties but attr() function does the same job for jQuery 1.5 and lower version so you can use attr() for the same purpose in jQuery version lower than 1.6.

How to remove key value pair from Map during Iteration - Example tutorial

Suppose you have a Map e.g. HashMap or Hashtable, which contains key value pairs e.g. books and their prices, and you want to remove all books whose prices are greater than 40 USD, How do you that in Java? Many Java programmer, will say that they will iterate over Map and check each entry and then use remove(Object key) or remove(Object key, Object value) methods from java.util.Map to remove any mapping where the value is greater than 40 USD. Though the approach is right, the answer is wrong. Yes, we'll iterate over Map to check each value but we'll not use the two remove() methods from java.util.Map interface because they will throw ConcurrentModficationException, when you call them to remove mapping during iteration. Instead, we'll use the Iterator.remove() method to remove any key value pair, where the value is greater than 40 USD.

10 tips to quickly become productive with new Project/Codebase

One of the main drawback of changing job or changing project it that you lost all subject matter expertise you have learned by working the last couple of years in that project or domain. It doesn't matter whether you are an expert in a programming language, once you change job, you lost your hard earned experience on projects or domain you are working on. When starting a new job or on to a new project you will rarely be working on a complete greenfield environment. Understanding and mastering an unfamiliar code is a difficult process and it can sometimes feel overwhelming due to the amount of new information you need to take on.

Java SE 8 Certification Books - Best of Lot Must Read

If you are preparing for Oracle Certified Associate, Java SE 8 Programmer, also known as Java SE 8 Programmer I or OCAJP8 exam and looking for some good resources e.g. books, study notes, and mock exams then you have come to right place. I have been sharing some of the most useful resources for Java 8 certification aspirants ever since the exam was launched. You can find a lot of this exam and essential resources in this blog. To continue that tradition, I am going to share some of the best books to crack the Java SE certification i.e. OCAJP 8 (1Z0-808)  and OCPJP 8 (1Z0-89). Yes, you need to pass two exams to become Java 8 certified professional. The OCAJP is also a prerequisite for OCPJP exam, which is a professional level exam. Alternatively, if you already hold a Java certification e.g. Java SE 6 or before then you can take one of the upgrade exams e.g. 1Z0-810 to become Java SE 8 certified professional.

Top 10 Java ConcurrentHashMap Interview Questions and Answers

The ConcurrentHashMap class part of concurrent collections added on JDK 1.5 e.g. BlockingQueue, CopyOnWriteArrayList, CopyOnWriteArraySet etc. It is a replacement of synchronized hash-based map implementations e.g. Hashtable and synchronized HashMap. It implements Map and ConcurrentMap (a sub-interface of Map) interface which allows you to store key value pairs. The class is similar to HashMap or Hashtable but it's more scalable and the right fit for concurrent Java application. Unlike Hashtable which achieves its thread-safety by compromising scalability, ConcurrentHashMap uses advanced techniques e.g. dividing the map into segments to remain thread-safe and scalable at the same time.

How to convert a lambda expression to method reference in Java 8?

If you have been coding in Java 8 then you know that using method reference in place of lambda expression makes your code more readable, hence it is advised to replace lambda expression with method reference wherever possible, But, the big question is, how do you find whether you can replace a lambda with method reference? Yes, it's not that easy, especially if you have been using Java 8 only for a couple of months and struggling to get the functional programming concepts and idioms sorted in your head. Anyway, the simple rule to replace lambda expression with method reference is built on common sense, which you will learn in this article.

Top 5 Books to Learn Groovy for Java Developers - Best Of Lot, Must Read

Groovy is a programming language which is specially created for Java developers with a view to being a fast paced, scripting companion to Java. It aims to increase the productivity of Java developer by simplifying Java code by removing unnecessary boilerplate. Groovy not only present a succinct and easy to read syntax but also provide a much more elegant and convenient API than Java for common stuff. For example, a Groovy file can do in 50 lines what a Java source code do in 500 lines. You can declare an array as [] and map as [: ] which really make code full of data without much syntax. Because of this property, Groovy is heavily used in unit testing of Java application using a framework like Spock is built on Groovy.

How to create a thread-safe ConcurrentHashSet in Java 8?

Until JDK 8, there was no way to create a large, thread-safe, ConcurrentHashSet in Java. The java.util.concurrent package doesn't even have a class called ConcurrentHashSet, but from JDK 8 onwards, you can use newly added keySet(default value) and newKeySet() method to create a ConcurrentHashSet backed by ConcurrentHashMap. Unlike tactical solutions like using concurrent hash map with dummy value or using the set view of the map, where you cannot add new elements. The Set returned by keySet(defaultValue) and newKeySet() method of JDK 8 is a proper set, where you can also add new elements along with performing other set operations e.g. contains(), remove() etc. Though you need to be careful that these methods are only available in ConcurrentHashMap class and not in ConcurrentMap interface, so you need to use a ConcurrentHashMap variable to hold the reference, or you need to use type casting to cast a ConcurrentHashMap object stored in ConcurrentMAp variable.

10 Differences between StringBuffer and StringBuilder in Java

StringBuffer and StringBuilder are two important classes in Java which represents mutable String i.e. the String object, whose value can be changed. Since String is Immutable in Java, any change or operation on String object e.g. converting it to upper or lower case, adding character, removing character or substring all result in a new String object. This can put a lot of pressure on Garbage collector if your application generates lots of throws away String instances, to avoid this issue, Java designer presented initially StringBuffer class and later StringBuilder. When StringBuffer was introduced it has its own problem e.g. it was synchronized and hence was a lot slower.

Top 10 Programming/Coding Problems and Challenges Websites

Do you love programming challenges? If Yes, then you will be happy to see so many free resources available to improve your programming skills. There are so many websites, which has interesting programming questions, puzzles, riddles, problem set and challenges. Some of them even provide a world wide ranking, so that you can judge yourself among other programmers from all over the world. In this article, we will see my collection of 10 websites, which provides programming and coding challenges. I have tried to include a mixture of sites which have both easy, moderate, tough and extremely difficult programming challenges.

How to format/parse dates with LocalDateTime in Java 8 - Example Tutorial

One of the common tasks in Java project is formatting or parsing date to String and vice-versa. Parsing date means you have a String which represents a date e.g. "2017-08-3" and you want to convert it into an object which represents the date in Java e.g. java.util.Date in pre-Java 8 world and LocalDate or LocalDatetime in Java 8 world. Similarly, formatting a date means converting a date instance into String, for example, you have a Date object or LocalDatetime object and you want a String in dd-MM-yyyy format. Java 8 API provides a good support for formatting and parsing dates. For example, if you have a date as String e.g. "2017-08-3 12:30" and you want to convert it to a LocalDateTime instance, which is a new class from JDK 8 Date and Time API and contains both date and time part, how do you do that? Well, you can use the format() and parse() method from LocalDateTime class to achieve that, but you need one more thing, a date format.

Best book to Learn TCP/IP, UDP and Computer Networking Protocols

Both TCP/IP and UDP are very popular networking protocol and in this era of the internet and a connected world, they become even more important. No matter, whether you are a computer science graduate or doing masters in computer science, a software engineer, a network engineer, or a Java programmer, good knowledge of TCP/IP and UDP goes a long way to securing a job and doing well on it. Even though I mostly interview for Java programmers, I almost always ask a couple of questions on TCP/IP and UDP protocol to check if the candidate is familiar with computer network basics or not because even if you work for Java application, you are exposed to the network.

Entuware or Whizlabs? Which Exam Simulator Should you Buy for Java 8 Certifications?

I often receive queries from Java certification aspirants about exam simulators e.g. whether should I go for Whizlabs or Enthuware, which one is better? If I have to buy just one exam simulator, which one would you recommend, Whizlabs or Enthuware? I thought to answer all those questions in a blog post and here you go. To be honest both of them are really high-quality test simulator and whichever you buy, you will do well on actual exams. But, as a programmer I really like to analyze the situation, I compare pros and cons of each of them before I buy one of them. Since I have used both of them in past I am sure about quality they are neck to neck there, but here are couple of things which you can consider before buying Java certification simulator from Whizlabs or Enthuware

How to sort a Map by keys in Java 8 - Example Tutorial

In the last article, I have shown you how to sort a Map by values in Java 8 and in this tutorial, you will learn how to sort a Map by keys e.g. an HashMap, ConcurrentHashMap, LinkedHashmap, or even Hashtable. Theoretically, you cannot sort a Map because it doesn't provide any ordering guarantee. For example, when you iterate over a HashMap, you don't know in which order entries will be traversed because HashMap doesn't provide any ordering. Then, how can you sort a Map which doesn't support order? Well, you can't and that's why you only sort entries of HashMap but you don't store the result back into HasMap or any other Map which doesn't support ordering. If you do so, then sorting will be lost.

How to check/uncheck checkbox using jQuery? Example Tutorial

In the last couple of articles, I have shared a couple of useful jQuery tips e.g. reloading web page and working with tag selectors, today, I'll show you how to check or uncheck a particular checkbox using jQuery. If you remember, in HTML a checkbox is checked if the "checked" attribute is present and its value is not false, otherwise, it's unchecked. By using jQuery function prop() we can dynamically add this attribute or if present we can change its value i.e. checked=true to make the checkbox checked and checked=false to mark the check box unchecked. Though you should remember that prop() function is only available from jQuery 1.6 version and if you are running on lower jQuery version then you can also use attr() to check/uncheck a particular checkbox.

Top 50 Java Programs from Coding Interviews

Coding is an integral part of any programming job interviews Java development interviews are no exception. I would even suggest you should never hire anyone without testing their coding skill, coding is also an art and more often than a good code is a good developer as well. If you look at tech giants like Amazon, Facebook, and Google they thoroughly test the coding skill of any developer they hire, particularly Amazon who first send online coding exercises to filter Java programmers who can code. This online test usually gives you requirements and ask you write a program in limited time usually 2 to 3 hours. The program should meet the output given by the exercise itself. These type of exercises are very tough to crack if you don't have a good coding skill.

Arithmetic overflow error converting numeric to data type numeric in SQL Server

This error comes when you try to store an out-of-range floating point value into a numeric variable. For example, if your NUMERIC or DECIMAL variable is defined as NUMERIC(5,2) than the maximum value it can hold is 999.99, if you try to store something like 1000.00 then it will throw "Arithmetic overflow error converting numeric to data type numeric". One of the common reason of this error is the ignorance and misunderstanding of the NUMERIC data type. For example, many SQL Server DBAs and developers think that a NUMERIC(5,2) variable can hold a 7 digit floating point number where 5 digit is before decimal and 2 digits are after the decimal. This is wrong. A NUMERIC(5,2) means, the total number of digits in the value cannot exceed 5 and decimal precision is 2 digits i.e. the maximum possible value is 999.99.

How to reload/refresh a page using JavaScript and jQuery

JavaScript provides several ways to reload or refresh an HTML page but the standard way to do this job is by using window.location object. This object provides a reload() method which instructs the browser to reload the page. The browser can do it from its cache or from the server, which depends upon optional parameter i.e. reload(true) will reload the page from the server but reload(false) will only reload the page from browser's cache, which may or may not represent the current version at the server.

Is it possible to have an abstract method in a final class?

This is one of the interesting core Java questions which was asked to one of my readers recently during a telephonic interview for Java developer job interview. Even though he knows that you cannot make an abstract class final in Java, he got confused by the wording of the methods. The answer is simple, No, it's not possible to have an abstract method in a final class in Java. Why? because as soon as you declare an abstract method in a Java class, the class automatically becomes an abstract class and you cannot make an abstract class final in Java as discussed before, hence it's not possible to have an abstract method in a final class in Java.

Does Spring Certification help in Job and Career? Why become Pivotal Certified Spring Professional?

One of the frequently asked question among Java and Spring developer is whether Spring certification is valuable? or does Spring Certification help you in Job and Career? These questions are not very different from what Java developer ask about Oracle's Java certification (see here). The short answer to these question is Yes, Spring Certifications are very valuable and it not only provides Industry recognition for your knowledge, experience, and skill but also set you apart from the millions of Java and Spring developer who are not certified. Of course, as with any certification, the most valuable part, apart from recognition is the learning process and this is true for Spring certifications as well.

2 Ways to check if A String is rotation of other in Java?

Write a program to check if one String is a rotation of another String is a common coding problem you will see on programming job interviews.  A String is said to be a rotation of another String, if it has the same length, contains same characters, and they were rotated around one of the characters. For example,  String"bcda" is a rotation of "abcd" but "bdca" is not a rotation of String "abcd". One of the simplest solutions to this interesting problem is first to check if two String has the same length, if not then one String cannot be the rotation of another. If they are of the same length then just create another String by concatenating first String with itself, now check if second String is a substring of this concatenated String or not, if yes, then second String is a rotation of first.

OCAJP 8 FAQ - Oracle Certified Associate Java Programmer I Certification (1Z0–808) Frequently asked Questions

The Oracle Certifications is one of the most repeated, industry-recognized certifications. It also provides Java certifications like Oracle Certified Associate Java Programmer, also known as OCAJP and Oracle Certified Professional Java Programmer, also known as OCPJP. These two are most popular Java certification and there are many benefits of passing them e.g. better chance to get a Java development job, improved performance on Java interviews, better salary rise, and promotions, and better opportunity for moving abroad.

Amazon Prime Day, Good opportunity to Buy Books and Gadgets

Most of my friends and colleagues used to wait until November to buy books, gadgets, and other computer items to get the huge discount offered on Black Friday deals, but you don't need to. Amazon is bringing Black Friday to the summer with their annual Prime Day offers. The Amazon Prime day is nothing but a one-day shopping extravaganza, where you get huge discounts on thousands of Amazon products including books, gadgets and other computer and electronics items. So, if you are looking to buy a new laptop, a new smartphone or want to track your fitness, you can buy Fitbit and other such gadgets at a much cheaper price on Amazon prime day.

Top 5 Books to learn UML (Unified Modeling Language) for Java Developers - Best of Lot, Must Read

The UML stands for Unified Modelling language and it is one of the great tools for Object oriented design. It allows you to create several diagrams e.g. class diagram, sequence diagram, object diagram etc, which helps you to understand your system better.   The UML also helps you to convey your thoughts and design to peer and team members before implementation. Since a picture is worth a thousand word, those interactions often help you to find shortcomings and loopholes in your software design very early. That's actually the reason I use UML in our projects. Btw, I didn't know about UML or UML diagrams when I first started Java development. Maybe, I might have heard about it but it just like many more things which I heard but don't pay enough attention. It was my first year in work when I was first asked to prepare both class and sequence diagrams for one of the modules I was developing.

Top 30 Linked List Algorithm Questions from Programming/Coding Interviews

The linked list is one of the most common and essential data structure and that's why you would frequently find linked list based coding questions on interviews. The range of questions can be from simple questions like finding the length of linked list to very difficult e.g. merging two sorted linked list. Nevertheless, point is that you should be familiar with linked list data structure and must know how to perform basics task in linked list e.g. adding or removing nodes from linked list, traversing order linked list and implementing linked list in your choice of programming language e.g. Java, C++, C, or Python. These linked list problems are not only good for coding interviews point of view but also very useful in learning programming. You should try to solve this problem yourselves, before looking at the solution to get the full benefit of them.

JSP - How to check if ArrayList is Empty using JSTL Example

There are multiple ways to check if an ArrayList is empty in JSP or not. For example, you can use the empty operator and the length function of JSTL to check if a list is empty or not. You can also use scriptlet, which allows you to insert Java code into JSP but that is not advisable because it makes it harder to maintain a JSP page. You can also write custom tag but that is not required because JSTL provides you necessary support. In this article, I'll show you two ways to check if a given list or ArrayList is empty or not in JSP page without using the scriptlet. You guessed it right, we will use JSTL, the Java standard tag library to solve this problem.

Is Joshua Bloch's Effective Java Still Valid in the Era of Java 8?

The Effective Java is probably one of most read book on Java technology and has been regarded by many programmers as the best book for Java developers. Though, recently many Java programmers have asked me whether Effective Java is still relevant in the era of Java 8? Or is there any better book on the same topic. The question is logical because It's been more than 9 years since the 2nd edition of Effective Java released in 2008 and also the most recent Java 8 has changed how you code Java. Many idioms and design patterns of good old days now become redundant and can be done easily with the new Java 8 syntax and feature, but does that mean "Effective Java" is not relevant now? Well, No, not at all. The Effective Java is still relevant and must read for Java programmers due to several reasons, which you will see in this article.

How to Escape JSON String in Java- Eclipse IDE Tips

While working or JSON parsing in Java application it's quite common to just copy paste a JSON String from some resources e.g. a RESTful web service and then use the Jackson library to parse the JSON. This is the quickest way to test and learn parsing JSON string in Java, but the main problem with this approach is that the JSON String also includes double quotes "" which is also used for enclosing String literals in Java. Since JSON String itself contains double quotes, when you just copy paste them in your IDE or Java source file, the didn't work as expected. If you remember, if your String contains double quotes then those need to be escaped when you are pasting them as String literals in your Java code.

Difference between Stable and Unstable Sorting Algorithm?

Recently in one on the interview, after some initial questions about sorting algorithms e.g. how do you write QuickSort or difference between QuickSort and MergeSort, the interviewer asked about do you understand the difference between stable and unstable sorting algorithm? This question was new to my reader, so he says, Sorry, never heard about that. The story ended there, and Interviewer moved on to next question but like many of us, my reader went on to find more about unanswered  questions and ultimately he asks me what is the meaning of a stable and unstable sorting algorithm? Some of you might be heard about it and many of you might not know about this distinction, I'll try to answer this question in this article.

Top 5 books to learn Agile and Scrum Methodologies - Best, Must Read

When I started my career, it was all waterfall model. You try, fail, and then with every version you get an improved version of a software. I pretty much used to this model of software development until I was introduced to Agile development methodologies in my next company. I was confused about Agile as some people say its Scrum and Sprint, other ways its XP and Kanban etc. The confusion lasted for a long time because I was afraid of asking questions (afraid of being perceived as dumb and someone who wastes time on meetings) and only getting information in bits and pieces and I wasn't good at searching books at that time. From that experience, I learned that, when you have confusion and want to learn more about a new technology, nothing is better than a book or online training courses to start with.

3 Best Spring Security Online Training Courses for Java Developers

The Spring Security is one of the leading open source, security framework which allows you to implement security in Java based web applications. It provides several security features e.g. authentication, authorization, remember me out-of-the-box, which means you can directly use them without adding code or changing your class. Yes, Spring Security implements security at application level i.e. you can even secure your non-secure resource without modifying them. It is also the leading framework to secure RESTful Web Services. Because of all these, the demand for Java developers with good knowledge of Spring Security is very high. They are also some of the highly paid Java developers. Many Java and Spring developer, particularly those who are involved in enterprise and Java web development are learning Spring Security.

Top 5 Java And Android Game Programming Books for Programmers

Many programmers and game developers  think that Java isn't the best language for game design, but you cannot ignore Java for game development. There is always some popular platform which allowed you to develop and sell games in Java e.g. J2ME in past and Android now. Ever since Android used Java as a programming language, the game development in Java has got a new lifeline and seems to be doing quite well. Even games like Minecraft also doing great on the Java platform. It's true that C++ is still the best language to develop games due to their high-performance and many top game development companies e.g. Sony, Nintendo, and Microsoft XBox they prefer C++ over Java when it comes to developing great games. But with the Introduction of Android and iOS has completely changed the game development industry.

Maven - 10 Things Java developer should know

The Apache Maven is an essential tool for Java developers. It makes their life easy by allowing them to create Java project faster by using a standard directory structure. It also helps them to download project dependency automatically. Not only that, Maven also download transitive dependencies which relieve Java developers from the big headache of keep check of different versions of dependent libraries. For example, if your application is dependent on Spring framework but Spring is dependent on Log4j then you also need to download the correct version of Log4j JAR files for Spring MVC framework, Maven does this automatically for you. Maven also allows you to build projects, upload artifacts to the central or local nexus repository and deploy the release in your various test environments automatically.

Difference between application/x-www-form-urlencoded and multipart/form-data in HTTP/HTML?

Recently in one of the Java web developer interview, one of my readers asked about the difference between x-www-form-url-encoded and multipart/form-data MIME types. In HTTP, there are two ways to send the HTML form data to the server either by using ContentType application/x-www-form-urlencoded or by using multipart/form-data. Even though both can be used to send both text and binary data to the server there is a subtle difference between them. In the case of x-www-form-urlencoded, the whole form data is sent as a long query string.

Jersey Web Service Hello World Example in Java

After Restlet, Jersey is another popular open source framework to create RESTful web services in Java. Jersey conforms JAX-RS specification and actually it is the reference implementation of JAX-RS (JSR 311)(http://jsr311.java.net/nonav/releases/1.1/index.html) specification. In the last article, we have seen the Restlet HelloWorld Example and today we'll see the Jersey HelloWorld Example. Typically, when a developer thinks of creating a RESTful web service using Java, they assume that using a Java EE application server is the only way to create this type of application. However, there are simpler, lightweight alternative methods for creating RESTful applications available using Java SE. This tutorial demonstrates one such alternative using the Grizzly Web server along with the Jersey REST framework. Grizzly's main use case is the web server component for the GlassFish application server.

How to compare two lists of values in Microsoft Excel - Java

If you are working in real world application then you may frequently face scenarios where you have to compare data e.g. you get two lists of values and you want to know which values are common between two lists, which values only exists in the first list and which values only exists in the second list. If the list contains just 5 to 10 values you can do it easily with your eyes but what is fun if a programmer doing the task manually. You should be able to leverage all the tools available to you to do this comparison reliably. One of such ubiquitous and omnipresent tool is Microsoft Excel which is much more powerful then you can think of. It's like your brain, most of us just use 5% of Excel and a good knowledge of Excel's little bit advanced functionality e.g. VLOOKUP can be very helpful while comparing the list of values and reconciling data between different worksheet.

How Spring MVC Framework works? How HTTP Request is processed?

One of the frequently asked Spring MVC Interview questions is about explaining the flow of web request i.e. how an HTTP request is processed from start to end. In other words, explaining the flow of request in Spring MVC. Since many of my readers ask this question time and again, I thought to summarize the flow of request processing in a short article. It all starts with the client, which sends a request to a specific URL. When that request hit the web container e.g. Tomcat it look into web.xml and find the Servlet or Filter which is mapped to that particular URL. It the delegate that Servlet or Filter to process the request. Since Spring MVC is built on top of Servlet, this is also the initial flow of request in any Spring MVC based Java web application.

How to prepare for Spring Framework Certifications?

Ever since Pivotal, the company behind Spring framework made the mandatory Spring training optional (see here), I have received many queries from experienced Java developers who are interested in doing Spring certifications. This move from Pivotal suddenly makes the Spring certification affordable for many experienced Java and Spring developers who were interested in Spring certification earlier but couldn't progress further due to expensive mandatory training. Since many of them are now preparing for Spring certifications e.g Spring Core or Spring via self-study they are increasingly looking for good resources to prepare for the exam. I have received a lot of questions on preparation, books, mock exams, exam structure, passing marks and useful resources.

How to get JAR files of Jackson Libary for JSON Processing

If you are using Jackson to parse a JSON String in Java first time and wondering where can you get the Jackson related JARs, or which JAR files are really need then you have come to the right place. It can be really confusing for a new user to set up or include Jackson library in their Java projects sometimes, especially, if you are not very familiar with the structure of Jackson projects, various JAR files and in particular Maven. Since Jackson is the most popular open source library for processing JSON responses e.g. generating Java objects from JSON received from RESTful Web services or generating JSON String from Plain Old Java Objects (POJO). It is the go-to library for any JSON need because it offers a lot of features without compromising on performance.

What is the cost of Spring Framework Certification and Training in India and USA?

One of the frequently asked question about Spring certifications and training e.g. Spring Core and Spring Web Application Developer Certification is their cost e.g. what is the cost of Spring certification in India? or how much it cost for Spring framework certification in the USA etc. Earlier, Spring certification used to cost around 3000 USD in the USA and other North American countries and around 50,000 INR in India due to mandatory training you needed to take before you can appear in the exam. The cost of the Spring framework training was more than 90% of the total cost of the Spring certification. But gone are those days. Since 10th May 2017, you can take the exam without mandatory training, see here. Due to this reason, the cost of Spring certification has come down heavily and it's just now the cost of the exam voucher which is just 200 USD globally.

2 Books to Prepare for Spring Professional Certifications Exam

Ever since Pivotal has removed the requirement of mandatory training to become a certified Spring developer, many Spring developers have been asking for good resources to prepare for Spring Professional V4.2 Exam and Spring Professional V4.3 Exams e.g. good books, mock exams, study notes etc. to prepare for Spring Core Certifications via self-study. Since, earlier, you cannot give Spring certification exam without attending an online or instructor-led core Spring training, which cost around 3200 USD in the USA and North America and 50K INR in India, many experienced Spring developers refrain from becoming a certified Spring developer. Now that restriction has been lifted and it's not mandatory to take training to take Spring certification, many Java developers who have good working experience in Spring framework are looking to get recognition for their skill.

jQuery Tutorial - How to modify multiple HTML elements in one line

jQuery allows you to modify multiples elements in one go, you can modify attributes, text, or color of multiple HTML elements by executing just one line of jQuery code. In this jQuery tutorial, I will show you how to modify multiple <li> elements in one go. In our example, we have a couple of <li> tag to display sub-headings, now we will change them in one go using jQuery. If you look at our HTML, we have an ordered list <ol> to display top 10 programming languages, each of them is a <li> item. We also have one button, "Click Me", which will when clicked, changes all <li> item's text to "jQuery is the new Boss". Here is the jQuery code, which does that.

Can you take Spring certification without Pivotal Training Course?

Yes, you can take Spring certification without taking mandatory Spring training. Pivotal, the company behind Spring, has announced on 10th May 2017 that "Spring Certification Exams are now available for individual purchase, without enrolling in the course". This is one of the most exciting changes in the Spring certification program since it's launched 10 years back. The cost of Spring certification was the single, biggest obstacle for many experienced Java and Spring developers to get certified for their Spring framework skills. This step from Pivotal is a really positive step and gives a real chance to many experienced developers in cost-sensitive countries like India to get certified for their skill. Now, you don't have to enroll for a 50K training if you have good knowledge of Spring certification and exam objectives, just like Java certification, you can buy the Spring certification voucher @ 200 USD and take the exam online or offline at any test center.

Solution of java.lang.OutOfMemoryError: GC overhead limit exceeded

The java.lang.OutOfMemoryError: GC overhead limit exceeded is another type of OutOfMemoryError in Java which comes when JVM spent too much time doing garbage collection without any success.  For example, if almost 98% of CPU for a Java process is busy doing GC and reclaims very less amount of Java heap space around 2%, then JVM throws "java.lang.OutOfMemoryError: GC overhead limit exceeded" error. Though, the definition of 98% CPU time may vary between different Garbage collector and different JVM version.  Unlike java.lang.OutOfMemoryError: Java heap space and java.langOutOfMemory: Permgen space, this is not so frequent and you will rarely encounter this error in your Java application, but this also denotes resource exhaustion.

How to enable Spring Security in Java Web application?

Spring Security is one of the most popular frameworks to implement security in Java web application in a declarative way. It provides several essential security features e.g. LDAP authentication, authorization, role-based access control,  remembers the password, URL protection, concurrent active sessions management etc. In order to enable Spring security in Java Web application, you need to do configure three things, declare a delegating proxy filter in web.xml, add the ContextLoaderListener in web.xml and provide actual security constraints on applicationContext-Security.xml file. Since Spring security uses a chain of filters to implement various security constraints, also known as Spring's "security chain filter", it relies on web container for the initialization of delegating filter proxy.

How to print 1 to 100 without using loop in Java

This is one of the interesting problems  I have seen on coding interviews  for beginners. The program has surprise element by saying that you need to print 1 to 100 without using a loop e.g. for, forEach or enhanced for loop. This brings out some innovative solutions from candidates which tell a lot about their approach, knowledge, and attitude. I remember, asking this question during campus recruitment to at least 5 candidates. The first one took 5 minutes to think and then come up with the brute force way where he just copies pasted 100 System.out.println() and printed number 1 to 100 but when we asked to improve that, he couldn't too that. Unfortunately, he didn't think that recursion can replace an iterative algorithm without using a loop.

Difference between Servlet and JSP?

Servlet and JSP are two of the most popular Java web technologies to generate dynamic content in Java web applications there is some key difference between them. For example, Servlet is designed for Java developers as most of the coding is done in Java, while JSP was designed and developed for web GUI developer e.g. guys who write HTML and JavaScript and that's why you see the coding in JSP is tag based. Even though you can use HTML tags as String inside Servlet and Java code as Scriptlet inside JSP, both are considered as bad practice and should be avoided at all cost because they are very hard to maintain. The different nature of Servlet and JSP also allows frontend and backend developers to work in parallel, JSP work is mostly done by frontend developers while Servlet work is done by backend developers.

Top 10 Free Java Programming Books, EBooks and PDF download

Who doesn't like free stuff? Well, I do like and many Java programmers like me simply love free Java books, eBooks, and PDFs. Fortunately, the Internet is full of free books and eBooks but unfortunately, many of them are of not good quality. Most of the eBooks which are freely available either are sample chapters of popular Java programming books or they are simply old and out-of-date. In my last article, I have shared a lot of such books and the feedback was that most of them, even though they are good in the past, have simply not up to the mark. The search goes on and while browsing the net a couple of days back I hit the Jackpot when I found these free Java books from Oreilly. Unlike most of the books, these free Java books are good, up-to-date and cover latest technologies like Java 8, MicroServices, Docker, Java EE, Functional Programming and Core Java.

Which Java 8 Certification Should you Take? OCAJP8 (1Z0-808) , OCPJP8 (1Z0-809) , or Upgrade(1Z0-810 and 1Z0-813)

There are a lot of confusion among Java programmers and Oracle Java Certification aspirants related to various Java 8 certifications e.g. what are exam codes, which exams they should go for, whether they are eligible for Java SE 8 upgrade exams, and what should they do if they have just passed Java SE 7 Programmer II certification. I will try to answer each of these questions here, but to get it right let's first clear the confusion about various Java SE 8 exams There are four Java 8 certifications available in Oracle's site:

1) Oracle Certified Associate, Java SE 8 Programmer OCAJP8, exam code 1Z0-808
2) Oracle Certified Professional, Java SE 8 Programmer OCPJP8, exam code 1Z0-809
3) Oracle Certified Professional, Java SE 8 Programmer (upgrade), exam code 1Z0-810
4) Upgrade to Java SE 8 OCP ( Java SE 6 and all prior versions) - exam code 1Z0-813

Top 4 Books to Learn Java for Beginners (Newbie)

I receive lots of emails and Facebook chats related to Java, but one of the most common questions which I have mostly asked is, which is the best book to learn Java? I have just started learning Java, Could you please recommend a good core Java book to me? After answering in one word too many of those readers and new Java developers as "Head First Java", I thought to write this blog post, Why? because some of them come back to me and asked me "Can you please recommend a serious Java book, not the comics?" Well, I didn't like that comment, but then I thought it's natural that not everyone will find "Head First Java" as good as I have always found.

Cause of "java.lang.SecurityException: Missing required Permissions manifest attribute in main jar" [Solved]

If you are working Java Web start application using JNLP and suddenly started throwing "java.lang.SecurityException: Missing required Permissions manifest attribute in the main jar", then check whether you have updated the Java or JRE on your machine. From JDK 1.7 update 51, Java has tightened the security further with number of changes e.g.

1) Block all self-signed and unsigned Java application and Applet if you have opted for HIGH security in Java Control Panel, which is also the default one.

2) Require "Permission" attribute for High-security setting

3) Warning users of missing permission attribute for medium security setting.

Difference between Struts ValidatorForm vs ValidatorActionForm - Interview Question

Struts provide two classes ValidatorForm and ValidatorActionForm for validating form fields. Instead of doing basic validation by using the validate() method in Action class, these classes allows you to leverage rich feature of validation framework provided by Jakarta Struts framework. You can do declarative validation by defining rules in XML config files like validation-rule.xml or validations.xml as well. Since Struts is one of the popular Web MVC frameworks, you can also use its validation framework on any Java web application implemented using Struts. Now, coming back to the question, what is the actual difference between ValidatorForm and ValidatorActionForm in Struts? They both look quite similar, right?

Difference between PriorityQueue and TreeSet in Java?

The PriorityQueue and TreeSet collection classes has a lot of similarities e.g. both provide O(log(N)) time complexity for adding, removing, and searching elements, both are non-synchronized and you can get element from both PriorityQueue and TreeSet in sorted order, but there is fundamental difference between them, TreeSet is a Set and doesn't allow a duplicate element, while PriorityQueue is a queue and doesn't have such restriction. It can contain multiple elements with equal values and in that case head of the queue will be arbitrarily chosen from them. Another key difference between TreeSet and PriorityQueue is iteration order, though you can access elements from the head in a sorted order e.g. head always give you lowest or highest priority element depending upon your Comparable or Comparator implementation but iterator returned by PriorityQueue doesn't provide any ordering guarantee.

Difference between Transient, Persistent, and Detached Objects in Hibernate

In Hibernate framework, an entity can be in three states, transient, persistent, and detached. When an object is in transient state, it is commonly refereed as transient object, similarly if it is in persistence and detached state, it is known as persistent and detached object. When an entity is first created using the new operator e.g. new User() and not associated with Hibernate session e.g. you haven't called session.save(user) method then it is known as transient object. At this stage, Hibernate doesn't know anything about this object and the object doesn't have any representation in database e.g. a corresponding row in the User table. Hibernate will not run any SQL query to reflect any changes on this object. You can move this object into persistent state by associating it with an hibernate session e.g. by calling save() or saveOrUpdate() method from an hibernate Session.

Top 5 FREE eBooks to Learn jQuery Online or download PDF

Everybody loves free resources, don't you? Well, I do and that's why I am always in search of good free resources e.g. eBooks and training courses. In the last article, I have shared some of the free JavaScript books and this time I am sharing a couple of good free eBooks to learn jQuery. The jQuery is one of the most important skills in today's internet world. It is the JavaScript library which has changed the face of websites, they are now more interactive and smooth than ever before. The Internet is also not short of free resources and when it comes to learning jQuery, you will find thousands of articles and tens of eBooks, but not all resources are good. Some of them are not up-to-date and many of them contain incorrect information, hence choosing the good resource is vital.

Difference between @Autowired and @Inject annotation in Spring?

What is the difference between @Autowired and @Inject annotation in Spring is one of the frequently asked questions on Spring interviews? Since everybody is now moved or moving to annotation driven, Java configuration in Spring, this question has become even more important for prospective candidates looking for a Java web development job using Spring framework. The @Autowired annotation is used for auto-wiring in Spring framework. The Autowiring is a process on which Spring framework figure out dependencies of a Spring bean, instead of you, a developer, explicitly specifying them in the application context file. You can annotate fields and constructor using @Autowired to tell Spring framework to find dependencies for you.

Difference between CAST, CONVERT, and PARSE function in Microsoft SQL Server

Though all three, CAST, CONVERT and PARSE are used to convert one data type into another in SQL Server, there are some subtle differences between them.The  CAST method accepts just two parameters, expression, and target type, but CONVERT() also takes a third parameter representing the format of conversion, which is supported for some conversions, like between character strings and date time values. For example, CONVERT(DATE, '2/7/2015', 101) converts the character string '2/7/2015' to DATE using DATE format 101, representing United States standard. By using the PARSE function, you can also indicate the culture by using any culture supported by the Microsoft's  dot NET framework. For example, PARSE('7/8/2015' AS DATE USING 'en-US') parse the input literal as a DATE by using a United State English Culture, similar to 101 formatting style.

Difference between repaint and revalidate method in Java Swing

What is the difference between revalidate() and repaint() in Java Swing is one of the popular Swing Interview Questions especially on Investment banks? Though both methods sound similar, there is a subtle difference between them. the revalidate() method instruct LayoutManager to recalculate layout and often called once new components are added or removed from Container. The revalidate() can also trigger to call to the repaint() method to repaint components which have changed i.e. width, height or any other visible property, which can affect layout. On the other hand repaint() method puts a paint request in AWT thread, for repainting of a component on which it has called.

OCAJP 1Z0-808 - Best Books and Mock Exams for Java 8 OCA Certification

From the last couple of months, I have been helping few developers to prepare for Java 8 associate certification with exam code 1Z0-808, also known as OCAJP 8. From my experience, both for preparing for Sun certification and helping other developers to get Java certified, I can say that two keys to be successful in Oracle Java certification are choosing a good study guide and buying one or two top quality mock exam simulators. When I say success, it doesn't just passing the exam but scoring above 90% because passing score 65% is not very difficult to achieve and anybody can pass OCAJP8 by just a couple of month of practice but to score 90% and above is not that easy, you need to prepare and prepare hard. Since just passing OCAJP8 will not make the desired impact, I always suggest my students aim for 100%, so the n worst case then can still score above 90%.

Recursive Binary Search Algorithm in Java - Example Tutorial

The binary search algorithm is one of the most famous search algorithms in computer science. It allows you to search a value in logarithmic time i.e. O(logN), which makes it ideal to search a number in a huge list. For example, in order to search a number in a list of 1 million number will take around 210 comparisons compared to 1 million comparison required by the linear search algorithm. Only thing is that the list must be sorted before you can use binary search algorithm and it must support index-based search. That's why binary search is often implemented using an array because doing a binary search with linked list will not be fast because it doesn't provide index-based access i.e. O(1) access. You have to traverse to that element to read its value in linked list which is O(n), effectively reducing the performance of binary search to a sequential search algorithm.

Top 10 Java books of last 5 Years For Experienced Programmers

If you think you have read all important books on Java and don't have anything new to read then hang on. Java is changing continuously, now Java 9 is on the way, but more importantly, it has already changed a lot in last 5 to 6 years with major releases like Java 8 and some useful features introduced in Java 7. Not only, the language is changing but also the Java virtual machine, Garbage collector, and other tools involved in Java development is changing, hence, it is now a right time to look at some of the newer Java books which are released in last 5 years to learn new features and tools of Java. Since I often receive emails and Facebook messages about some good books to read on Java, I thought to jot down books I have read in last a couple of years.

Can we declare a class Static in Java?

The answer to this question is both Yes and No, depending on whether you are talking about a top level class or a nested class in Java. You cannot make a top level class static in Java, the compiler will not allow it, but you can make a nested class static in Java. A top level class is a class which is not inside another class. It may or may not be public i.e. you can have more than one class in a Java source file and only needs to be public, whose name must be same as the name of the file, rest of the class or interface on that file may or may not be public. On the other hand, a nested class is a class inside a top level class. It is also known as the inner class or member class in Java.

Log4j Tips : Use MDC or Mapped Dignostic Context to distinguish logging per Client or Request

The MDC or Mapped Diagnostic Context is a concept or feature of Log4j logging library which can be used to group related log messages together. For example, by using MDC you can stamp a unique identification String like clientId or orderId on each log message and then by using grep command in Linux, you can extract all log messages for a particular client or order to understand exactly what happened to a particular order. This is especially very useful in multi-threaded, concurrent Java applications where multiple threads are simultaneously processing multiple orders from multiple clients.  In such applications, searching for relevant log messages in a big log file where log messages for multiple orders or clients are overlapping is a big task.

Difference between ArrayList and ArrayList<?> in Java - Raw Type vs Wildcard

One of my readers asked me about the difference between ArrayList vs ArrayList< in Java?>, which was actually asked to him on a recent Java development interview. The key difference between them is that ArrayList is not using generics while ArrayList is a generic ArrayList but they looks very similar. If a method accepts ArrayList or ArrayList<?> as a parameter then it can accept any type of ArrayList e.g. ArrayList of String, Integer, Date, or Object, but if you look closely you will find that one is raw type while other is using an unbounded wildcard. What difference that could make? Well, that makes a significant difference because ArrayList with raw type is not type safe but ArrayList<?> with the unbounded wildcard is type safe.

Difference between Abstraction and Encapsulation in Java - OOP

Both Abstraction and Encapsulation are two of the four basic OOP concepts which allow you to model real-world things into objects so that you can implement them in your program and code. Many beginners get confused between Abstraction and Encapsulation because they both look very similar. If you ask someone what is Abstraction, he will tell that it's an OOP concept which focuses on relevant information by hiding unnecessary detail, and when you ask about Encapsulation, many will tell that it's another OOP concept which hides data from outside world. The definitions are not wrong as both Abstraction and Encapsulation does hide something, but the key difference is on intent.

How to compare two XML files in Java - XMLUnit Example

The XMLUnit library can be used to compare two XML files in Java. Similar to JUnit, XMLUnit can also be used to test XML files for comparison by extending the XMLTestcase class. It is a rich library and provides a detailed comparison of XML files. Btw, comparing XML is completely different than comparing String in Java or comparing object using equals(), as two XML which contains different comment and whitespace can be equals, which is not true for String or character comparison. Also while comparing XML files, it's very important to know exactly which content or part is different and XMLUnit not only shows the content which is different but also XPath of elements which is getting compared.

Top 5 books to Learn Object Oriented Programming - Must Read, Best of Lot

The OOP or Object Oriented Programming is one of the most popular  programming paradigms which helps you to organize code in re the l world system. It's a tool which helps you to write complex software by thinking in terms of objects. Unlike its predecessor procedural programming paradigm which is implemented most notably by C, which solves the problem and complete task by writing code for computers, OOP style of programming allows you to think in terms of real world objects which has both state and behavior. You can view anything as objects and then find their state and behaviors, this will help you to simulate that object in code.

10 Examples of CUT command in UNIX and Linux

The cut command in UNIX is a nice utility program which allows you to cut data from a text file. The Linux cut command allows you to cut data by character, by field or by column. if used correctly along with sed, find, or grep in UNIX, the cut can do lots of reporting stuff. For example, you can extract columns from a comma separated file or a pipe or colon delimited file using cut command. For example, if you are only interested in first two columns you can show them using this command.  In this Linux cut command tutorial we will see different options of cut command, different examples of Linux cut command and some important points about cut in UNIX.

Java Program to Multiply Two Matrices - Matrix Multiplication Example

How to write a Java program to multiply two matrices in Java is a very good programming exercise to get familiar with the two-dimensional array in Java. this example teaches about how to multiply arrays, how to access elements from a multi-dimensional array, how to pass them to a function etc. Since the matrix is a natural representation of multi-dimensional array in Java, they are often used to illustrate real word matrix exercises e.g. the calculating sum of two matrices or calculating the difference of two matrices etc. By the way, before writing the program, let's recap how to multiply two matrices in mathematics first. If you remember, you can only multiply two matrices if, and only if, the number of columns in the first matrix equals the number of rows in the second matrix. That is known as matrix multiplication criterion.

How hostname to IP address Conversion or Name Resolution works in Linux?

One of my favorite Linux Interview questions is about how to convert hostname to IP address in Linux? This questions not just test candidate's basic Linux command skills but also shows his understanding of how name resolution works in UNIX or Linux? Many developers, software engineers, and support professional don't really know how Linux converts an hostname into IP address or what happens when they type http://www.amazon.com in their browser in UNIX? They are not really familiar with how the name amazon.com is resolved to an IP address. Since network application only works with IP address and names are for us humans, who find it easier to remember a name than IP address, it makes sense to understand how this name resolution happens. Sometimes, this question also asks as for how nslookup or host command works, which are two of the popular command to convert hostname to IP address.

JAXB Date Format Example using Annotation | Java Date to XML DateTime String Conversion

One of the common problem while marshaling Java object to XML String using JAXB is the default format of date and time provided by JAXB. When JAXB converts any Date type object or XMLGregorianCalendar to XML String, precisely xsd:dateTime element, it by default prints unformatted date e.g. 2012-05-17T09:20:00-04:30. Since most of the real world, Java application has a requirement to print date in a particular format like dd-MM-yyyy or include date and time in format dd-MM-yyyy HH:mm:ss, it becomes a problem. Thankfully, JAXB is very extensible and provides hooks and adapters to customize marshaling and unmarshaling process. You can define an extension of XmlAdapter to control and customize marshaling and unmarshaling or any Java type depending upon yours need.

10 Examples of Optional in Java 8

Null is bad, it can crash your program. Even it's creator called it a billion dollar mistake hence you should always try to avoid using nulls whenever you can. For example, you should not return a null String when you can return an empty String, similarly never return null collections when you can return an empty collection. I have shared many such tips in my earlier article, 10 tips to avoid NullPointerException and my reader liked that a lot. But, I wrote that article a couple of years ago when Java 8 was not around and there was no Optional, a new way to avoid NullPointerException in Java, but, things has changed now. Java SE 8 style of coding is rapidly becoming the de-facto coding style in many companies and as a Java developer you should also learn and embrace the good things of Java 8 e.g. lambda expression, streams and of course the Optional.

Does making all fields Final makes the class Immutable in Java?

One of the common misconceptions among many Java Programmer is that a class with all final fields automatically becomes Immutable. This is not correct, you can easily break immutability of certain class if the final field it contains is a mutable one, as we'll see in this article. One of the most common examples of this is a java.util.Date fields e.g. birthDay, expirtyDate, or joiningDate sort of fields. You have to be extra cautious to keep your class' immutability intact with mutable fields. The most common mistake in this regard happens when Java programmer return reference of the original object when a client ask e.g. getBirthDay() returns the date object pointed by birthDay field. When you return a reference to a mutable object, you are sharing ownership of that reference with whoever receives it. This can break invariant, such as immutability.