Java String replace(), replaceAll() and replaceFirst() Method Example

In this tutorial, I will be sharing about the replace() method, replaceAll() method, replaceFirst() method, what is the difference between replace() and replaceAll() method, and how to replace a character in a String in Java.

Java String class provides three types of replace methods.
1. replace()
2. replaceAll()
3. replaceFirst()

Read Also: String Interview Questions and Answers

Let's dive deep into the methods:

1. Java String replace() method

According to Java docs, Java String replace() method returns a new String by replacing all the occurrences of old char or CharSequence with new char or CharSequence.

Java String class provides two replace() methods:

1. public String replace(char oldChar, char newChar)

Parameters:
oldChar: old Character
newChar: new Character

Returns: This method returns a string by replacing all oldChar with newChar.

2. public String replace(CharSequence target, CharSequence replacement) 
//Introduced in JDK 1.5

Java Concurrency: Thread Pool with Example

In this Java Concurrency tutorial, I will be sharing what is a Thread Pool, why do we need Thread Pool, and what are the different kinds of thread pools via executors provided by Java.

What is a Thread Pool

In simple words, Thread Pool is a group of worker threads. Worker threads are waiting for the task( or job). It can be reused many times.   

Why do we need Thread Pool

Creating a new thread in java is an expensive operation since it requires an Operating System to provide resources needed for the thread. In a large-scale application, there will be a significant memory management overhead for allocating and deallocating many thread objects. Using worker threads in the application minimizes the overhead due to thread creation. As a result, we use Thread Pool for large-scale operations.

Read Also: Multithreading Interview Questions and Answers

Where does this Thread Pool concept is implemented?

While designing web servers and application servers we can use the thread pool concept. When any DB connection is required it will check in the connection pool to get the DB connection.

7 Tools That Every Programmer Should Know

In this day and age, any person who has mastered a computer skill will never feel the need to search for a job. It takes time and effort to learn a skill, but once you have mastered it, you automatically equip yourself with the ability to sell your skill and make money from it. With the advancement of technology, it has become easier to put those skills to use. All you have to do pick the tool that best suits your expertise and then master that tool. If the students and young professionals who complain about low wages or unemployment could understand how important it is to learn a tool and how learning a tool could boost their professional standing, they would be doing it without hesitation.

Read Also: 5 Best Books on Object-Oriented Programming

For programmers, there are some tools that not only make your job simpler but also open upon a whole world of opportunities for you. A programmer who knows just the language he/she programs in falls ways behind a person who knows a couple of time-saving tools as well. This probably won’t be the first time you are hearing about these tools, and that is actually a serious problem. Most young professionals already know about these tools, they just don’t take the time to learn them properly and when they are assigned a task that involves usage of these tools, they often lack.

That is why we believe knowing about this list, and understanding each tool is very important. So if you are looking for some tools that would help you enhance your skills as well as your professional rank in the market, we have just the anecdote for you.

7 Essential Tools for Programmers

Here are the tools that could help put you on the map of professional developers and up to speed with the Software Industry. Understanding these tools is a very good way to maximize your work output and achieve success in your career as a software developer.

1. Github

5 Best Books on Object Oriented Programming - Must Read

Do you want to be the best at Object-Oriented programming?
If you do, do not miss out on what we are about to tell you. 

Among the most common programming concepts is OOP or Object-Oriented Programming, which lets you structure code in the practical environment. This is a platform that helps you to compose complex software by learning about objects and relations. It is an antecedent Procedural Programming concept, quite famously enforced by C, addresses the issue, and completes the function by producing computer code. Anything can be perceived as an object, and there state and behavior patterns can be found, which will allow you to emulate the object in coding.

Read Also:  OOPs Interview Questions

Therefore, reading a few books on Object-Oriented Analysis and Design is important for a qualified programmer before you know that there is hardly any point in studying OOP basics such as Abstraction, Encapsulation, Inheritance or Polymorphism. What counts, in fact, is the method of implementing certain concepts.

Below books are for any type of programmer. “Head First Oriented Analysis and Design”, which is fantastic for inexperienced people, and  "Elegant Objects", which is considered to inspire and is a  pleasure to read for skilled programmers. These also include critical books such as "Clean Code" and "Head First Design Patterns" which will educate you on the ways to produce good code using the concepts of OOP and SOLID design.

Best Books For Object-Oriented Programming


[Solved] java.lang.ClassNotFoundException with Example

In this article, we will discuss java.lang.ClassNotFoundException. This ClassNotFoundException is thrown when the classloader can not load the class from the system. ClassLoader is the class of the JVM core library that is used to load a class or find a class. ClassLoader throws this exception when it fails to load a class from application libraries. JVM uses the following methods to load class files.

1.    The forName method from Class class.
2.    The loadClass method from ClassLoader class.
3.    The findSystemClass method from the ClassLoader class.

Read Also: Difference between ClassNotFoundException and NoClassDefFoundError

1. ClassNotFoundException is a Checked Exception

ClassNotFoundException class inherited from ReflectiveOperationException class which has support of reflection functionalities. Also, ReflectiveOperationException inherited from Exception class. ClassNotFoundException is a checked exception. So we have to throw it from a method declaration or we should catch this exception.