Sunday, April 30, 2023

How to Join Two or More Tables in a SQL query? Left Join Example Leetcode Solution

Hello guys, when it comes to combining two tables in SQL, many programmers don't know that they can use the JOIN clause. In fact, JOIN is there to fetch data from multiple tables together. There are mainly two types of joins, INNER Join and OUTER join. On Inner join, only those records have matching values in both tables, while in Outer join, all records from one table are selected in addition to matching records from other tables. There are two kinds of Outer join in SQL, LEFT OUTER JOIN and RIGHT OUTER JOIN. Both are actually the same thing, which means you can get the same result by using either of the outer joins by changing the table's position from left to right.

How to create RESTful Web Services in Java using Spring Boot? Example Tutorial

Hello guys, if you are looking for a complete tutorial to create REST API on Spring Boot then you have come to the right place. In the past, I have shared the best RESTful Web Services courses and best Spring Boot courses and in this article, I am going to show you how to create RESTful web services using Spring Boot step by step. After going through this tutorial you will be able to create your own REST endpoints and RESTful application using Spring Boot and Spring Framework and Java programming language. How to make Spring boot REST API? is a common question that everyone has who is new to Spring boot application development. 

What is Spring Expression Language (SpEL)? Difference between $ and # in @Value expressions Example

Hello Java programmers, if you are wondering what is Spring Expression Language and how to use them in your Spring Framework or Spring Boot application then you have come to the right place. Earlier, I have shared the best Spring Framework coursesFree Spring Questions, Spring projects, and books, and in this article, I am going to teach you about Spring Expression Language with simple, easy-to-understand examples. The Spring Expression Language (SpEL for short) is a powerful language that supports querying and manipulating an object graph at runtime. The syntax is similar to Unified EL, but it has several more features, such as method calling and rudimentary string templating.

What is SRP or Single Responsibility Principle Example in Java? SOLID Design Pattern Example

Hello guys, if you want to learn about SRP or the Single Responsibility principle and wondering how to write code that follows SRP and what are pros and cons of following this design principle then you have come to the right place. Earlier, I have shared the best object-oriented programming and design courses and books and in this article, I am going to talk about SPR. The Single Responsibility Principles, popularly known as SRP is part of 5 Object-oriented design principles, introduced by Robert C. Martin, popularly known as Uncle Bob. The Single Responsibility principle says that "there should be one reason to change a class". This means a class should do only one thing, and do it perfectly.

[Solved] How to Find maximum Product of a sub-array in Java? Example

Hello guys, if you are asked to find maximum product of a sub-array in Java and you are wondering how to solve this difficult looking coding problem then you have come to the right place. Earlier, I have shared 30 array coding problems, 30 linked list problems, and 10 dynamic programming problems and in this article, we shall be finding the maximum product of a sub-array in java. This problem has a lot to do with arrays. But first, we'll solve the problem then we talk about Array and how it operates. The problem we are to solve here is to find the maximum product of a subarray in Java. We won't just jump to the writing of codes like code monkeys but, it is essential to understand the problem we are solving first, so we can give the best approach in solutions to it. when we say finding the maximum product of a sub-array it means getting the total of a product in an array!

How to check if a given Tree is a Binary Search Tree in Java? Example Tutorial

Hello guys, if you are preparing for a coding interview then you may know those binary tree problems are not easy to solve on coding interviews and I have seen many candidates struggling to do post-order traversal and checking if a given binary tree is a binary search tree or not. If you want to succeed in the coding interview, you need to prepare well on binary trees in general. One way to prepare better is solving common binary tree coding problems like this one, where you need to find if the given tree is BST or not. There are a lot of things that would tell us if a tree is a binary search tree. But before we get to that, we need to understand what a binary tree is.

Radix sort in Java with Example

Hello guys, in one of the interview I was asked to name any O(n) sorting algorithm. I was shocked because I only knew about QuickSort and Mergesort whose best time is O(NLogN), so I couldn't answer that question. After the interview, the first thing I did was to Google about O(n) sorting algorithm and I was surprised to find that there are many algorithms like Radix Sort and Counting Sort and Bucket Sort which can provide O(n) performance. So, I learn them and wrote articles about them like in previous article I explained about Counting Sort algorithm and in this article, I will explain Radis sort like what it is and how it works. In Radix sort, we are sorting by comparing individual digits from the last one to the first one. In essence, radix sort is like this: sort elements by the last digit. 

Top 20 Mockito Interview Questions with Answers for Java Programmers

Hello guys, if you are preparing for Java developer interview then you must prepare for Mockito, one of the most popular mocking and unit testing library for Java developers. Mockito is used across all kind of companies, both big and small like startups for unit testing Java applications and that's why good knowledge of Mockito is required to crack the Java Interview. Along with JUnit, Mockito is quite important and if you are looking for Mockito Interview questions and answers then you have come to the right place. Earlier, I have shared best JUnit and Mockito courses and unit testing books, and even popular JUnit interview questions and in this article, I am going to share 20 common Mockito questions for your interviews.

Is 101 Blockchains Certifications worth it? Review?

Hello guys, if you want to start your career in Blockchain field and wondering going for a Blockchain certification then you have come to the right place. Earlier, I have shared 2023 Blockchain Developer RoadMap and these best Blockchain certifications to start your career in 2023 and in this article, I am going to review one of the popular Blockchain certification provider, 101 Blockchains Academy. The worldwide blockchain industry is expanding at an unnerving rate for a technology that came only a decade ago. In 2021, the global market had a valuation of almost $4.67 billion and might reach $7.18 billion in 2022. At the same time, blockchain adoption in the financial sector is at an all-time high. Healthcare and many other industries are gradually joining the blockchain revolution. As a result, many people search for blockchain certifications to support their career development goals.

Saturday, April 29, 2023

What is SAGA Design Pattern in Microservices? With Examples

 Hello guys, I have been writing about Microservices and Java from long tie and in the past, I shared with you 10 essential Microservice design patterns and principles and best Microservices courses for Java developers which many of you appreciated. At the same time, a lot of you asked me to go deep down into each of those patterns and explain them with examples. So I decided to create this new series of Microservice Pattern tutorials where I will explain each of those essential Microservice pattern with example every week. So far, we have covered Database Per MicroservicesCQRS, Event Sourcing, and Circuit-breaker pattern and in this article, let's have a look at SAGA Pattern, how does it work, what problem it solves and pros and cons of SAGA Pattern with examples. 

Top 20 Apache Kafka Interview Questions Answers for Java Developers

Hello, guys if you are preparing for the  Java Developer or Apache Kafka interview and looking for frequently asked Apache Kafka interview questions and answers then you have come to the right place. Earlier, I have shared the best Kafka courses and popular interview questions on JavaJMSSpring Boot, and Hibernate and in this article, I Am going to share 20 frequently asked Apache Kafka interview questions with answers. Over the years, Kafka which is developed by Apache Software Foundation has gained popularity because of its immense capability of data processing. Apache Kafka provides a unified, high-throughput, low-latency platform for handling real-time data feeds and because of that it has become a go to choice for high-speed message for many fortune 500 companies.  

Top 35 Python Interview Questions with Answers 1 to 3 Years Experienced Programmers

Hello guys, if you are preparing for a Python developer job and looking for some frequently asked Python interview questions then you have come to the right place. Earlier, I have shared the Complete Python Developer RoadMap,  best books and best courses to learn Python and in this article, I am going to share 35 Python questions, covering different concepts for Python developer interviews. Sitting in any interviews, especially in tech interviews, is a tough job itself. You can't go in without proper preparation. Even if you have taken or given dozens of interviews, it is always recommended to go through the quick preparation notes or concepts.

Top 21 GraphQL Interview Questions and Answers for Beginners and Experienced Developers

Hello guys, if you are preparing for web developer interviews where GraphQL skills are needed and you are looking for frequently asked GraphQL Interview questions then you have come to the right place. Earlier, I have shared both Web development interview questions as well as REST Interview Questions and in this article, I am going to share 20 common GraphQL Questions from Interviews with answers. These questions covers essential GraphQL concepts like difference between REST And GraphQL and pros and cons of using GraphQL to consume APIs. If you have used GraphQL in past then you can easily answer these questions but if you forgot then you can always join of these best GraphQL online courses to learn and revise key GraphQL concepts.

What is Generator Function in JavaScript? Example Tutorial

Hello guys, Functions are an essential part of JavaScript programming. Basically, a function is a piece of code that can take inputs and return outputs. Moreover, a function can be executed at any time and any number of times. When a regular function is called, it executes from top to bottom. Its execution ends when the function body ends or a return statement is encountered. But JavaScript provides a special kind of function that works in a different. These functions are called generator functions and they were introduced in ES6. In this article, we will discuss what are generator functions and how to use them with the help of an example. It's also a popular JavaScript interview questions, commonly asked to experienced developers.

Friday, April 28, 2023

Difference between Microservices and Monolithic Architecture

Hello guys, if you are preparing for Microservice developer interview or just a JAva developer interview where Microservices skills are needed then you must prepare with the difference between Monolithic and Microservices articles. It's one of the popular Microservices interview questions and often asked on both face-to-face round of interview or telephonic interviews.  Microservices and monolithic architectures are two of the most common approaches to building software systems. While both approaches have their benefits and drawbacks, they differ significantly in terms of their architecture, development, deployment, and maintenance.

Thursday, April 27, 2023

Why Programmers Should Learn Mathematics Again?

Hello folks, I have been learning Mathematics again from some time now, ever since I have introduced with Knuth's "Concrete Mathematics" by one of my friend, who I know is a much better programmer than me. I was like, no dude, programmers don't need to learn Mathematics again, whatever I have learned in the past, I have hardly used them. I should learn more about functional programming, Scala, JVM tuning and how to design Scalable, robust and concurrent systems rather than wasting time to learning Maths. But, he insists me to read the book and couple of others on discrete maths whenever you have some free time. So, the book was lying with several others for a couple of months until a fine day when I attracted with its cover. I quickly skim through the book, only to realize that I couldn't understand a bit and got bored in the first reading. 

10 Example of SCP (Secure Copy) Command in Linux

Hello guys, in last few articles I have explained how to use netstat, curl, and lsof command in Linux and in this article, I am going to share how to use SCP command in Linux to copy files and directory from remote host. Similar to SSH, its one of the essential command for any Java Programmer or IT professional as most of the time you will need to transfer data between servers and then you will need either SCP, SFTP, or rSync. The scp is another essential command for Linux user which allows you to copy files and directory from one server to another in a Linux network. It is based upon SSH and behave similarly in terms of authentication and logging but allows you to copy a file or directory from remote server. 

Top 30 Gradle Interview Questions with Answers for Java Developers

Hello guys, if you are preparing for Java developer interview then you must have come across Gradle, a Groovy based build tool which is gaining popular with Java community. While its not mandatory to learn Gradle for Java Interview if the job description mention Gradle or Groovy then you should prepare Gradle is one of the essential tool for Java developers. It's similar to  Maven and ANT, two other popular build tool for Java project but offers several advantages which I have explained in Maven vs Gradle post earlier.  These Gradle questions are good for both beginners and Java developer with 1 to 3 years of experience which are using Gradle in their project or expecting Gradle question on Java Interview.

10 Example of netstat networking command in UNIX and Linux

The netstat command is one of the most essential and useful networking command for Linux users. It is a general, all purpose network information tool which can be used to find out information about current network connections, multicast group membership, routing tables, network interface statistics and many other low-level details of the host's current network configuration. The good knowledge of netstat command is not only important from the troubleshooting perspective but also from security perspective. It gives useful security related information e.g. what network ports are currently "open" on your system and the list of current network connections and their states. 

Difference between -Xms and -Xmx JVM Parameters forJava Heap Memory

Though both -Xms and -Xmx JVM options are used to specify the size of heap memory, main difference between them is that -Xms is used to specify initial heap memory while -Xmx is used to specify the maximum heap memory. The JVM (Java virtual Machine) provides several command line arguments to specify size of different memory areas, also known as generations of Java Heap space, but two of the most useful JVM parameters which specify initial and maximum heap memory is -Xms and -Xmx. When you start JVM by using java command you can specify the maximum heap size with the JVM option -Xmx and a size e.g. java -Xmx1G MainClass will start JVM with maximum heap size of 1 giga bytes. Remember there is no space between -Xmx and size, if you leave space e.g. -Xmx 1024M then JVM will throw invalid heap memory error, so be careful there. 

How to declare a method which takes a lambda expression in Java 8? Example Tutorial

You may have seen lot of examples of how to use lambda expression in Java 8 e.g. to replace anonymous class, to implement Runnable or to implement Comparator but there are hardly any examples of teaching you to how to declare your own user defined method which can accept lambda expression. In this tutorial, I will try to bridge that gap. Actually, a method doesn't know whether you are passing an instance or a lambda expression to it, all you need to remember is that lambda expression is of SAM type in Java 8. Which means, you can pass lambda expression in place of an interface which has just one abstract method. 

Difference between char, varchar, nchar and nvarchar data types in SQL Server? Example

What is the difference between char and varchar in SQL, followed by nchar and nvarchar, is one of the popular SQL interview questions, and surprisingly not every programmer knows this basic difference. If you go with the name, which you should, then you can figure out that char is a fixed-length data type while varchar should be a variable-length data type. Though all char, varchar, nchar, and nvarchar are used to store text or String data there are subtle differences between them. As I said char is fixed length, which means a variable or a column like Zipcode char(10) will take only 10 bytes to store data, including space.

3 Maven Eclipse Tips for Java Developers

Hello guys, If you are using Maven inside Eclipse IDE via M2Eclipse plugin then the following tips can help you a lot. Maven is one of the essential tool for Java developers as it is used to build your application, compile your code, create packages which can be deployed into physical box or cloud. Apart from that Maven also provide dependency management feature which means you don't need to manually download JAR file and add into your classpath. You just specify which library your code is using and the version and Maven will automatically download correct JAR file for you and put in your local Maven repository. Maven can also manage transitive dependency which means suppose your code is depend on Spring Framework which itself need 10 more open source library to work. With Maven you just need to specify which version f spring framework you want to use, and it will download all the library needed by Spring automatically.  In nutshell, Maven makes Java development easier and every Java developer should learn it. 

Wednesday, April 26, 2023

Top 21 Maven Interview Questions with Answers for Java Programmers

Hello guys, if you are preparing for Java developer interviews then you should not ignore Maven as its on of the important build tool for Java developers. Most of the Java projects you are going to work will use Maven for building artifacts and deploying into both Physical machine and cloud. If you already know the importance of Maven and looking for frequently asked Maven interview questions then you have come to the right place. Earlier, I have shared 130+ core Java questions, Spring Boot questions, Hibernate Questions, and even JUnit questions for thorough preparation and in this article, I am going to share 20 common Maven questions from Java interviews with answers. 

Top 5 Cyber Security Certifications to Aim in 2024 - Best of Lot

Cybercrime is the quickest developing wrongdoing in the United States, and it is just expanding and more modern. After client data was taken, organizations, for example, Facebook, Panera Bread, Under Armor, and Uber acquired features. Managerial nerves and interest for network protection certifications develop with each hole. These worries are all around established. As per Centrify, 66% of customers in the United States would probably quit working with an organization that has been hacked.

10 Example of find command in UNIX and Linux

The find command is one of the most versatile commands in UNIX and Linux, and I used it a lot in my day-to-day work. I believe having a good knowledge of find command in UNIX and understanding of its different options and usage will increase your productivity a lot in UNIX based operating systems, e.g. Redhat Linux or Solaris. If you are a QA, support personnel, and your works involve lots of searching text on Linux machine or if you are a Java or C++ programmer and your code resides in UNIX, find command can significantly help you to look for any word inside your source file in the absence of an IDE.

Maven vs Gradle? Which one Java Developer Should Learn?

Hello guys, if you are looking for a quick introduction to Maven and Gradle then you have come to the right place. Earlier, I have shared the best Maven course and best courses to learn Gradle, if you haven't checked them, I suggest you can also look at them if you want to learn these tools in depth. Maven and Gradle are the two most popular build tools for Java applications. They manage dependencies and create artifacts.  How do they do that? They have a repository like a maven has Maven repository where the store every single Java library and depending upon which library you add to your project, they download that library + all the transitive dependency for those libraries automatically. 

how to fix the password issue for Maven in Eclipse? [Solved]

Most Java programmers use Maven in Eclipse via the M2EClipse plug-in, which gives one capability to build, run, and test Java application using Maven. I also use the M2Eclipse plugin for integrating Maven with Eclipse, but more often there are issues dealing with them like Maven not able to find certain archetypes, or maven not able to download Jar files from remote maven repository. Since I need to change the password often for security reasons like every 3 months, I do see a lot of maven issues in Eclipse related to building projects. Most of the time these are compilation errors that are caused because maven is not able to connect to remote maven central repository, even though you have updated password in settings.xml in the maven installation folder like C:\apache-maven-2.2.1\conf\settings.xml

Difference between Inheritance and Polymorphism in Java and OOP - Example

Both Inheritance and Polymorphism are key OOP concepts and similar to Abstraction and Encapsulation, they are also closely related to each other. Because of their similarities, many OOP programmers, especially beginners get confused between Inheritance and Polymorphism. Even though they are closely related and you need Inheritance to support runtime Polymorphism they are a totally different concept. Inheritance refers to the ability of classes or objects to inherit properties of other classes or interfaces. It means you can write code for common functionalities and reuse it at different places by just using Inheritance and not re-writing those codes again and again. For example, you can write code to

How to use for loop in Linux? Looping through List, values, and range in Bash with Example

If you know how to use for loop in bash shell or Linux, you can speed up a lot of task, saving precious time while doing support or troubleshooting in Linux. One of my favorite use of for loop is repeating same task among multiple host. For example, If I have to clean up some files from 10 hosts in the network, instead of manually going and removing files from individual host, you can use for loop and ssh command to automatically remove old log files from all the host, without manually logging into them. This is a tremendous time saving trick if you are working for an application which is running on more than one host. It's a life-saver if your application is running on 30 to 40 hosts. 

3 Ways to Learn Web Development in 2024 - Best of Lot

Hello guys, if you want to learn Web development but not sure how to start it then you have come to the right place. In the past, I have shared best free web development courses as well as best paid web development courses and in this article, I am going to share 3 ways to learn web development in depth. Web development has changed a lot in the recent decade. More and more frameworks and libraries have come out while the older ones are either updated or left out. For example, React and Vue has debuted in the mid-2010s and quickly became popular while AngularJS was completely re-written to survive modern web development. Today, Web development is one of the most popular domains in the IT community. Every company or product wants a website because the web is easily accessible today. Even when mobile applications are gaining popularity, the web remains at the top.

How to use Mockito to Unit test Java Program with JUnit? Example Tutorial

Hello guys, if you are writing unit test your Java application then you would have definitely come across JUnit and Mockito, two of the essential unit testing framework  for Java developers. While JUnit offers support to run your test, setup and teardown and also assertion to check the expected and actual output. Mockito complements JUnit by offering you a mock based testing approach. Mock is nothing but a test double which can return a configured value when a certain method is called. It also provides ability to check if a particular method is called or not. By using Mock object or test double you can check if your code is behaving properly or not in different scenarios. This is also the key difference between JUnit and Mockito, JUnit provides infrastructure to run your test while Mockito provide infrastructure to created Mock objects. 

How to check if a String has all unique characters in Java? [Solved]

Hello guys, its been long time since I shared any interesting coding problem but the wait is over. Today, I am going to share one interesting and popular String based coding problem which you would love to solve. Today's coding challenge is to find out if a given string has all unique characters or not, for example, if given String is "Java" then your function should return false because all styles from this String are not unique. On the other hand, if the given String is "Python," then your function should return true because all characters are unique in this String. Btw, don't just jump on the solution if this is ever asked to you on Interview; instead, you should ask a couple of good questions to demonstrate your requirement gathering skill and attention for details.

Difference between JPA, Hibernate, and MyBatis in Java

Hello guys are you tired of using plain old SQL to access your database? Are you looking for a better way to manage your database interactions in Java? Well, you're in luck because JPAHibernate, and MyBatis are here to save the day! If you're a Java developer, you've likely come across the terms JPA, Hibernate, and MyBatis when working with databases. While they all deal with object-relational mapping (ORM), they have their own distinct approaches and features. Understanding the differences between them can help you make informed decisions when choosing which one to use for your projects.

Monday, April 24, 2023

Top 35 T-SQL and Microsoft SQL Server Interview Questions and Answers

Hello guys, if you are preparing for Java developer interview where Microsoft SQL Server is listed as mandatory and required skill or you preparing for a junior DBA role for Microsoft SQL Server and looking for common SQL Server interview questions for practice then you have come to the right place. Earlier, I have not only shared SQL Server courses for beginners but also 50+ SQL and Database Questions for programmers and DBA. You an also check them to get yourself familiar with generic SQL concepts like normalization, joins, aggregation, partitioning, indexing, and transaction along with these SQL Server specific questions which focuses mainly on T-SQL and SQL Server functionalities and how general SQL commands behave in Microsoft SQL Server. 

12 Examples of kubectl command in Linux

Hello guys, if you are working with Kubernetes pods like deploying your application, starting and stopping them by scaling to zero instances, while you just want to see logs or want to login into the Kubernetes pods itself, you must know how to use kubectl commands to do all these task. Since most of the companies, both big and small are using Kubernetes to deploy services on cloud, its imperative for Java developers and other Software developers to get familiar with the kubectl command. We deploy our Java Microservices on Kubernetes mainly because Kubernetes can start the services automatically when it goes down. We have different Kubernetes clusters for different environments like DEV, UAT, and PRODUCTION and I often switch between those cluster using kubectl commands to check the status of our Java services or interact with them.

5 Examples of df command in Linux

The df command is used to find the amount of disk space used and available on different partitions and file systems. The simplest example of df command is just typing df on console with out any arguments and it will show you the space used and available on all currently mounted file systems of all types e.g NFS, ext3 and both local and remote. Alternatively you can ask df command to print the size and space available and used for a particular partition. Normally the disk space is printed in units of 1024 bytes, but this can be overridden. I commonly use df -h option to print the size and disk usage in human readable format e.g. G for giga bytes, M for mega bytes and so on. 

How Long does it Take to Learn Machine Learning in 2024?

Hello guys, if you want to learn Machine Learning in 20243 and wondering how long does it take to learn Machine Learning and become a Machine Learning Engineer then you have come to the right place. Earlier, I have shared best free Machine Learning courses and books and in this article, I will share how much time it take to learn Machine Learning and how you can quickly learn essential ML concepts and become a Machine Learning Engineer in 2024 but before that let's see what does Machine Learning means? Machine learning is the science of making the machine predict the result of something based on previous data. 

How to Base 64 Encoding Decoding in Java 8 - Example Tutorial

Until Java 8, there was no standard way to Base64 encode a String in Java or decode a base64 encoded String. Java Programmers either use Apache Commons library and its Base64 class to encode or decode binary data into base 64 encoding, as shown here, or rely on internal Sun classes e.g. sun.misc.BASE64Encoder and sun.misc.BASE64Decoder(), which was not officially part of JDK and can be removed without notification. Java 8 solves this problem by providing standard support for base64 encoding and decoding by providing a java.util.Base64 class. 

5 ways to find length of String in Java - Example Tutorial

On another day, someone asked me, is there a way to find the length of String without using the length() method from java.lang.String class? I didn't ask why, because I know it might have been asked to him on Interviews. Before I explore ways to find the length of String, let's recap what does the length of String means in Java? Well, it's no different than C here, a number of characters in a String including whitespace, newlines are known as length of String. By knowing this, you can think of many approaches to calculating length e.g. getting a char array from String and counting a number of characters or many are by applying some clever tricks.

How to recursively show all files in a directory and sub-directory in Java - Example

Hello, guys if you are looking for a Java program to recursively list all files in a directory or sub-directory in Java then you have come to the right place. Earlier, I have shared the best Java Programming courses and In this article, I will show you how you can use the SimpleFileVistor class from java.nio package to recursive list all files and directories inside a given directory. The API also provides you control over whether to list only files or directories when you are navigating recursively. This makes it very useful for archiving programs or creating build tools like Maven or any Java program which has to deal with files and directories. 

Solving ArithmeticException in Java? Integer and Floating point Arithmetic Example

I am starting a new series called Java Coding Quiz, in which I'll show you subtle Java concepts hidden in the code. This is an OCAJP or OCPJP style question but focused on teaching subtle details of the Java programming language. In today's puzzle, you will learn about one of the key concepts about how floating-point and integer arithmetic works in Java. This is a very important concept for any Java developer because Java behaves differently when the same operation is performed by different types of variables but of the same value.

How to use Comparable Interface in Java? compareTo() Example

Hello, guys, today I am going to talk about one of the fundamental concepts in Java, defining the natural ordering of the objects like lexicographical order for String and numerical order for Number classes like Integer, Double, Float, etc. The compareTo() method is defined in the java.lang.Comparable interface. It is used to define the natural ordering of an object, for example String class override compareTo() to define the lexicographical order for String objects. Integer class override compareTo() to define the numeric ordering of integer objects.

How to implement Linear Search in Java? Example Tutorial

Hello guys, earlier, I have talked about how the binary search algorithm works and shared the code to implement the binary search in Java. In that article, someone asked me about is there any other search algorithm that exists? How can you search an element in the array if it's not sorted, and you cannot use the binary search algorithm? To answer his questions, I mentioned the Linear search algorithm, which is the predecessor of binary search. Generally, it is taught before the binary search algorithm because the binary search is faster than Linear search. However, never mind, you can still learn this useful algorithm to search for an item in the array or linked list.

When to make a method final in Java? Example

Hello guys, if you are wondering when to make a method final in Java then you have come to the right place. Earlier, I have told you when to make a method static and when to make private and today, I will teach you when to make a method final in Java. The final keyword in Java is not as mysterious as volatile or transient, but still, it creates a lot of doubts in programmers' minds. I often receive questions like, When to make a method final in Java or When to make a method static in Java, later I answered in my earlier post. Questions like this are not trivial, knowing what a keyword does is just a small part of mastering that functionality. Similar to the real world, where knowing that a sword can cut a lot of things is not enough for a warrior to survive, you need to know how to use that and more importantly, use it effectively. 

Sunday, April 23, 2023

Spring Hello World Example in Java using Dependency Injection

Hello All, In this Spring framework tutorial, you will learn how to write the hello world example in the Spring framework. This should be your first tutorial to start learning the Spring framework, as it gets the ball rolling. While coding and running this example, you learn a lot about the Spring framework, Spring XSD files, necessary JAR files, and more importantly how the Spring framework works. This HelloWorld program in Spring framework is an extension of the classical Java hello world program, which you might have seen earlier. This program is written using the Dependency Injection design pattern by using the Spring Frameworks' IOC container.  Even though now you can configure Spring dependency using annotations and Java configuration, this example uses a traditional XML way to configure dependencies.

How to use jQuery Class and Id Selector to find DOM elements? Example

One of the best things about jQuery is there selectors, which gives jQuery enormous power to find and select DOM elements so easily. If you are coming from JavaScript background then you might love those classical methods to find DOM elements like getElementById() and getElementByName(). They have served very well in the old days of JavaScript coding,  but once you start using jQuery selector, which is quite similar to CSS selector, I am sure you will forget them. Searching and finding HTML elements using jQuery selectors are natural, intuitive, and super easy and that's why I love them.

Saturday, April 22, 2023

5 Examples of Text Block and Multiline String in Java - Tutorial

While some programmers are troubled with frequent Java releases (it's actually hard to keep up), many are excited to see new features coming in Java every six months. I haven't been sharing a lot of new features lately, last I wrote about var from Java 10 and static factory from Java 9. Well, to be honest, I don't get much time to try out these new features and to publish articles on those, but a couple of new features from Java 12 and Java 13 caught my attention and I decided to give it a try and write something about them. So, the first feature in this series is the "Text block" of Java 13.

How to use Records in Java? Example Tutorial

Hello! Welcome, all again in the journey of Java. We are here today to learn a very interesting topic in Java: Records!  If you are wondering what is Record and how to use Record in Java then you have come to the right place. In this article, I am going to cover everything about the Record I know and will try to explain in simple words so that you know what is Records, what benefits it offers, and how you can use them. But before we dive in and understand what it is, let’s first understand what would happen without them. So, we would get an idea of the need and significance of Records. By the way, this is another article covering new Java features, earlier, I have covered Sealed ClassesCompletableFuturePhaser, and how to use var in Java. If you haven't read them already, you can check them to learn these useful Java features 

How to use Sealed classes and Interface in Java? Example Tutorial

Hello friends! If you are wondering what is Sealed class in Java and whether you should use it or not and looking for a Sealed class tutorial then you have come to the right place. Earlier, I have shared Java Record Tutorial and Java CompletableFuture tutorial and today, I will explain you about another interesting Java feature. Yes, I am talking about Sealed classes in Java. This is a relatively new feature that was added in Java 15 as a preview feature. This was added as part of JEP 360 to provide more fined-grained inheritance control in Java. This can be better understood by an example. So, I am going to give you a situation and we will analyze this situation together. 

6 Subtle Date and Calendar Details to Learn before using Date in Java - Example Tutorial

Hello guys, to appreciate the brilliance of the new Date and Time API introduced in Java 8, you must remember the nasty problems you have earlier faced with Java's old Date and Calendar API Well, I have been using Java for the last 20 years and I have to face them so I thought to write this article to educate Java programmers about the shortcomings of old Java Date and Calendar API. Another reason for this article is that even though Java is ready with the new, shiny, and carefully designed Date and time API, your project is probably not. Most of the prominent organizations that use Java at large scales, like Investment banks, Insurance companies, major E-commerce giants, are quite reluctant to upgrade. There are many firms, both big and small that are still running on Java 5 and expect to migrate to Java 6 in a couple of years.

How to find number of days between two dates in Java 8 [LocalDate until() & between() Example ]

You can use the LocalDate.between() method to find the number of days between two dates in Java. This method is full proof and takes care of date-time nuisances like leap year and daylight saving time. Before Java 8, it was really difficult to calculate the number of days between two dates in Java. Though old Date and Calendar API provides methods to compare two dates like equals(), before(), and after(), no method can tell the exact difference in days or months between two dates unless you are using the joda-time library. All that is over now. You can now do better date-time arithmetic using Java 8 Date and Time API.

How to use TreeSet in Java? SortedSet Example Tutorial

Hello friends, we meet again for our journey of learning Java. Today, we are gonna learn something very fruitful and easy. Hope you all are excited and ready. I would recommend you guys to go through the HashSet article which goes over hashing and what sets are actually as this topic has some of its features. So, What's the wait? Let's start! Continuing our example used in HashSet and reusing it here. Suppose you guys are given the task of storing car names (yes, I love cars :p). Now, how would you store it? This question has already been answered by our HashSet article. The new problem here is, we need to store the names in a naturally sorted manner. As we have a set of String, we need to sort them alphabetically. How to do that?

How to Remove a Key, Value, or Entry from HashMap in Java 8 - Example Tutorial

In the last article, I have shown how to remove key/value pairs from a map in Java-based upon some conditions like removing all entries where values are greater than some values. I have told you that you must use the Iterator's remove() method for removing mapping while iteration to avoid ConcurrentModificationException, but that's not required anymore in Java 8. From JDK 8 onwards, you can selectively remove mapping without iterating over Map. The JDK 8 API has added several new methods to existing interfaces e.g. java.util.Collection, java.util.Map, Comparator, etc because the interface can now contain concrete methods in the form of static and default methods.

[Solved] How to Reverse an ArrayList in Java using Recursion? Example Tutorial

If you ever need to reverse a List in Java e.g. ArrayList or LinkedList, you should always use the Collections.reverse() method. It's safe and tested and probably performs better than the first version of the method you write to reverse an ArrayList in Java. It's also one of the recommended best practices to prefer the library method instead of writing your own, as advised by great Joshua Bloch in Effective Java. There are so many benefits of using library methods like it was written by experts, thoroughly and open-source tested, and more actively maintained. Anyway, if you have been asked to write a function to reverse a List using recursion in Java, maybe as part of your homework, assignment, or during an interview, then you are in the right place.

How to use ConcurrentLinkedDeque in Java? Example Tutorial

Hello guys, ConcurrentLinkedDeque is another amazing class from Java's concurrent collection package which can be used as high-performance, thread-safe and non-blocking data structure. As the name suggest, its a Deque which means its allows you to operate at both ends of queue. You can insert at one end and consume from other end. It's also concurrent and thread-safe which means multiple threads can operate on same queue at the same time. You can have multiple producer threads which are inserting data into the queue and multiple consumer threads which are consuming data from this data structure. Before going to discuss this topic, let me inform you that this article is in continuation of our deque article series. It's totally not mandatory to go through those articles, but it is highly recommended as they all play a part in the understanding of today's topic.

How to find the First Key or Value from a Map in Java? HashMap Example Tutorial

Hello guys, if you are working with Java HashMap or any other Map implementation like TreeMap or LinkedHashMap and wondering how to get the first enty, first key or first value then you have come to the right place. In my past articles, I have talked about how HashMap works internally as well as we have seen several HashMap examples and in this article, I will show you how to get the first key or value from HashMap in Java. I actually needed this when I was doing a coding exercise online and I was using TreeMap to store objects. Since TreeMap store objects or mapping like key and value in sorted order the first element can be either maximum or minimum depending upon whether you sorted the TreeMap on increasing or decreasing order. 

Difference between Synchronized and Concurrent Collections in Java? Answer

Synchronized vs Concurrent Collections
Though both Synchronized and Concurrent Collection classes provide thread-safety, the differences between them come in performance, scalability, and how they achieve thread-safety. Synchronized collections like synchronized HashMap, Hashtable, HashSet, Vector, and synchronized ArrayList are much slower than their concurrent counterparts like ConcurrentHashMap, CopyOnWriteArrayList, and CopyOnWriteHashSet. The main reason for this slowness is locking; synchronized collections lock the whole collection e.g. whole Map or List while concurrent collection never locks the whole Map or List.

How to convert Milliseconds to Minutes and Seconds in Java? TimeUnit Example Tutorial

I used to convert milliseconds to seconds in Java by simply dividing it by 1000, and then into minutes by further dividing it by 60, and then hours by even further dividing by 60 and so on. This works but its not the most elegant way to convert millisecond into hours, minutes, seconds or other time unit. JDK comes with a nice utility class called TimeUnit, which as its name suggest, allow you to convert one time unit into other. So if you have milliseconds e.g. execution time of a method and you want to convert into minutes and seconds to improve readability, you can use TimeUnit.toSeconds() and TimeUnit.toMinutes() methods. 

Difference between final and effectively final of Java 8? Example Tutorial

If you remember, You can only access a local final variable inside an anonymous class, if you try to access a non-final local variable then compiler will complain, but things has changed a little bit in Java 8 with introduction of lambda expression. Since Java designer are expecting more and more usage of lambda expression they have relaxed that restriction a little bit by introducing a new concept called effectively final, which means now you can access a non-final variable inside anonymous class or lambda expression, provided its not changed after creation i.e. even if its not declared with final modifier but it still like a final variable.  So, concept wise, the variable must still be treated as final variable but the final keyword is not mandatory anymore. This difference between final and effectively final will be more clear with an example of both anonymous class and lambda expression. Let's see that.

How to create Soft and Hard Links in Java? Files + Path + Java NIO Example

Hello guys, not many people know that Java NIO File API also allows you to create links in Java. Many of Java programmer are familiar with ln command in Linux which is used to create soft and hard link but you can also do that using Java File API. Path represents not only files and directories, but links to files and directories, symbolic or otherwise. In fact, the Path class detects and handles links automatically, without requiring you to do anything specific when one is encountered in your application. However, you do have options available on how to handle symbolic links when they occur, and you can also create new links in Java for file systems that support them.

How to choose the Right Collection Class in Java? List, Set, Map, and Queue Example

The Java collection framework offers implementation of different data structure like an array, list, set, map, queue, tree, etc and the choice really depends upon the situation and properties of the different data structure. For example, if your requirement is fast search with index then you can use ArrayList and if you want to store key-value pairs then you would consider using hash table data structure and there are a couple of implementation of hash table data structure in Java, like HashMap, Hashtable, LinkedHashMap, TreeMap, and ConcurrentHashMap. Now, which one will you choose? If you don't know or confused don't worry, I will give you a set of rules and use cases which will help you choose the right Collection type in Java depending upon scenario. 

Difference between Filter and Listener in Servlet - Java JEE

One of the frequently asked Servlet Interview question is what is the real difference between a Filter and a Listener? What is the role they play in a Java web application? In this article, I'll try to answer these question by explain what is Servlet Filter and Servlet Listener and what are their use in Java web application. A filter is used for pre-processing and post-processing. It can intercept the request before it hits to the servlet and can modify both header and body of Servlet, hence it is used to perform login, authentication, authorization and other security aspect which is require before client can access the resource e.g. a Servlet or JSP. Similarly, filters can also intercept the response and modify both header and body of response, hence you can use it both compress and encrypt the response before sending it to the client. 

Top 15 SQL Server Management Studio (SSMS) Keyboard Shortcuts and Tips

SQL Server Management Studio, also known as SSMS is an essential tool for Microsoft SQL Server developers as well as any full-stack Java developer whose application is using SQL Server database in the backend. It allows you to connect to the MSSQL database, execute SQL queries, check execution plan, see table and schema detail, writing and debugging stored procedures, and many more features. Imagining life without SSMS for SQL Server DBA and developer is impossible. 

ByteBuffer Read Write Example in Java

Hello guys, if you have worked with Java NIO API then there is a good chance that you may be familiar with ByteBuffer, one of the important class which is used to read and write data from channels. Java NIO Buffers are used when interacting with NIO Channels like FileChannel. As you know, data is read from channels into buffers, and written from buffers into channels. A buffer is essentially a block of memory into which you can write data, which you can then later read again. This memory block is wrapped in an NIO Buffer object, which provides a set of methods that makes it easier to work with the memory block. If you compare this with traditional java.io package then you will remember that we read and write data from stream into array but in case of NIO, we read and write data from channels into ByteBuffer

Database Per Microservice Pattern in Java - Example Tutorial

Hello guys, in the last article, I share with your 10 essential Microservice design patterns and principles and best Microservices courses for Java developers which many of you appreciated. At the same time, a lot of you asked me to go deep down into each of those patterns and explain them with examples. So I decided to create this new series of Microservice Pattern tutorials where I will explain each of those essential Microservice pattern with example every week. In this article, let's have a look at what is database per microservice. Microservice architecture is a combination of a set of loosely coupled microservices and each service can be developed independently in an agile manner. We can use this pattern and practices when designing microservices. So let's go deep into what is database per microservice is and why we use it in our programming. 

10 Reasons to learn MongoDB NoSQL Database in 2024

Hello guys, If you are in web development or Software development then you may know that databases are an important part of modern development. Be it web or mobile application development, you will always find some kind of database in it. Modern development is not complete without databases because data is required to be stored somewhere. As a Java developer I have worked across many projects and most of them have relational database but things are changing nowadays and more and more project are using NoSQL Databases like MongoDB, Redis, Cassandra etc which can really improve performance in many specialized cases. 

3 ways to parse JSON String to Object in Java [Jackson, Gson, and json-simple Example]

One of the common task in Java web application, particularly the ones which deals with RESTful web services are parsing JSON messages. Many times you need to parse JSON to create a Java object like parsing a JSON message to create a POJO,  for example, an Order or a Book. Representing JSON in Java is easy, it's like a String value but unfortunately, JDK doesn't provide any standard API to parse JSON in Java. There were talks to add JSON parsing API in JDK 9 but that didn't materialize, but you don't need to worry. There are many good open-source JSON parsing libraries you can use to parse any kind of JSON in your Java program. 

How to calculate Area and Perimeter of Square in Java Program? Example Tutorial

Hello guys, if you are looking for Java program to calculate area of Square or program to calculate perimeter of square or just learning Java and looking for programming exercises then you have come to the right place. I have share many programming exercises and homework in this blog and today, I am going to share another simple programming assignment for beginners. Yes, we ae going to write a program which will calculate the area and perimeter of a square in Java. If you don't remember, area of a square is nothing but the multiplication of side with itself or square of side, while perimeter of a square is 4 times of its side because in case of square, each side is equal. 

Friday, April 21, 2023

Top 5 Websites To Learn TypeScript in 2024

Hello guys, if you want to learn TypeScript and looking for resources like books, online courses, tutorials, online platforms, websites then you have come to the right place. Earlier, I have shared best free TypeScript courses and best TypeScript paid courses and in this article, I am going to share best platform and websites to learn TypeScript in 2024. But, before we get to a list of the best free courses that will teach you everything you need to know about TypeScript, let me tell you a little bit more about what it really is.For those of you who don't know, TypeScript is basically a strongly typed superscript of JavaScript. It can b compiled to plain JavaScript. TypeScript can be used for application-scale JavaScript development. It can also be executed on any browser, any host, and any operating system.

Top 20 Rust Interview Questions and Answers for Developers

Hello guys, if you are preparing for Rust Developer job interview and looking for Rust Programming interview questions then you have come to the right place. Earlier, I have shared best books and courses to learn Rust programming and in this article, I am going to share frequently asked Rust Interview Question. These questions covers essential Rust features and concepts and you can use this list to quickly prepare for Rust developer interviews. If you have used Rust in past or worked as Rust developer then you can easily answer these questions but if you cannot, you can always go back and join one of these best Rust online courses to learn and revise essential Rust concepts.

Spring Boot + Angular + Java Project Example and Tutorial

Hello Java programmers, if you are looking for a full-stack Java project with Spring Boot and Angular then you have come to the right place. Earlier, I have shared best Spring Boot courses, books as well as Spring boot + Reactjs project and In this tutorial, we are going to discuss how to create your first application using spring boot and angular. So we are using a simple crud application to build the application here. Here we create a School Classroom Dashboard application that can insert, update, delete and search students. The frontend of the application will be handled by angular and the backend of the system is using the spring boot. This is also a great Spring boot project beginners to do learn Spring boot better. So let's have a look into this.

Difference between Proxy and State design Pattern in Java

Hello guys, if you are preparing for Java interviews and looking for difference between Proxy and State design pattern then you have come at the right place. In the past, I have explained several important object oriented design patterns like State patttern, Strategy, Adapter, Facade, Factory, Observer, Decorator, Command, and Composite Pattern and also shared frequently asked questions on design patterns (See here) and in this article, I am going to share the key difference between Proxy and State Design Pattern in Java and OOP. The difference between Proxy and State pattern comes in both intent and structure, here are the key difference between both Proxy and State Design Pattern in Object oriented programming.

10 Reasons to learn JavaScript Programming Language in 2024

Hello guys, if you want to become a web developer or a full stack web developer who can code frontend, backend, and both web application and mobile apps then you must learn JavaScript. It's one of the most popular programming language with lots of jobs and opportunity and its also very easy to start learning. If you also want to learn JavaScript but not sure whether JavaScript is the right programming language or not, or want to learn JavaScript but not sure whether its worth the effort then you are the right place. Earlier, I have shared best JavaScript courses, books, and best places to learn JavaScript and in this article, I am going to share 10 key reasons to learn JavaScript in 2024. 

AES Encryption and Decryption in Java - AES Encoding Decoding Example Tutorial

Hello Java programmers, if you are looking for an example to encrypt and decrypt a test using the AES algorithm in Java then you have come to the right place. Earlier, I have shown you how to Base 64 encode and decode a String in Java, and in this article, I will teach you how to encode and decode a string using AES Algorithm.  If you don't know, AES stands for Advanced Encryption Standard algorithm and it is a symmetric block cipher that is used to protect classified information by many Government and Security organizations. You can use AES to encrypt sensitive data in your application config file like database password, user login details and keys etc. In our example we will be using an AES Algorithm with AES - 128, AES has a fixed block size of 128 bits. We will be using a password based secret key.

Thursday, April 20, 2023

How to use Session attributes in Spring MVC? @SessionAttribute and @ModelAttribute Annotation Example Tutorial

Hello Java and Spring developer, if you are wondering how to use the session attribute in Spring MVC application, then you have come to the right place. In the past, I have shared how to build REST API using Spring and several other Spring tutorials like Spring Boot + React fullstack application, and in this article, I will share a couple of strategies to use session attributes in Spring MVC application. Using session attributes in Spring-MVC is a major concern in each web application as there is session management in most of the web applications right now. Because Spring MVC is such a sophisticated framework for web development, it comes with its own tools and API for working with sessions. 

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 Find Square Root of a Number in Java? Example Solution

Write a program to calculate the square root of a number in Java or C++ is one of the popular coding interview questions from Programming job interviews both on tech companies like Facebook, Amazon, and investment banks like Citibank and Bank Of America, etc. The problem may look easy because you might know how to find the square root of a number but it's not. In fact, it's one of the tricky questions you would encounter in programming job interviews. The first hurdle is do you really remember how to calculate square root by hand? Many programmers don't. I know they have learned it past but when you ask them to calculate square root by hand, many won't remember the algorithm they have learned in school or college.

How to Print a left triangle star pattern in Java? Example Tutorial

Pattern based exercises are very common on Interviews as they are tricky for beginners and also offers coding practice. In the past, I have shared article on how to print pyramid pattern of stars in Java and Pyramid pattern of albhabets, and in this article, I will show you how to print left triangle star pattern in Java. There are different ways of printing different patterns, but most of them involves using loops and print methods like print() and println() to print characters like star, alphabets or numbers. If you know how to use loops and when to break from loop then you can easily solve pattern based coding problems. In this section, we shall be writing a program to print a left triangle star pattern. We would first implement that before I explain other things that you need to know in getting this task done.