Both the StringBuffer and StringBuilder classes are used to create mutable strings. But StringBuffer are synchronized, which means that only one task is allowed to execute the methods. Consider the following program which appends a “-” mark to a StringBuilder object by 100 threads. import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; public class MutableStringDemo{ static StringBuilder stringBuilder =…… Continue reading What is the difference between StringBuilder and StringBuffer classes.
Category: Java
Java Thread synchronization
To enhance the speed of a program, we use multiple threads to access the same resource at the same time. But, this kind of shared resources can produce unexpected results due to this simultaneous access made by multiple threads. The following example demonstrates the problem. Here, we have a sample bank system that contains 4…… Continue reading Java Thread synchronization
Java Thread pools.
Suppose there is a server software which creates new threads for each and every client requests. When there are a million number of clients are requesting different tasks through the server, the server must create million of threads for them which is a very expensive operation and could limit throughput to cause poor performance. The…… Continue reading Java Thread pools.
Java Thread Methods
Java provides a bunch of methods to manage threads that we create. Few of most important methods are listed down below. MethodUsagegetName() Returns the thread name getPriority()Returns the thread priority sleep()Suspend a thread for a period of timejoin()Wait for a thread to terminateisAlive()Determines if the thread is still running Now let’s see how each of…… Continue reading Java Thread Methods
Multithreaded programming with Java.
A thread is the smallest sequence of instruction executions which can be scheduled by an OS scheduler to run on a CPU. A thread is living inside a process and it is considered as a lightweight process. Threads are the fundamental model of program execution in a Java program, and the Java language and its…… Continue reading Multithreaded programming with Java.
Introduction to Threads and Concurrency.
A thread is simply a sequence of programmed instructions that can be executed independently in CPU. A single process of a program can have several threads, these threads are executed parallelly at the same time within the same process. There are two type of processes based on the number of threads. Single-threaded processes. :- Only…… Continue reading Introduction to Threads and Concurrency.
How to create a simple “Welcome to Java” program in Java
The first program that you develop when you are learning any programming language is the “Hello World” program. So, let’s create a “Hello World” program in java. But I would like to do different, instead of creating a “Hello World” program let’s create a “Welcome to Java” program. Note: A “Hello World” program is a…… Continue reading How to create a simple “Welcome to Java” program in Java
How to download and set the PATH for OracleJDK on Windows OS
Step:1 go to this link, https://www.oracle.com/technetwork/java/javase/downloads/index.html at the top of the page you will see a title “Java SE Downloads”. Note: Java has different Programming Language platforms, 1. Java SE(Standard Edition) – for normal use (it is the core platform of all other Editions).2. Java EE(Enterprise Edition) – for large scale development (like servers).3. Java…… Continue reading How to download and set the PATH for OracleJDK on Windows OS
How to install JDK(Java Development Kit) on Ubuntu OS
Ubuntu supports for a default JDK which is OpenJDK(not OracleJDK ). what are the differences between OpenJDK and OracleJDK?. OpenJDK is a free and open-source implementation of Java SE Platform Edition with contribution from Oracle and open Java community.OracleJDK is developed and maintained by the Oracle itself whereas OpenJDK can be developed by Java Community.Oracle…… Continue reading How to install JDK(Java Development Kit) on Ubuntu OS
Let’s start High-level programming with java
The most interesting topic in Software field that each of everyone likes to learn is programming. Because programming is not a thing that only Software professionals do, it is a thing that covers many fields all around the world. It is rare to find a person who does not know the meaning of ‘Computer Programming’.…… Continue reading Let’s start High-level programming with java