Difference between HashMap vs TreeMap vs LinkedHashMap in Java

Hello guys, if you are wondering what is difference between HashMap, TreeMap and LinkedHashMap in Java and  when to use HashMap, TreeMap and LinkedHashMap in Java then you are at the right place. Earlier, I have shared difference between HashSet, TreeSet, and LinkedHashSet and in this article, I will explain the difference between these three common Map implementation HashMsp, TreeMap, and LinkedHashMap. Though all three classes like HashMap, LinkedHashMap and TreeMap are implementation of java.util.Map interface, there is some functionality difference between them. Perhaps most notable difference between them comes from their iteration order. HashMap makes absolute no guarantee about in which order you can iterate their keys, any application depending upon iteration order of HashMap is fragile, because it can change anytime. In fact, in Java 7, iteration order of HashMap is different than Java 6. 

3 Ways to send a HTTP GET and POST request in Java? JDK 11 HttpClient Example tutorial

Hello guys, today's word is of modern web applications and APIs and in this world the ability to communicate with remote servers is an essential skill for Java developers. Whether you need to retrieve data from a web service or send data to a server for processing, mastering the art of making HTTP requests is crucial. If you are a Java developer the you must know how to send HTTP requests and parse HTTP Response to work effectively on different kind of Java web applications. If you don't know then don't worry as In this comprehensive guide, we will walk you through the fundamental concepts and practical techniques for sending HTTP GET and POST requests in Java. Whether you're a beginner looking to learn the basics or an experienced developer seeking to refine your skills, this tutorial will equip you with the knowledge and tools to interact with web services effectively using Java.

Top 20 Java Access Modifier Interview Questions Answers for Beginners

Access modifiers is one of the essential concept in Java and every programmer should be familiar with, and because of its importance, its also a popular topic in Java interviews. Access modifier can be applied to class, method, fields, and variables and as the name suggests they control the access. Like who can access that particular class, method or variable. For example, public modifier provides universal access which means any public class, method or variable is accessible by everyone and everywhere. In other words, you can access a public class both within the package and outside the package. 

Top 20 YAML Interview Questions Answer for Developers and DevOps Engineers

Hello guys, if you are preparing for DevOps Engineer interview then you should also prepare YAML questions as YAML is used extensively in Kubernetes, or creating Helm charts or creating Ansible Playbook and you can expect few questions on YAML on DevOps Engineer Interviews. If you don't know YAML stands for Yet Another Markup Language and its one of the popular language for defining system rules. YAML is used in Spring Integration and most popularly in Ansible for defining Ansible playbook which you can use to install or uninstall application and do other stuff. Because of that reasons YAML has become quite popular and you may be asked about basic questions in YAML if you are going for a Developer or DevOps Interview where YAML skills are required. At the very minimum you should know how to read YAML and how to write YAML, particular declaring list and key-value pair in YAML. It's not a big topic but knowing basic really help during interview.

What is Java Constant and how do you declare it? static + final keyword Example Tutorial

Hello friends, ee are again here with new article that is on Java Constant will give all basics about the topic to our viewers or readers. you are looking for content to understand about Java Constant to have deep knowledge of Java basics then you will definitely learn from this article. The definition of "constant" states that it refers to something with a fixed value. Giving a variable in Java a fixed value that it will hold throughout the course of the program's execution creates a constant. Any variable must be converted into a constant by using the "static" and "final" modifiers in the manner described below:

Top 15 Spring Data JPA Interview Questions with Answers

Hello guys, If you are preparing for a Spring developer interview and looking for some Spring Data JPA Interview questions then you have come to the right place. Earlier, I have shared frequently asked interview questions on Spring Boot, Spring Cloud, Microservices, and Spring MVC in general, and in this article, I will share frequently asked Spring Data JPA Interview Questions with Answers for Java developers. Spring is one of the most popular and widely used frameworks. Spring Data JPA is an important part of the framework as it makes working with JPA or any JPA implementation like Hibernate easier.  

Top 18 Spring Cloud Interview Questions for Java Developers [with Answers]

Hello guys, If you are preparing for Java and Spring Boot Interview and looking for some Spring Cloud interview questions then you have come to the right place. Earlier, I have shared 15 Spring Boot Interview questions and today, I am going to share 15 Spring cloud interview questions for Java developers. These questions are good to revise essential Spring cloud concepts before interviews. Today is the world of cloud computing and most of the new Java development is happening on Cloud like AWS, GCP, and Azure. That's why it's very important for Java developers to learn about cloud and frameworks and libraries which support cloud-native development in Java, like Spring Cloud from Spring project.

Difference between JpaREpository, CrudREpository, and PagingAndSortingRepository

Hello and welcome to my blog post. In this article, we will delve into the world of Spring Data repositories and explore the key differences between three commonly used interfaces: JpaRepository, CrudRepository, and PagingAndSortingRepository. If you're a Spring Boot developer working with databases, understanding the distinctions between these interfaces is crucial for efficient data management. So let's dive right in and uncover the unique features and use cases of each repository interface.

How to convert ByteBuffer to String in Java [Example]

You can easily convert ByteBuffer to String in Java if you know how to convert byte array to String. Why? because it's very easy to convert ByteBuffer to a byte array and vice versa. All you need to do is call the ByteBuffer.array() method, it will return you the byte array used by java.nio.ByteBuffer class, later you can easily create String from that byte array. Though always remember to provide correct character encoding while converting byte array to String.

How to Convert Byte array to String in Java with Example

There are multiple ways to convert a byte array to String in Java but the most straightforward way is to use the String constructor which accepts a byte array i.e. new String(byte []) , but the key thing to remember is character encoding. Since bytes are binary data but String is character data, it's very important to know the original character encoding of the text from which byte array has created. If you use a different character encoding, you will not get the original String back. For example, if you have read that byte array from a file which was encoded in "ISO-8859-1" and you have not provided any character encoding while converting byte array to String using new String() constructor then it's not guaranteed that you will get the same text back? Why? because new String() by default uses platform's default encoding (e.g. Linux machine where your JVM is running), which could be different than "ISO-8859-1".

2 Ways to Print Custom String Value of Java Enum

We all know that how powerful the enumeration type in Java is, and one of the main strengths of enum is that they can implement an interface, they can have an instance variable and you can also override any method inside enum instance. In Java programs, we often need to convert Enum to String type, sometimes just to print values in the log file and other times for storing log into the database.  By default, when you print an enum constant, it prints its literal value e.g. if the name of the enum instance is RED, then it will print RED. This is also the value that is returned by the name() method of java.lang.Enum class. But, there are situations when we want a custom String value for an enum constant. 

How to compare String Objects in Java [Example Tutorial]

The String is a special class in Java, so is String comparison. When I say comparing String variables, it can be either to compare two String objects to check if they are the same, i.e. contains the same characters, or compare them alphabetically to check which comes first or second. In this article, we are going to talk about the right way of comparing String variables, but what is the wrong way? The wrong way is to compare String using the == operator. It is one area in which almost every Java programmer has made mistakes sometimes by comparing two String variables using the == operator. 

How to parse String to Date in Java using JodaTime Example

In this Java tutorial, we will learn how to parse String to Date using Joda-Time library, for example, we will convert date String "04-12-2014" to java.util.Date object which represents this date. Before Java 8 introduced its new Date and Time API,  Joda was only reliable, safe and easy way to deal with date and time intricacies in Java. Java's own Date and Time was not that great, starting from JDK 1.1 when they made java.util.Date a mutable object and when they introduced Calendar in Java 1.2. It is one of the most criticized feature of Java on communities along with checked exception and object cloning. 

How to create a Microservice in Java using gRPC? Example Tutorial

Hello guys, if you are wondering how to create Microservices in Java then you have come to the right place. Microservices architecture has gained significant popularity due to its scalability, modularity, and ease of deployment. When it comes to building microservices, gRPC (Google Remote Procedure Call) is an excellent choice for facilitating communication between services. In last few articles, I have shared how to build Microservices in Java using Spring Boot and How to build Microservices app using Quarkus and In this article, we will explore how to create a microservice application using gRPC in Java, along with a comprehensive step-by-step tutorial.

How to Create a Microservice using Quarkus in Java? Example Tutorial

Hello guys, Microservices architecture has become increasingly popular due to its flexibility, scalability, and ease of maintenance. When it comes to building microservices in Java, Quarkus is an excellent framework that provides a lightweight, fast, and efficient runtime. In this tutorial, we will explore how to create a microservice application using Quarkus in Java, along with a comprehensive step-by-step example. In last few articles, we have seen how to create Microservices using Spring Boot and Microservices using gRPC and in this article, we are going to see how to create a Microservice architecture using Quarkus framework. 

What is Service Discovery in Microservices? Client Side vs Server Side Service Discovery?

Hello guys, if you are wondering how different services communicate with each other in a Microservice architecture then you are not alone. Many Java programmer I have interviewed doesn't really know how different services in a Microservice architecture communicate with each other. n the past, I have shared several Microservices design patterns like  Event Sourcing, SAGA, Database Per Microservices, CQRS, API Gateway, Aggregator Design Pattern,  as well as best practices to design Microservices and in this article, I will talk about Service Discovery Pattern. In a distributed system architecture, Service Discovery plays a crucial role in enabling efficient communication between services. Service discovery patterns provide mechanisms for dynamically locating and accessing services within a network. 

How to log messages to File and Console in Java using Log4j? Example Tutorial

Hello guys, if you are wondering how to use a logging library like Log4j or SLF4j in Java then you have come to the right place. In this tutorial, you will learn how to implement logging in your Java program using the Log4j library. Log4j is a Java based open source library from Apache Software Foundation, which is widely used for logging messages in Java applications. In order to use log4j in your application, you first need to download log4j.jar files from https://logging.apache.org/log4j/2.x/download.html site. You can download either the zip version or the tar version depending upon whether you are running your Java program in UNIX or Windows. If you are using Maven then you can also add the following dependency in your pom.xml file and Maven will take care of downloading JAR files. 

How to Check if a Given Point Lies Inside a Triangle in Java? [solved]

Hello guys, its been long time I shared a coding problem so I thought to share one today and its one of the interesting one, how to check if a give point is inside a triangle or not? Determining whether a point lies inside a triangle is a common problem in computational geometry. It finds applications in various fields, such as computer graphics, robotics, and image processing. In this article, we will delve into the mathematical concepts behind this problem and explore a practical Java implementation. We will examine the algorithm step-by-step and illustrate it with code examples. Additionally, we will provide unit tests to ensure the accuracy and reliability of our implementation.

What is Constructor in Java and How it works? [with Example]

In simple word, Constructor is a method like a block of code which is called by Java runtime during object creation using new() operator. Constructor are special in the sense that they have the same name as the Class they are part of. They are also special in a sense that they are called by JVM automatically when you create an object. Have you ever thought about Why do you need a constructor? What benefits it provide? One reason is to initialize your object with default or initial state since default values for primitives may not be what you are looking for. One more reason you create constructor is to inform the world about dependencies, a class needs to do its job. Anyone by looking at your constructors should be able to figure out, what he needs in order to use this class.  For example, following class OrderProcessor needs a Queue and Database to function properly.

Difference between ReentrantLock vs synchronized lock in Java? Example Tutorial

In concurrent programming, synchronization is essential to ensure that multiple threads can safely access shared resources without causing data inconsistencies or race conditions. In Java, there are two primary mechanisms for achieving synchronization: ReentrantLock and the synchronized keyword.  The ReentrantLock and synchronized lock both serve the purpose of allowing exclusive access to critical sections of code, but they differ in terms of flexibility, performance, and the level of control they provide to developers. Understanding the nuances between these two synchronization approaches is crucial for Java developers aiming to build efficient and reliable concurrent applications.