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.

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 application.properties 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.

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.

Sunday, June 16, 2019

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.

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 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.

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.