Found 34469 Articles for Programming

Which method must be implemented by all threads in Java?

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

894 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

292 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

225 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

428 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

How do we define tuple in Python?

Pranav Indukuri
Updated on 08-Nov-2022 10:39:05

386 Views

A tuple is a collection of python objects that are separated by commas which are ordered and immutable. Tuples are sequences, just like lists. The differences between tuples and lists are, that tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. Let us see about the creation of tuples in a detailed way. Empty Tuple Empty tuple means a tuple with no elements. Example Following is a way, to can create an empty tuple. temp=() print(temp) Output The following output is obtained on executing the above program. () Non Empty Tuple It ... Read More

How do you split a list into evenly sized chunks in Python?

Pranav Indukuri
Updated on 08-Nov-2022 10:34:19

2K+ Views

List is one of the frequently used data structures in python. A list is a data structure in python that is mutable and has ordered sequence of elements. Following is a list of integer values Example lis= [5, 10, 15, 20, 25] print(lis) Output If you execute the above snippet, it produces the following output. [5, 10, 15, 20, 25] Let us discuss various ways to split a list into evenly sized chunks in Python. Using slice operator You can print the list of elements with equally sized chunks, and they can be solved simply by using the ... Read More

How to get first 100 characters of the string in Python?

Vikram Chiluka
Updated on 19-Sep-2022 10:10:12

4K+ Views

In this article, we will show you how to get the first 100 characters of a string in python. The following are the 4 different methods to accomplish this task − Using While Loop Using For Loop Using Slicing Using slice() Function Assume we have taken an input string. We will return the first 100 characters of the input string using the above-specified methods. Method 1: Using While Loop Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Create a variable to store the input string. Create another variable to store ... Read More

How can we convert a list of characters into a string in Python?

Pranathi M
Updated on 11-May-2023 14:55:49

226 Views

A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. A list's items are any elements or values that are contained within it. Lists are defined by having values inside square brackets [], just as strings are defined by characters inside quotations. They are used to store multiple items in a single variable. In Python, strings are among the most widely used types. We can create them simply by enclosing characters in quotes. Python treats single quotes the same as double quotes. Creating strings is as simple as assigning a value to ... Read More

How would you make a comma-separated string from a list in Python?

Vikram Chiluka
Updated on 24-Aug-2023 15:03:30

51K+ Views

In Python, a list is an ordered sequence that can hold several object types such as integer, character, or float. In other programming languages, a list is equivalent to an array. Square brackets [] are used to denote it, and a comma (, ) is used to divide two items in the list. In this article, we will show you how to get a comma-separated string from a list using python. − Using join() method Using join() & map() Functions Using join() & List comprehension Assume we have taken a list containing some random elements. We will return ... Read More

Advertisements