My Articles:
We all know how to create objects of any class. The simplest method to create an object in Java is using new keyword. Let’s explore other methods to create objects without new keyword. 1. Using Class.newInstance() The Class.forName() loads the DemoClass in memory. To create an instance of this class, …
Learn to identify dead code and unreachable code in Java, with example. It may be asked in your Java interview coding problems as a puzzle. Let’s sovle it.
Learn to compile and run java programs in Hindi by changing the default character encoding in eclipse to UTF-8.
HATEOAS is a constraint on REST that says that a client of a REST application need only know a single fixed URL to access it. Any and all resources should be discoverable dynamically from that URL through hyperlinks included in the representations of returned resources.
In this Java tutorial, learn about asynchronous and synchronous exceptions in Java. Also, learn how they are different with checked and unchecked exceptions. 1. Asynchronous and synchronous exceptions Normally Java differentiates the exceptions into two categories on basis of “timing” when they are discovered. These categories are checked and unchecked …
Java diamond operator. Denoted with <> characters. It is also called elvis operator. It removes redundant type information from parameterized types in generics.
We all know that the easiest way of deep cloning (with some performance overhead) or deep copy is serialization. Java serialization involves serializing the object into bytes and from bytes to the object again. We suggest using in-memory deep cloning whenever it is the only need and we don’t need …
Learn to print simple array and 2d array in Java. For nested arrays, the arrays inside array will also be traversed in this Java print array example.
Java Serialization – Dos and don’ts for correct serialization and deserialization. Learn to use serialVersionUID, readObject and writeObject with example.
Java double brace initialization example. Learn what is double brace initialization, it’s performance and what each brace means?
Declaring similar static methods in parent and child classes is called method hiding. For non-static methods, it is method overriding.
Hibernate one to many mapping is made between two entities where the first entity can have a relation with multiple instances of the second entity but the second can be associated with only one instance of the first entity. It is a 1 to N relationship. For example, in any …
Hibernate/JPA @ManyToMany association example using join column in the database. Learn to create unidirectional and bidirectional mappings.
Learn to create and manage one-to-one relationships between entities in a hibernate/JPA based application using @OneToOne annotation.
Step by step hibernate hello world example with maven and eclipse. Learn to create, configure and store hibernate 5 entities in the database.
We all are aware of the functional responsibilities of garbage collector [GC] in Java. But only few try to go real deep on how garbage collection works. You are not one of them and that’s why you are here. In this Java memory management tutorial, we will try to understand …
Learn to find duplicate words in string or sentence along with their counts, using the Collections and Java 8 Stream with Examples.
A clone is an exact copy of the original. The java clone() method provides this functionality. Learn to create shallow copy, deep copy and using copy constructors in Java.
Java XPath Example. XPath is a syntax used to describe parts of an XML document. In this tutorial, we will see some useful ways to apply xpath to extract information from an XML file.
It is overwhelmingly easy to write bad unit tests that add very little value to a project while astronomically inflating the cost of code changes. This post will go through the JUnit best practices we must consider while writing the test cases. In programming, “Unit testing is a method by …
In contrast to traditional custom exceptions, the new approach uses static inner classes for every new exceptional scenario.
Have you ever tried to reason why Java’s main() method is public, static and void? Why its name is main? What happens inside JVM when you invoke main() method? What is the purpose of main method? Let’s find out. Since Java 21, we can create instance main() methods that do …
Learn Java finalize() signature, the purpose of finalization, how can we call finalize() method manually, and why you should not use it.
Abstract factory is a factory of factories; a factory that groups the individual but related/dependent factories together without specifying their concrete classes.
Learn about immutable objects, records and collections in Java and create a Java class immutable step by step with examples.
All of us must have gone though interview questions related to String class in java. These String interview questions range from immutability to memory leak issues.
The factory pattern simply generates an instance for client without exposing its instantiation logic to the client.
To create a singleton, make the constructor private, disable cloning, disable extension and create a static variable to house the instance
Easy to follow examples of sorting a collection of objects in any order using Comparable or Comparator Interfaces.
Java ThreadPoolExecutor & BlockingQueue example to run a demo task with fixed size thread pool. Also, learn to use RejectedExecutionHandler.
In Java, abstraction and encapsulation help in creating abstract actors in the system. Encapsulation is the realization of abstraction.
Learn about java abstract classes vs interfaces in detail and when to use interfaces and abstract classes in solving design issues in Java 8.
In simple words, java abstraction captures only those details about an object that is relevant to the current perspective. Learn more about abstraction in java.
Learn to create a deadlock in Java programmatically, with an example. Also, learn to detect deadlock and how to solve a deadlock situation.
Learn how hashmap works internally in java with example. Learn the hashmap internal implementation analysis, collision resolution and Java 8 hashmap update.