Saturday, June 29, 2019

How to enable Spring Security in Java Web application?

Spring Security is one of the most popular open source frameworks to implement security in Java web application in a declarative way. It provides several essential security features like 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.

Wednesday, June 26, 2019

What is SecurityContext and SecurityContextHolder in Spring Security?

The SecurityContext and SecurityContextHolder are two fundamental classes of Spring Security. The SecurityContext is used to store the details of the currently authenticated user, also known as a principle. So, if you have to get the username or any other user details, you need to get this SecurityContext first. The SecurityContextHolder is a helper class, which provide access to the security context. By default, it uses a ThreadLocal object to store security context, which means that the security context is always available to methods in the same thread of execution, even if you don't pass the SecurityContext object around. Don't worry about the ThreadLocal memory leak in web application though, Spring Security takes care of cleaning ThreadLocal.

Monday, June 24, 2019

The @SpringBootApplication annotation Example in Java + Spring Boot

Hello guys, today, we'll learn about the @SpringBootApplication annotation, one of the most important annotations from popular Spring Boot framework, which has changed the way Java developers use Spring framework for writing Java applications. In this article, I'll explain to you the meaning of @SpringBootApplication and it's used in a simple Spring Boot application. We use @SpringBootApplication annotation on our Application or Main class to enable a host of features e.g. Java-based Spring configuration, component scanning, and in particular for enabling Spring Boot's auto-configuration feature.

Sunday, June 23, 2019

Top 5 Best Java 8 Tutorials, Courses, and Books

It's been quite some time since the Java 8 was released but Java community is still buzzing with functional programming and lambda expression. Many developers, programmers, and bloggers have already shared lots of really good tutorial to learn lambda expressions, probably the biggest thing in Java world after Generic was introduced in Java 5. While the term "lambda expression" may sound abstract and academic, Java 8 Lambdas can have a big impact on how you program every day. Java 8 has not only introduced Lambda expressions but also Stream API, Functional interfaces, new Date and Time API and default methods, which has completely changed the way you write your Java code. As a professional Java developer, you will have to learn Java 8 one day, and it's better to do sooner than later.

Saturday, June 22, 2019

Difference between @ContextConfiguration and @SpringApplicationConfiguration in Spring Boot Integration Test

Even though both @ContextConfiguration and @SpringApplicationConfiguration annotations are used along with SpringJUnit4ClassRunner to specify how to load the Spring application context, there is a subtle difference between them. Although @ContextConfiguration does a great job in loading application context it doesn't take full advantage of Spring Boot features. Spring Boot applications are ultimately loaded by either SpringApplication ( in case of the JAR) or SpringBootServletInitializer. This class not only loads the application context but also enables logging and loading of external properties specified in or application.yml file, and other features of Spring Boot framework, which is not loaded or enabled by the @ContextConfiguration annotation. 

Friday, June 21, 2019

Top 5 Selenium + Cucumber Online Courses for Java Developers and Automation Testing Programmers

The days of manual testing is limited as more and more companies are shifting towards Automation testing. This means all manual testing QAs needs to learn new test automation skills like Selenium, Cucumber, JUnit, Mockito, and TestNG to give their career a boost. If you are manual testers or non-programming testers interested in learning test automation, a Java developer who wants to write a better integration test, or a freshers/graduates who want to kick start their career in automating testing then you have come to the right place. In this article, I am going to share some of the best courses to learn Selenium Webdriver with Java and other automation testing tools like JUnit, Cucumber etc.

Thursday, June 20, 2019

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 the controller, e.g., @RequestMapping, @RequestParam, and @PathVariable. Even though both @RequestParam and @PathVariable is used to extract values from the HTTP request, there is a subtle difference between them, which makes them a useful question from an 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.

Wednesday, June 19, 2019

Top 5 TensorFlow and Machine Learning Online Training Courses for Programmers

If you are curious about Artificial intelligence, Data Science, and Machine learning then I am sure you have heard about TensorFlow, Google's machine learning API, which they have used to develop the RankBrain algorithm for Google Search. TensorFlow is one of the most popular machine learning API which allows you to automate several real-world tasks, for example, you can use it for image detection. In fact, a Japanese farmer turned programmer used it to detect the best quality Cucumber, which only his father and mother can do it with his years of experience. That's the power of machine learning, which is now available to everyone because of TensorFlow.

Tuesday, June 18, 2019

Top 5 Java 8 and 9 Courses for Programmers (FREE) - Best of Lot

Hello guys, if you are looking for some free resources e.g. books, tutorials and courses to learn and master new features introduced in Java 8 and Java 9 then you have come to the right place. In past, I have shared some of the best Java 8 tutorials and books and in this article, I am going to share some of the best, free Java 8 and Java 9 courses from Udemy and Pluarlsight with you. These courses are pretty similar to many paid courses you normally buy and many of these are made free by just promotional or educational purpose by their instructor. You can join these courses to learn JDK 8 and JDK 9 features in a couple of days.

Monday, June 17, 2019

How to Crack Spring Core Professional v5.0 Certification - Latest Spring Certification for Java Programmers

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 has suddenly made 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 5 or Spring Professional 5 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.

Top 5 Android Online Training Courses for Java Developers - Best of Lot

Java has been very lucky that Android uses it as a programming language. This opened a big door of opportunities for Java developers in Android app development. Many people ask me why Java Developer should learn Android? My simple answer is that good knowledge of Android OS improves your chances of getting a job and making a difference in people's lives because Android Apps is the direct way to connect billions of people. Android is without a doubt THE biggest mobile platform in the world, with over 80% market share and over billions of devices running Android. By creating apps for such a big platform, you have a great opportunity to make a difference.

Sunday, June 16, 2019

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.

Top 5 Free Git Courses for Programmers to Learn Online - Best of Lot

One of my goals in 2018 is to learn and master Git and I have been searching for some good tutorials and courses to start with. The Internet is full of git tutorials and a simple Google search will leave you thousands of tutorials but the big question mark is where do you start? It's easy to pick a tutorial or a blog post if you have some background about what is Git, what it does? and how to use it but if you don't have much background then you need a course which can tell you all the information from the ground up. I personally like learning from a book or an online course before moving to blog posts as they were often well structured. When you search for Git courses in popular online course websites like Udemy, Pluralsight or Coursera, you will find some good courses like Git Complete: The Definitive Guide on Udemy and Git Fundamentals from Pluralsight which will teach you everything about Git step by step. These are excellent resources to start with Git.

Saturday, June 15, 2019

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)  because they are intended for human viewers while REST API just return data in form of JSON or XML because most of the REST clients are programs. This difference is also obvious in the @Controller and @RestController annotation.

Thursday, June 13, 2019

5 Tips to Prepare for Oracle Java Certifications (OCAJP and OCPJP)

Hello All, today, I am going to share some useful tips to prepare for Oracle's Java certifications like OCAJP and OCPJP, both associate and programmer level certification. These certifications are great for both mastering Java language as well as getting recognition for your skill which not only improves your chances of getting a Java development job but also helps you in your career growth. Though you need a bit of Java experience or knowledge to pass the exam. If you are completely new to Java then you need to first go through a comprehensive course like The Complete Java MasterClass on Udemy and learn how to program in Java, because getting certified without knowing how to program in Java is of no use.

Wednesday, June 12, 2019

Binary Tree PreOrder Traversal in Java - Recursion and Iteration Example

Unlike a linked list and array which are linear data structure and can only be traversed linearly, there are several ways to traverse a binary tree because of its hierarchical nature. The tree traversal algorithms are mainly divided into two types, the depth-first algorithms, and breadth-first algorithms. As their name suggests, in a depth-first algorithm, the tree is traversed downwards (towards the depth) before the next sibling is visited, the PreOrder, InOrder and PostOrder traversal of a binary tree is actually depth-first traversal algorithms. On the breadth-first algorithm, also known as level order traversal, the entire breadth of the tree is traversed before moving to the next level, hence it is also known as level order traversal.

Tuesday, June 11, 2019

10 Object-Oriented (OOP) Design Principles Java Programmer Should Learn in 2019

The Object-Oriented Design Principles are the core of OOP programming, but I have seen most of the Java programmers chasing design patterns like Singleton pattern, Decorator pattern, or Observer pattern, and not putting enough attention on learning Object-oriented analysis and design. It's important to learn the basics of Object-oriented programming like Abstraction, Encapsulation, Polymorphism, and Inheritance. But, at the same time, it's equally important to know object-oriented design principles. They will help you to create a clean and modular design, which would be easy to test, debug, and maintain in the future.

Tuesday, June 4, 2019

Top 20 Spring REST Interview Questions Answers for Java/JEE Programmers

Hello guys, I have been sharing some REST with Spring tutorials from last a couple of weeks and today, I am going to share some of the frequently asked Spring and REST interview questions to Java developers applying for Web developer roles. Since Spring Framework is the most popular and the standard framework for developing Java web application and RESTful Web Services, a good knowledge of Spring core and Spring MVC is expected from any senior Java developer, but if the job description mention about REST and Web Services, you also need to be aware of how to develop RESTful Web Services using Spring Framework. From Spring 3.1, the framework has been enhanced a lot to support many features needed for RESTFul API out-of-the-box e..g HTTPMessageConverter can convert your HTTP response to JSON or XML by just detecting relevant library in classpath e.g. Jackson and JAXB.

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

Sometimes we need to enable and disable input elements like text box, radio buttons, or checkboxes, but every time you make a change you need to reload the HTML? The question is, 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, you can grab the element you want to enable or disable and change this property by using the prop() or attr() function, depending upon the version of jQuery you are using.

Monday, June 3, 2019

Top 5 Spring Cloud Courses for Java Developers to Learn Online - Best Of Lot

Hello guys, if you are learning Spring Cloud for developing cloud-based Java application and looking for some good resources to start with e.g. online courses and books then you have come to the right place. In this article, I am going to share some of the best courses to learn Spring Cloud and develop a cloud-based application in Java. One of the common question when it comes to learning a new technology is how to start? I was a big fan of books earlier but nowadays I personally like to start with an online course to learn things.  It works better because you gain a lot from the instructor's experience and you also have a chance to ask questions to the instructor.

Sunday, June 2, 2019

How to Check/Uncheck CheckBoxes in a Page using jQuery? Example Tutorial

In the last couple of articles, I have shared a couple of useful jQuery tips like reloading web page and working with tag selectors. Today, I'll show you how to check or uncheck a particular checkbox using jQuery, one of the most popular JavaScript framework. jQuery provides CSS like selectors which can make this kind of task trivial. 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() you 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 checkbox unchecked.

How to Sort a HashMap by Values in Ascending and Descending Order in Java 8 - Example Tutorial

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.