Why are Strings Immutable in Java?
The immutable strings help in achieving the required data safety and performance in a Java application with help of underlying string pool.
“Core Java” is Sun’s term, used to refer to Java SE, the standard edition and a set of related technologies, like the Java VM, CORBA, etc. This is mostly to differentiate from others like Java ME or Java EE. “Core Java” is Oracle’s definition and refers to subset of Java SE technologies.
The Core Java technologies and application programming interfaces (APIs) are the foundation of the Java Platform, Standard Edition (Java SE). They are used in all classes of Java programming, from desktop applications to Java EE applications.
The immutable strings help in achieving the required data safety and performance in a Java application with help of underlying string pool.
Java compiler rearranges the statements we write in a Java program for performance improvements. Learn to generate the byte code for a class file to see how they have been rearranged.
Learn Java Secure Hashing algorithms in-depth. Java examples of MD5, SHA256, SHA512, PBKDF2, BCrypt, SCrypt algorithms with salt to create secure passwords.
Learn the basics of CountDownLatch and how to use it in real-life applications, its methods and use it to control the flow of application.
Since Java 7, the try-with-resources statements allow declaring AutoCloseable resources in a try block that JVM will close automatically.
Polymorphism in Java is the ability to create member functions or fields that behaves differently in different programmatic contexts.
The Path class, introduced in the Java SE 7 release, is one of the primary entry points of the java.nio.file package. If our application uses Java New IO, we should learn more about the powerful features available in this class. In this Java tutorial, we are learning 6 ways to …
Learn to read and write excel files in Java using Apache POI library – with examples. Learn to add and evaluate formula cells and add color formatting also.
ToStringBuilder is a utility class provided by apache commons lang library. ToStringBuilder is a utility class provided by apache commons lang library. It provides a consistent and better control over what and how much data, an object should expose using toString() method and in which format. It can also help …
In Java, there are different ways of reading and parsing CSV files. Let’s discuss some of the best approaches such as OpenCSV, Super CSV etc.
Use the constructor parameters wisely to reduce the number of unnecessary objects and improve the performance of ConcurrentHashMap.
Reason When you are working with java libraries that internally depend on cglib, then it’s very normal to encounter the below error: This error is due to an incompatible version of cglib with additional jar files in your project, such as asm. Solution The solution is very easy. Just place …
Apache HttpClient simplifies the interactions with RESTful APIs by supporting various HTTP methods, headers, and request configurations. This article will explore how to consume REST APIs using Apache HttpClient5 with examples. 1. Setup Before diving into implementation, we need to import the latest version of Apache HttpClient. Next, we will …
Learn to design a good custom key class for HashMap. As a rule, always honor the hashcode and equals contract, and make the class immutable.
Learn to read small and large files from the filesystem using the Java NIO APIs Path, FileChannel, ByteBuffer and MappedByteBuffer.
Java NullPointerException (NPE) is an unchecked exception and extends RuntimeException. NullPointerException doesn’t force us to use a try-catch block to handle it. NullPointerException has been very much a nightmare for most Java developers. It usually pop up when we least expect them. I have also spent a lot of time …
Using the entrySet() specifically is more powerful and yields better performance than using the keySet() for iteration over a HashMap in Java.
We can detect the infinite loop in a LinkedList using “Floyd’s Cycle-Finding Algorithm” or Hare and Tortoise approach.
This Java article compares the performance of an ArrayList iteration using simple for-loop, enhanced for-loop, list iterator and stream API.
Suppressed exceptions, as name suggest, are exceptions thrown in the code but were ignored somehow. If you remember try-catch-finally block execution sequence and how they return any value or exceptions, you will recall that exceptions thrown in finally block are suppressed if an exception is thrown in try block also. …
In Java Concurrency, until we have a particular reason, it is always recommended to implement the Runnable interface to create new threads.
Learn the differences between sleep() and wait() methods in Java. Learn when o use which method and what effect they bring in Java concurrency.
In Java, a synchronized block of code can only be executed by one thread at a time. Also, java supports multiple threads to be executed concurrently. This may cause two or more threads to access the same fields or objects at same time. Synchronization is the process which keeps all …
Java is passed by value and not pass-by-reference. If it had been pass-by-reference, we should have been able to C like swapping of objects.
Java palindrome example. Learn palindrome programs in Java using the reverse method, for loop and recursion methods.
A thread dump is a list of all the Java threads that are currently active in a Java Virtual Machine (JVM). There are several ways to take thread dumps from a JVM. It is highly recommended to take more than 1 thread dump while analyzing any problem such as deadlock …
In this tutorial, learn to read or parse XML document using Java SAX parser API for XML example. Learn to parse XML elements to java objects.
Learn to parse an XML document and read the value of an attribute using XPath in Java. We can read the attribute value for all its occurrences in the document, or only for selected nodes in the XML. 1. XPath Expression for Attributes In XPath, the ‘@’ is used to …
All of us have come across situations when we have to parse user input for validation. Other fields such as text or numeric are rather easy, but Java date validation is a little bit difficult, and a small error can leave the application in an unstable state. 1. Java Date …
Password validation is the need of almost all applications today. There are various ways to validate passwords from writing everything manually to using third-party available APIs. In this password validation tutorial, we are building a password validator using regular expressions. 1. Regex for Validating the Passwords ((?=.*[a-z])(?=.*d)(?=.*[@#$%])(?=.*[A-Z]).{6,16}) The above regular …
A regular expression defines a search pattern for strings. This pattern may match one or several times or not at all for a given string. The abbreviation for regular expression is regex. Regular expressions can be used to search, edit, and manipulate text. Regex meta characters are special symbols that …
Java enum example. The purpose of enum is to enforce compile time type safety. Learn enum constructors, methods, inheritance, EnumMap and EnumSet etc.
Learn to use underscores between digits in Java numerical literals such as int, long or double. It helps in improving the code readability.
Java program to send email through Gmail SMTP server using TLS or SSL protocols. Also, send plain text emails as well as attachments.
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.
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.
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.
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.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.