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.

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 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 20 CSS Interview Questions and Answers for 1 to 2 Years Experienced Web Developers

Hello guys, if you are preparing for web developer job interview and looking for common CSS Interview Questions then you have come to the right place. Earlier, I have shared HTML Interview questions and CSS Interview Questions and in this article, I am going to share 20 common CSS Interview Questions with answers. If  you have used CSS for a couple of months then most likely you know the answer of these CSS questions but if you struggle with any of them then you can always go back to these best CSS online courses to revise key concepts. I have tried to include as many questions as possible covering different CSS concepts but you can also contribute, feel free to ask questions on comments. 

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.

Top 20 Machine Learning Interview Questions and Answers

Hello guys, if you are preparing for Machine Learning Interviews and looking for common Machine Learning questions then you have come to the right place. Earlier, I have shared 35 Python Interview Questions and 20 AI Interview Questions and in this article, I am going to share 20 Machine Learning Interview Questions with answers. If you have gone through a Machine learning course or have worked in Machine Learning for a few months then you should know answer to all of these questions but if you struggle to answer them then I suggest you to revise concepts by going through these best Machine Learning courses for beginners. They are great to learn and revise important Machine Learning 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. 

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.

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. 

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.

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

How to check if Checkbox is checked in JQuery? Example Tutorial

Hello guys if you are wondering how to check if a checkbox is checked using jQuery then you have come to the right place. Earlier, I have shared, how to check/uncheck checkbox or how to find all unchecked checkboxes using jQuery and in this article, I will share how to check if a particular checkbox is checked or not. While working in Java web application front end, written using JSP, HTML, CSS, and JavaScript, we often need to check status of checkbox e.g. whether a particular checkbox is checked or not? One example of this is checking is checking, whether user has accepted terms and conditions before submitting form. Thankfully, JQuery provides a nice and easy way to find status of checkbox. 

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

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

Review - Is Google Digital Marketing & E-commerce Certification worth it?

Hello guys, if you want to learn Digital marketing and e-commerce skill online and looking for best resources like book, online courses, and tutorial then you have come to the right place. In this article, I am going to introduce with Google's Digital Marketing certification on Coursera, which is is a great resource to learn Digital Marketing in 2023. If you don't know, Google's Digital Marketing & E-commerce Certification is a popular program that offers individuals the opportunity to gain essential skills and knowledge in the digital marketing industry. The certification covers a wide range of topics, including search engine optimization (SEO), pay-per-click (PPC) advertising, e-commerce, and more

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.

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. 

[Solved] How to check if given point is inside Triangle or not in Java? Example

One of the interesting problem from Java Programming interviews is, "write a program to check if given point lies inside a triangle or not?". You will be given co-ordinates of vertices and the point as part of problem and you need to write a function e.g. isInside() which return true if point is within the triangle and false if it is not. For example, in the triangle specified by vertices (11, 31), (21, 1), and (1, 1) the point (11, 16) are inside the triangle and point (30,17) are outside of the triangle. It's a good coding interview question if you have not heard before, just think about how do you prove if the point lies inside the triangle or not? It's not a difficult algorithm and you can think of it by just trial and error. 

How to Rotate Array to Left or Right in Java? Example - LeetCode Solution

Hello guys, rotating an array in Java is a common coding problems which are often used to teach beginners coding as well used during interviews to check candidate's programming and data structure skills. This problem may look easy but its not that easy, especially if you are not coding regular. In order to rotate an array of n elements to the right by kth index, you need to rearrange the item in such a way that the array will start from k + 1the element.  For example, with n = 7 and k = 3, the array [1, 2, 3, 4 ,5, 6, 7] is rotated to [5, 6, 7, 1, 2, 3, 4]. See, it looks like you pick the the 4th element and rotated the array in right direction. The problem becomes even more interesting when interviewer ask you to rotate the array by left or right and in place. Could you do it in-place with O(1) extra space?

Wednesday, April 19, 2023

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

10 Essential UTF-8 and UTF-16 Character Encoding Concepts Every Programmer Should Learn

Hello guys, if you want to learn about character encoding, particularly UTF-18 and UTF-16, and looking for a good resource then you have come to the right place. In this article, I am going to discuss 10 important points about UTF-8 and UTF-16 character encoding which I believe every programmer should learn. This is one of the fundamental topics to which many programmers don't pay attention unless they face issues related to character encoding. Knowing how a character is stored and how they are represented in such a way what computer can understand is very important in this age of globalization and internationalization where you need to store and work through data that contains characters from multiple languages. 

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. 

How to check Perfect number in Java? Example Tutorial

Hello guys, if you are wondering how to check if a given number is a perfect number or not in Java then you have come to the right place. This is one of the interesting coding problem to solve and learn and improve your coding and programming skill. In face, I learned most of my programming by solving these kind of questions. I started with simple ones like factorial, prime number, palindrome, anagram, string permutations before I started solving tree based problems and Dynamic programming problems. These kind of exercise not only give you a chance to get familiar with the programming language constructs like data type, operators, functions, class etc, but also help to build coding sense, which is nothing but your skill to convert your logic into code. 

Counting Sort Algorithm in Java? Example Tutorial

Hello guys, in our last article, we looked at the Radix Sort in Java and in this article, we will look at the counting sort in Java. If you are thinking how they are related then let me tell you that both are O(n) sorting algorithms. Yes, its possible to sort in O(n) or linear time. If you are wondering that you have so far only learned that best sorting algorithms are Quick Sort and Merge Sort who sorts an array in O(nLogN) time then you are in for surprise. Yes, there existing O(n) sorting algorithms which are faster than both Quicksort and Merge sort like Radix Sort, Counting Sort, and Bucket Sort but they have their limitation. They are not general purpose sorting algorithm and you can use this to sort only integers and it also depends upon how big is the data set and how many different numbers are in the data set. 

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 JVMThe real difference comes in addressable memory or heap memory