Found 34494 Articles for Programming

What does the method addAll(Coll C)do in java?

V Jyothi
Updated on 20-Feb-2020 11:30:01

82 Views

The addAll(Collection

How to match at the beginning of string in python using Regular Expression?

Pranav Indukuri
Updated on 08-Nov-2022 10:56:52

10K+ Views

A regular expression in Python is a group of characters that allows you to use a search pattern to find a string or set of strings. RegEx is a term for regular expressions. To work with regular expressions in Python, utilise the re package. To match with the beginning of the string in python by using regular expression, we use ^/w+ regular expression. Here, ^ implies the start with. /w returns a match where the string contains any word characters (a z, A Z, 0 9, and underscore character). + indicates one or more occurrence of a character. ... Read More

How to use isAlive() method of Thread class in Java?

Sharon Christine
Updated on 20-Feb-2020 10:00:55

248 Views

The isAlive() method of the Thread class returns true if the thread is alive, which is anytime after the thread has been started but before it runs to completion.Exampleclass first implements Runnable {    public void run() {       try {          for(int i=0; i

Where and how can I create a private constructor in Java?

Swarali Sree
Updated on 25-Feb-2020 10:17:06

242 Views

We can use a private contractor in a Java while creating a singleton class. The Singleton's purpose is to control object creation, limiting the number of objects to only one. Since there is only one Singleton instance, any instance fields of a Singleton will occur only once per class, just like static fields. Singletons often control access to resources, such as database connections or sockets.ExampleThe easiest implementation consists of a private constructor and a field to hold its result, and a static accessor method with a name like getInstance().The private field can be assigned from within a static initializer block ... Read More

When a thread is created and started, what is its initial state?

Samual Sam
Updated on 30-Jul-2019 22:30:20

384 Views

When a new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread.After this newly born thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task.

Which method must be implemented by all threads in Java?

Monica Mona
Updated on 25-Feb-2020 10:22:01

873 Views

While creating a thread class we must override the run() method of the Thread class. This method provides an entry point for the thread and you will put your complete business logic inside this method.Exampleclass ThreadDemo extends Thread {    private String threadName;    ThreadDemo( String name) {       threadName = name;       System.out.println("Creating " +        threadName );    }    public void run() {       System.out.println("Running " +          threadName );       try {          for(int i = 4; i ... Read More

What is the Thread class in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:20

291 Views

The java.lang.Thread class is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently. Following are the important points about Thread −Every thread has a priority. Threads with higher priority are executed in preference to threads with lower priority.Each thread may or may not also be marked as a daemon.There are two ways to create a new thread of execution.One is to declare a class to be a subclass of Thread.Another way to create a thread is to declare a class that implements the Runnable interface. Read More

What is meant by a multithreaded program in Java?

Sharon Christine
Updated on 13-Mar-2020 04:54:40

224 Views

A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.Multi-threading enables you to write in a way where multiple activities can proceed concurrently in the same program.Exampleclass RunnableDemo implements Runnable {    private Thread t;    private String threadName;       RunnableDemo( String name) {          threadName = name;          System.out.println("Creating " + threadName);       }       public void run() { ... Read More

What is concurrency in Java?

Swarali Sree
Updated on 30-Jul-2019 22:30:20

426 Views

The ability to run multiple programs or parts of programs (threads) in parallel is known as concurrency.A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources especially when your computer has multiple CPUs. Multi-threading enables you to write in a way where multiple activities can proceed concurrently in the same program.

How can dead thread be restarted in Java?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

2K+ Views

A thread goes through various stages in its lifecycle. For example, a thread is born, started, runs, and then dies. New − A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread. Runnable − After a newly born thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task. Waiting − Sometimes, a thread transitions to the waiting state while the thread waits for another thread to perform a task. ... Read More

Advertisements