Thursday, April 20, 2023

How to Fix org.springframework.jdbc.BadSqlGrammarException: Implicit conversion from data type varbinary to date is not allowed

Hello Java programmers, if you are using JdbcTemplate of Spring Framework to interact with the database from Java program and getting "org.springframework.jdbc.BadSqlGrammarException: Implicit conversion from data type varbinary to date is not allowed" error then you have come to the right place. Earlier, I have taught you how to use JdbcTemplate in Java and Spring, and in this article, I will teach you how to fix "org.springframework.jdbc.BadSqlGrammarException: Implicit conversion from data type varbinary to date is not allowed" error in Spring-based Java application. 

How to use @RequestBody and @ResponseBody Annotations in Spring? Example Tutorial

Hello Java programmers, if you are wondering how and when to use use the @RequestBody and @ResponseBody annotation in Java then you are at the right place. Earlier, I have shared how to create RESTful Web Service using Spring Boot and today I will teach you how and when to use these two crucial annotations @RequestBody and @ResponseBody. While developing client server Java application using Spring Framework you may need to connect the HTTP request and response body with the domain object while working on the REST API. The annotations @RequestBody and @ResponseBody in Spring were used to bind these HTTP requests and responses. In simple words, these are the annotations which converts JSON to your Java object and your data to JSON while sending to client. Let's look at these two Spring annotations in more detail.

Top 5 Common Spring Bean Exception, Error and Solution [BeanDefinitionStoreException, NoSuchBeanDefinitionException, BeanCreationException]

Hello guys, error handling and troubleshooting is an important skill for Java developers. During development you can get variety of exception and sometime they are quite difficult to solve especially if you have no clue what they are and what causing them. Things can be even more difficult if exception is coming from the framework you are using like Spring Framework or Hibernate, that's why its important to know common error and exception for standard framework like Spring. In this article I will explain what BeanDefinitionStoreException, BeanCreationException, NoSuchBeanDefinitionException and BeanDefinitionOverrideException are, what can cause them and how to fix those problems.

Spring Boot @Autowired Example - How Autowiring of Beans works in Spring?

Hello guys, if you are wondering how to use @Autowired annotation in Spring Boot and how auto-wiring works in the Spring framework and how the Spring framework magically finds dependency and relevant beans to inject into your program then you have come to the right place. In the past, I have shared how Spring MVC works and in this article, I am going to explain how auto-wiring works in spring and how you can use @Autowired annotation for auto-wiring dependencies in your code. In Spring, you need to know the most important things before starting your coding. From spring 2.5 onwards, the annotations-driven dependency injection was introduced and it is used to inject collaborating beans into the beans. So in this tutorial, we are going to explain how does auto wiring work in spring.

How to use @ModelAttribute in Spring MVC? Example Tutorial

Hello guys, there are many annotations in Spring boot which  I have shared 5 essential Spring Boot annotations earlier and from those, the @ModelAttribute takes a special place as this helps to bind a method parameter or method return value to a named model attribute then exposes it to a web view. So we are going to discuss what is @ModelAttribute in Spring MVC with an example given below.  The @ModelAttribute annotation refers to a Model object attribute (the M in MVC ;). The @ModelAttribute annotation is special to Spring-MVC and is used to prepare model data. It's also used to specify the command object that'll be tied to the data from the HTTP request.

How to calculate GCF and LCM of two numbers in Java? Example

This week's programming exercise is to write a Java program to calculate GCF and LCM of two numbers. The GCF stands for a Greatest common factor and LCM stands for Lowest common multiplier, both are popular mathematical operations and related to each other. The GCF is the largest number which divides both the number without leaving any remainder e.g. if two numbers are 24 and 40 then their GCF is 8 because 8 is the largest number which divides both 24 and 40 perfectly, without leaving any remainder. 

Wednesday, April 19, 2023

10 Reasons to Learn Rust Programming Language in 2024

Hi there! If you're reading this, you're probably considering learning a new programming language, and you're wondering if Rust is the one for you. Well, buckle up, because I've got ten reasons why Rust is worth your time and effort. Rust is a modern systems programming language that offers a unique combination of speed, safety, and fun. It was created to solve the problem of low-level programming languages like C and C++, which are prone to security vulnerabilities and can be difficult to use effectively. With its focus on performance and safety, Rust is quickly becoming one of the most popular programming languages in the world, and for good reason.

Template Method Design Pattern in Java? Example Tutorial

Template Method Pattern defines a sequence of steps of an algorithm but let you free to implement those steps on your way. You cannot change the algorithm but you can define how those steps should behave. To make sure that you cannot change the algorithm, template methods are usually made final in Java, which is also a good use case of when to make a method final in Java. The subclasses are still  allowed to override the steps but as I said, they are not allowed to change the sequence. It can also be provided a default implementation for one or more steps. Let us look at the following example to understand Template Method Pattern.  A Template method pattern provides a skeleton for performing any sort of algorithm or an operation, and it allows the sub-classes to re-define part of the logic. 

How to create Immutable List, Set, and Map in Java? List.of(), Set.of() and Map.of() Examples

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

Why Singleton is Anti Pattern in Java Now and Why you should avoid it? Example

There was a time when the Singleton pattern was the darling pattern of many developers. It's a unique feature to keep certain services available globally, makes it very useful in all kinds of applications. It was also one of the most used design patterns among Java developers. I think the main reason for the Singleton pattern's popularity of designing the application is that there is always one instance of the most important service like Manager and Data Access classes. Still, with the adoption of Dependency injection, Singleton slowly faded away, and now it's considered an anti-pattern in Java applications. 

Difference between 32-bit and 64-bit JVM in Java?

One of the rather new or latest Java interview question is, "What is the difference between 32-bit and 64-bit JVM? or, How do you choose between 32-bit vs 64-bit JVM? or When to use 32-bit or 64-bit JVM? Some interviewer also use this concept to trick candidates by asking what would be the size of int variable in 32-bit and 64-bit Java? As mentioned in 130+ Java questions from last 5 years. Another tricky questions is, does same Java program can run on both 32-bit and 64-bit JVM? Short answer of this question is that Java is platform independent and same Java program will run absolutely fine in both 32-bit and 64-bit JVM. The real difference comes in addressable memory or heap memory. 

Tuesday, April 18, 2023

10 Reasons To Learn HTML and CSS in 2024

Hello guys, if you want to become a web designer, a web developer or a just a fullstack developer but not sure if you have to learn HTML and CSS then you are not alone, many people have similar doubt especially those who want to become a frontend or backend developer . If you're looking to build websites or become a web developer, you'll definitely want to learn HTML and CSS. HTML (Hypertext Markup Language) and CSS (Cascading Style Sheets) are the foundation of all websites, and without them, the web as we know it would not exist. But why should you learn HTML and CSS? Let's take a look at 10 reasons why HTML and CSS are worth your time and attention.

How long it take to learn Blockchain?

Blockchains are obviously one of the unique technologies in the industry right now. Experts have pointed out that Blockchain could generate revenue of around $39 billion by 2025. In addition, Blockchain also offers significant opportunities for development. You can learn Blockchain and become a certified blockchain developer, smart contract developer or blockchain engineer. Unique features of Blockchain, such as decentralization and immutability, could help in developing unique tamper-proof records of transactions on a decentralized network of computers.

How to use Lombok in Java? Lombok @Data and @NonNull Annotations Examples

Hello Java programmers, if you have been doing professional Java development, you may have heard about Lombok library, one of the most popular Java libraries among professional Java developers, making coding in Java much more fun and rewarding. Java has always been criticized for its verbosity, and many programming languages like Scala and Groovy are invented to solve that problem, but Lombok solves that problem in Java itself. This means you don't need to learn a new programming language, but you can use the Lombok library and its annotations to write clear and concise code in Java. 

Switch case vs if-else-if vs Polymorphism in Java - Example Tutorial

Hello guys, conditionals like if-else and switch are very important for programming. After all, programming is for decision making and that's where these conditional programming elements help, but you may have heard that excessive use of if-else and switch is bad and is often taught as code smell. So does that mean, should you never use a switch case in Java? In this article, I will share my thoughts about using switch case vs if-else and then whether we can use Polymorphism to replace if-else in Java and Programming, but before that let's see what is a switch constructor in  Java. A switch construct allows you to choose between multiple options depending upon input,