Thursday, March 30, 2023

Difference between First and Second Level Cache in Hibernate [Answer]

If you have used Hibernate in past then you know that one of the strongest points of the Hibernate framework is caching, which can drastically improve the performance of the Java application's persistence layer if configured and used correctly. Hibernate provides caching at many levels e.g. first level cache at Session level, second-level cache at the SessionFactory level, and query cache to cache frequently executed SQL queries. The first level cache minimizes database access for the same object. For example, if you call the get() method to access Employee object with id = 1 from one session, it will go to the database and load the object into memory, but it will also cache the object in the first-level cache.

Wednesday, March 29, 2023

Difference between get and load in Hibernate

get vs load in Hibernate
Difference between get and load method in Hibernate is one of the most popular questions asked in Hibernate and spring interviews. Hibernate Session class provides two methods to access object e.g. session.get() and session.load() both looked quite similar to each other but there are subtle differences between load and get method which can affect the performance of the application. The main difference between get() vs load method is that get() involves database hit if an object doesn't exist in Session Cache and returns a fully initialized object which may involve several database calls while load method can return proxy in place and only initialize the object or hit the database if any method other than getId() is called on persistent or entity object.

Monday, March 27, 2023

Difference between save vs persist and saveOrUpdate in Hibernate

Save vs. saveOrUpdate vs. persist in Hibernate
What is the difference between save and saveOrUpdate or Difference between saving and persist are common interview question in any Hibernate interview, much like the difference between get and load method in Hibernate. Hibernate Session class provides a couple of ways to save an object into the database by methods like save, saveOrUpdate, and persist.  You can use either save(),  saveOrUpdate() or persist() based upon your requirement for persisting objects into the database. The key thing is that all these objects are used to store data into the database but they also make a transient object persistent in Hibernate.

Saturday, March 25, 2023

How to send HTTP POST Request with JSON Payload to REST API using Curl Command?

There are many ways to test your RESTful Web services developed using Spring MVC e.g. you can use RESTAssured for automation testing or you can use Postman to manually test your RESTful Web service but nothing beats the elegant, comfort, power, and simplicity of using curl command to test RESTful web service. It is my favorite tool to test any RESTful web service and I have used in past to test various aspect of Spring REST application e.g. testing headers, testing authentication and authorization, testing different content types like JSON and XML, testing cookies, and testing different HTTP methods to perform CRUD operations. 

Friday, March 24, 2023

Difference between REST and GraphQL API with Example

Hello guys, I have been learning GraphQL since last week and should I say, I am really impressed with its flexibility and how it address some of the pertinent problems with REST APIs. If you don't know, The GraphQL is a query language from Facebook which aims to solves some common problems with REST like a explosion of endpoints, over fetching and under fetching of data, response structure, versioning, and most important performance and Scalability. If you have used REST APIs then you know that you need to send a lot of request to get the data you want. You not only need send multiple request but also you get a lot of unnecessary data which you don't really need, and also need to know multiple endpoints. 

Thursday, March 23, 2023

Top 5 Tools for Testing REST APIs and RESTful Web Services in 2024 - Best of Lot

Hello guys, If you are a Java or web developer working on REST APIs and RESTful web services and looking for some tools to test your APIs and web services then you have come to the right place. Earlier, I have shared the best books and courses for RESTful web services and in this article, I am going to share five awesome but easily accessible and free tools to test your REST APIs. These REST API testing tools will help you to test your APIs as you build, starting from unit testing to integration testing and then fully automating your resting to create a regression pack. You can also use these tools to interact with your REST API during the development phase for quick tests. 

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.

7 Reasons to use Spring Framework for Creating RESTful Webservices in Java

REST has now become a standard way to develop web services and when it comes to Java, there are many frameworks and libraries available like JAX-RS, Restlet, Jersey, RESTEasy, Apache CFX, etc, but I encourage Java developers to use Spring framework to develop RESTful web services. But, some of you might ask, why use Spring Framework to develop RESTful web services in Java? What is the advantage and why it's better than other frameworks and libraries available out there? Well, the most important reason I think to use Spring for developing RESTful web service is that you can use your Spring MVC experience to develop RESTful web services.

Eclipse - How to Fix java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in Tomcat

Problem: You are getting java.lang.ClassNotFoundException exception complaining that Spring's DispatcherServlet class is not available in the classpath. This error is coming while running a Spring MVC based Java application from Eclipse and Tomcat as Server (running inside Eclipse IDE itself). You have either included spring framework JAR files manually by yourself or you are using Maven to download and manage dependent JAR files. Here is the stack trace of this error :

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:525)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:507)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:126)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1043)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957

Wednesday, March 22, 2023

How View Resolver works in Spring MVC? [InternalResourceViewResolver Example]

Hello guys, if you are wondering what is view resolver in Spring MVC and what role InternalViewResolver class plays in Spring MVC then you have come to the right place. Earlier, I have explained to you how Spring MVC works internally and how it processes HTTP requests coming to your web application. One of the important parts of that processing was resolving views, which is handled by the ViewResolver interface, which is the V part of MVC. They are responsible for returning correct views to the client, both in the Spring MVC application as well as on REST APIs. In this article, you'll learn more about view resolvers in Spring MVC by explaining the InternalResourceViewResolver class. 

Tuesday, March 21, 2023

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

Monday, March 20, 2023

Spring Boot + Hibernate Tutorial and Example for Java Developers

Hello guys, if you want to learn how to use Spring Boot and Hibernate together in a Java application and look for examples and tutorials then you have come to the right place. In the past, I have shared how to use Spring Boot with MyBatis and Spring Boot + Redis example and In this article on Spring Boot, we will discuss how to integrate Spring Boot with Hibernate. We will build a simple Spring Boot application and use Hibernate to store the data. So first, let's look at what is Hibernate in Java? Hibernate framework provides an abstraction layer which means programmers need not worry about implementation. Hibernate will implement different modules for developers internally like writing queries to perform CRUD operations on the database and establishing connections to different kinds of databases. This is a Java-based solution for object-relational mapping.

Saturday, March 18, 2023

Difference between @ContextConfiguration and @SpringApplicationConfiguration in Spring Boot Testing?

Hello folks, what is the difference between @ContextConfiguration and @SpringApplicationConfiguration is one of the frequently asked Spring Boot Testing interview questions which is often used to check if the candidate knows about how to unit test Spring boot application. 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 the case of the JAR) or SpringBootServletInitializer

What is @SpringBootApplication Annotation in Java and Spring Boot? Example Tutorial

Hello guys, if you are wondering what is @SpringBootApplicaiton annotation and how to use it then you have come to the right place. Today, we'll learn about the @SpringBootApplication annotation, one of the most important annotations from the popular Spring Boot framework, which has changed the way Java developers use the Spring framework for writing Java applications. In this article, I'll explain to you the meaning of @SpringBootApplication and its use 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.

Difference between BeanFactory and ApplicationContext in Spring Framework

The difference between BeanFactory and ApplicationContext in Spring framework is another frequently asked Spring interview question mostly asked Java programmers with 2 to 4 years experience in Java and Spring. Both BeanFactory and ApplicationContext provide a way to get a bean from the Spring IOC container by calling getBean("bean name"), but there is some difference in their working and features provided by them. One difference between the bean factory and application context is that the former only instantiates bean when you call getBean() method while ApplicationContext instantiates Singleton bean when the container is started,  It doesn't wait for the getBean to be called. 

Thursday, March 16, 2023

What is a Spring Data Repository? JpaRepository, CrudRepository, and PagingAndSortingRepository Example

Hello Java developers, if you are wondering what is Spring Data Repository interfaces like JpaRepository, CrudRepository, and PagingAndSortingRepository and how to use them then you have come to the right place. Earlier, I have shared the best Spring Data JPA courses and in this article, I will give you an overview of different Spring Data Repository interfaces and how to use them with step-by-step examples. The Java Persistence API (JPA) is the standard way of persisting java objects into relational databases. 

Wednesday, March 15, 2023

How to transpose a Matrix in Java? Example Tutorial

Hello guys, if you are wondering how to transpose a matrix in Java then you have come to the right place. Matrix related coding problems are great way to learn multi-dimensional array and nested loop and they are good programming exercise for beginners. In the past, I have taught you how to multiply matrices in Java and how to add/subtract matrices in Java, and in this article, I will show you how to create transpose of a given matrix in Java, but before that let's first understand what is transpose of a matrix means and how do you transpose a matrix in maths? Well, a transpose of a matrix is nothing but a matrix whose rows and columns are reversed. 

Why use @Override annotation in Java? Coding Best Practice Example

@Override annotation was added in JDK 1.5 and it is used to instruct the compiler that method annotated with @Override is an overridden method from super class or interface. Though it may look trivial @Override is particularly useful while overriding methods that accept Object as a parameter just like equals, compareTo or compare() method of Comparator interface. @Override is one of the three built-in annotations provided by Java 1.5, the other two are @SuppressWarnings and @Deprecated

Friday, March 10, 2023

How to use MyBatis in Spring Boot application in Java? Example Tutorial

Hello guys, In this tutorial, we will discuss how to create a spring boot project with MyBatis. First, you need to have a better understanding of what is MyBatis and its use-cases. MyBatis is a SQL mapping framework with support for custom SQL, stored procedures, and advanced mapping. Although Spring Boot does not officially support MyBatis, the MyBatis community has created a Spring Boot startup for MyBatis.This is the most commonly used open-source framework for implementing SQL databases access in java applications.

Thursday, March 9, 2023

Top 16 JMS (Java Messaging Service) Interview Questions and Answers

Java messaging Service or JMS interview questions is one of the important parts of any Core Java or J2EE interview as messaging is a key aspect of enterprise Java development. JMS is a popular open-source Messaging API and various vendors like Apache ActiveMQ, Websphere MQ, Sonic MQ provides an implementation of Java messaging API or JMS. Any Java messaging services or JMS interview can be divided into two parts where the first part focuses on fundamentals of JMS API and messaging concept like What is topic, What is Queue, publish-subscribe or point to point model, etc, While the second part is related to JMS experience with particular JMS provider.

Top 20 Questions Candidate Should Ask in Programming Job Interviews?

From the first round to HR round, from telephonic to face-to-face, in almost all kind of programming interviews, there will be a time when Interviewer will give you a chance to ask questions. Many programmers are too concern about asking questions, and they politely decline ; Well it's your chance to learn about the Job you are going to do, and you shouldn't let this opportunity goes away. The interviewer, also judges you by your questions; a good, thoughtful, positive question can create the great impression on Interviewer's mind. It also shows that  the interest of a candidate for a Job.

Monday, March 6, 2023

How to reload/refresh a page using JavaScript and jQuery? Example

Hello guys, if you are wondering how to reload or refresh a web page then don't worry 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 the browser's cache, which may or may not represent the current version at the server.

Sunday, March 5, 2023

Top 10 Scala and Groovy Frameworks Java Developers can learn in 2024 - Best of Lot

Hello guys, Groovy and Scala have been around for some time. Some useful Groovy and Scala frameworks can help Java developers create better applications and products like Microservices et al. l. If you are interested in learning the best Scala and Groovy framework, then you have come to the right place. In the past, I have shared the best courses to learn Scala and Groovy, and In this article, we are going to take a look at some of the best Scala and Groovy frameworks that can be useful in Java development  Akka, Lagom, Play, Spock, Gradle, and Grails. I'll also share links to some valuable courses to learn these practical Groovy frameworks.

How to redirect a page or URL using JavaScript and JQuery - Example

Redirecting a web page means, taking the user to a new location. Many websites uses redirects for many different reasons, e.g. Some websites redirect users from the old domain to new domain, some redirect from one page to another e.g. a more relevant page. If you are a Java programmer and worked previously with Servlet and JSP, then you might be familiar with SendRedirect and Forward methods, which are used to redirect users in web applications. Actually, there are two kinds of redirect, Server side redirect, and client-side redirect. In Server side redirect, the server initiates redirection, while in a client-side redirect, the client code does the redirection. Redirecting a web page using JavaScript and JQuery is a client-side redirection.

Top 10 Udemy Courses for Python, JavaScript and Web Development in 2024 - Best of Lot

Hello guys, Udemy, one of the most popular online learning platforms, is known for its sale where you can buy a $200 course for just $10, and they are running a sale now. It's actually an excellent time to buy some quality courses as you won't get another chance to buy the course at a price as low as $9.9, but the big question is which courses you should buy on Udemy in 2024? I always purchase courses from the reputed instructor and teach evergreen and in-demand skills like Java, Python, Microservices, Docker, Kubernetes, and AWS. I generally buy a lot of courses in Udemy sales and then access them whenever I need them. Though, I must warn you Udemy is addictive, and I often buy more classes than I need, so beware of that and buy courses you need now or shortly.  

Friday, March 3, 2023

Top 8 Courses to Learn about NFTs (Non Fungible Tokens) in 2024 - Best of Lot

Hello guys, if you want to learn what is NFT or Non Fungible Token and what is the buzz around NFT, and have questions like should you create and sell NFT etc then you have come to the right place. Earlier, I have shared best online courses to learn Blockchain and crypto currencies and in this article I am going to share best online courses to learn NFTs, but before that, let's understand what is NFT?  NFTs or else known as Non-Fungible Tokens are a form of digital art. Non-Fungible basically means that they are unique. If you own one NFT, there’s nothing else in this world that is the same as yours. Nothing! That uniqueness and sense of ownership is driving crazy sales with recent reports suggesting that NFT sale clocking at around $70 million and increasing exponentially.

Thursday, March 2, 2023

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

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> tags 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 the top 10 programming languages, each of them is an <li> item. We also have one button, "Click Me", which will when clicked, change all <li> item's text to "jQuery is the new Boss". Here is the jQuery code, which does that.

7 jQuery Selectors Examples for Beginners - Tutorial

jQuery selectors are like CSS Selectors, which allow you to find or select an element from the DOM tree. When HTML pages loaded in a browser like Chrome, Firefox, or Internet Explorer, the browser creates a tree-like structure is known as Document Object Model or DOM. JavaScript and jQuery allow you to play with this DOM i.e. selecting elements from DOM, traversing through DOM, going from one element to another, selecting a list of elements from DOM, adding or removing elements from DOM, etc.

Top 10 Free Courses to learn Spring Framework and Spring Boot in 2024 - Best of Lot

Hello guys, if you want to learn Spring Framework and looking for best online resources like books, courses, and tutorials then you have come to the right place. Earlier, I have shared best Spring Framework courses, books, and Spring interview questions and in this article, I am going to share best free courses to learn Spring framework in 2024. When I shared the list of best Spring Courses, a lot of you asked me about free spring courses and this article is the result of that research, but before we get to the 10 best free Spring courses that are perfect for beginners, let me tell you more about what the Spring Framework really is.

Top 16 Lambda Expressions + Stream Interview Questions Answers for Experienced Java Programmers

For a long time my readers were asking about some Java 8 interview questions, particularly on lambda expression, streams and around language changes e.g. default methods, method reference and functional interface. Finally, I am able to put some common Java 8 interview questions on lambda expression and Stream API and essential functional programming concepts like map, flatmap, and reduce together, which I going to share with you in this article, but before that, let's talk a little bit about impact of Java 8 in Java Developers interviews and why it's imperative for Java programmers to learn Java 8, particularly Lambda and Stream API

How to find all unchecked checkboxes from a page using jQuery? Example Tutorial

Hello guys, In the last tutorial, you have learned how to get all the checked checkboxes from a page using jQuery, but sometimes you also need all the checkboxes which are not selected. In this tutorial, you will learn that. If you remember, we have used the:checked pseudo selector to get all checked checkboxes, but, unfortunately, there is nothing like the :unchecked selector in jQuery, so using that will result in the syntax error. Even the!:checked or :!checked will not work, instead, you need to use not() jQuery selector, which does the negation job.

How to find a Good Programmers on Tech Interviews?

When it comes to interview, goal is to find the most suitable developer for job to get done but its very difficult to judge someone's caliber, experience and expertise in short duration of Interview. There is always a process starting from phone interview, written tests to face-to-face interview, but its still difficult to hire the right programmer. Process can help you to filter candidates but eventually it will come down to your experience and gut feeling. As you take more and more interviews, you will know what to ask and what not and like many other interviewers in the world, you will develop some of your own tips. Similarly, I have developed couple of tips from my experience which has helped me to differentiate an average programmer with a good programmer in past.

Top 5 Courses to Learn Recursion for Dynamic Programming in 2024 - Best of Lot

Hello guys,  if you want to learn and Master Recursion and looking for the best resources like books, online courses, and tutorials then you have come to the right place. Earlier, I have shared the best dynamic programming courses, and 15 Recursion exercises for beginners, and today, I am going to share the best courses to learn Recursion for beginners. Recursion is the process by which a function calls itself again and again directly or indirectly. These types of functions are called recursive functions. All successful software programmers need to have an understanding of how recursive functions work as well as how to build recursive functions. 

Top 10 Dynamic Programming Problems from Coding Interviews

Dynamic Programming is one of the toughest concepts to master for programmers but at the same time, it's quite important to crack any programming job interviews. Nowadays, you will find at least one Dynamic programming coding problem on every coding interview and that's where most of the programmers get stuck. They try to solve the problem using techniques like divide and conquer but ultimately fail because it's difficult to come to a solution to such problems unless you have solved a decent number of dynamic programming-based coding questions. This is very similar to system design questions which look easy but when you try to solve them you often find yourself stuck and that's why I suggest you practice as much as possible. 

Wednesday, March 1, 2023

How to Fix 'javac' is not recognized as an internal or external command in Windows and Linux? Example

Hello guys, if you are trying to compile your Java source file and getting "'javac' is not recognized as an internal or external command" in Windows or Linux machine like Windows 10 or Redhat 8 but not sure what to do then you have come to the right place. This is a common Java related error and can occur to an operating system like Windows, Mac or Linux if java is not installed properly like only JRE is installed and JDK is not installed or javac is not added on PATH environment variable. In this article, I will explain what this error is and how you can fix it by following step by step guide I share, but if you still cannot solve this problem on your own then just ask for help in comments. But don't forget to check your PATH environment variable because that's where JDK/bin directory needs to be present, which contains all Java related commands including "javac" and "java" which are used to compile and run Java applications.