Tuesday, May 28, 2019

How to Create a thread-safe ConcurrentHashSet in Java 8? Example

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 the newly added keySet(default value) and newKeySet() methods to create a ConcurrentHashSet backed by ConcurrentHashMap in Java. This is better than old tactical solutions like using a 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() methods 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.

Monday, May 27, 2019

What is the Use of DispatcherServlet in Spring MVC Framework?

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. Btw, the DispatcherServlet is like any other Servlet is declared in the web.xml with a URL pattern but the only special thing is that the URL pattern for dispatcher servlet is enough to map every single web request to DispathcherServlert.

Sunday, May 26, 2019

Top 5 Node.js and Express JS online courses for Web Developers

There is no doubt that JavaScript is the #1 Programming language in the world and Node.js is one of the biggest reason for that. Initially, JavaScript was considered just a client-side scripting language but Node.js has changed all that by allowing developers to create dynamic web pages on the server side using JavaScript. It is also rated as the most popular framework of 2017 on StackOverflow Developers survey. The most important benefit of Node.js is that it allows you to build a full stack application based on just one language, JavaScript. This is especially useful for start-ups which put a lot of emphasis on being able to iterate early and often.

Friday, May 24, 2019

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 Spring questions on Java interviews? Since everybody is now moved or moving to annotation-driven and 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. If you don't know, 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.

What is the Role of InternalResourceViewResolver in Spring MVC? Interview Question

Earlier, I have explained to you about how Spring MVC works internally and how it process HTTP request coming to your web application. One of the important parts of that processing was view resolution, which is handled by the ViewResolver interface. In this article, you'll learn more about it by explaining the InternalResourceViewResolver class. 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.

Tuesday, May 21, 2019

How to find all Checked checkboxes in jQuery? Example Tutorial

Hello guys, suppose you have multiple checkboxes in your HTML page and you want to retrieve all checkboxes which are checked? How will you do that in jQuery? Well, you can use the pseudo selector like :checked to get all checked checkboxes. This selector checks for the checked property of checkbox and returns only those checkboxes which have this property. For example, following jQuery selector will return all the checkboxes which are checked:


In this, we are first selecting all input elements where type is a checkbox and then adding: checked to filter only those which are checked.

Monday, May 20, 2019

Top 10 ConcurrentHashMap Questions from Java Interviews

The ConcurrentHashMap class part of concurrent collections package added on JDK 1.5 which contains utility classes like 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 the scalability, ConcurrentHashMap uses advanced techniques e.g. dividing the map into segments to remain thread-safe and scalable at the same time.

Sunday, May 19, 2019

Top 5 Advanced SQL Books for Experienced Programmers - Best of lot, Must read

If you an experienced programmer and know how to write SQL queries and database fundamentals but want to take your SQL and database skills to the next level then you have a come to the right place. In this blog, I have shared a lot of free SQL books and courses you can use to start your SQL journey. This is also the second article about SQL books, In the first part, I have shared some of the best SQL books which are essential to learning SQL queries and fundamentals of database like normalization, indexing, and other design stuff, if you haven't read it yet, I suggest to do it now. You will find some amazing books to start learning SQL. In this article, I am going to share some of the best books to learn advanced SQL programming, which can help you to write better SQL queries and understand how database process those queries.

Saturday, May 18, 2019

Entuware or Whizlabs? Which Exam Simulator Should you Buy for Java Certifications (OCAJP, OCPJP, and Others)?

I often receive queries from Java certification aspirants about exam simulators like 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 with you both of them are really high-quality test simulators 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 the past I am sure about that in 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

Thursday, May 16, 2019

Java 9 Example - Factory Methods for Collection - Creating Unmodifiable List, Set, and Map

Hello guys, this is my first article in Java 9 features on this blog and today you'll learn about my favorite feature "factory methods for collection", which is introduced as part of JEP 269. The JEP stands for JDK enhancement proposal. If you have worked in Groovy or Kotlin then you know that how easy is to create the list with elements using collection literals e.g. to create a list of 1, 2, 3 you can simply write val items = listOf(1, 2, 3). Unfortunately, Java doesn't support that yet but things have been improved with the factory methods for collection in JDK 9 and it's almost like that. JDK has added static factory methods like of() on to basic Collection interfaces which you can use to create a list of items.

Wednesday, May 15, 2019

10 Differences between StringBuffer and StringBuilder in Java

Both 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 a character, or getting a substring, all results 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 as mutable String. That's the main difference between String vs StringBuffer and StringBuilder and also one of the frequently asked Java questions for beginners.

Tuesday, May 14, 2019

3 Ways to Learn Spring Core, Spring MVC, Spring Security, and Spring Boot Framework

If you are a Java developer and want to learn Spring framework then you have come to the right place. In this article, I will share three ways to learn the Spring framework, but before that let's understand what is a spring framework and why Java developers should learn Spring framework? Well, Spring is a framework that assists you to develop Java application by following some best practices, particularly the principle of dependency injection and inversion of control. As per this principle, instead of class asking for its dependency, the framework provides them at runtime.  Following these principles improves your code quality because it reduces coupling between different parts of your applications like between modules and classes, which makes it easier to test and develop.

Thursday, May 9, 2019

Difference between @Component, @Service, @Controller, and @Repository in Spring

Before you learn the difference between @Component, @Service, @Controller, and @Repository annotations in Spring framework, it's important to understand the role of @Component annotation in Spring. During initial release of Spring, all beans are used to be declared in an XML file. For a large project, this quickly becomes a massive task and Spring guys recognize the problem rather quickly. In later versions, they provide annotation-based dependency injection and Java-based configuration. From Spring 2.5 annotation-based dependency injection was introduced, which automatically scans and register classes as Spring bean which is annotated using @Component annotation.

Tuesday, May 7, 2019

How to declare and initialize a List (ArrayList and LinkedList) with values in Java - Arrays.asList() Example

Hello guys, today, I am going to share with you a useful tip to initialize a List like ArrayList or LinkedList with values, which will help you a lot while writing unit tests and prototypes. Initializing a list while declaring is very convenient for quick use, but unfortunately, Java doesn't provide any programming constructs like collection literals of Scala, but there is a trick which you can use to declare and initialize a List at the same time. This trick is also known as initializing List with values. I have used this trick a lot while declaring list for unit testing and writing demo programs to understand an API etc and today I'll you'll also learn that.

Sunday, May 5, 2019

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.