Found 7442 Articles for Java

Which method must be implemented by all threads in Java?

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

1K+ 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

430 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

317 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

538 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

What is maven automatic build tool in Java eclipse projects?

Janani Jaganathan
Updated on 13-Oct-2022 11:46:50

844 Views

Maven is a powerful open-source project management tool developed by the Apache Group to build and manage any Java-based project. Additionally, this tool makes Java developers' work easier while developing reports, checking the builds, and testing automation setups. As we stated above, Maven is primarily used to build and manage many Java-based projects, Java eclipse project is the integrated development environment (IDE) that often hits to mind. Hence, by reading this article, you will learn everything about Maven automatic build tool and what it means in Java Eclipse Projects. Understanding Maven Maven is a popular automatic build tool that focuses ... Read More

What is the difference between PATH and CLASSPATH in Java?

Revathi Satya Kondra
Updated on 17-Dec-2024 23:03:52

1K+ Views

In Java, the terms Path and ClassPath refer to different things and are used for different purposes. Let's discuss them one by one with a suitable example − Path The path environment variable is used to specify the set of directories that contains execution programs. When you try to execute a program from the command line, the operating system searches for the specified program in the current directory and, if available, executes it. In case the programs are not available in the current directory, the operating system verifies in the set of directories specified in the 'PATH' environment variable. Setting ... Read More

What is the Eclipse keyboard shortcut for "System.out.println()" in Java?

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

14K+ Views

To get System.out.println() line in eclipse without typing the whole line type sysout and press Ctrl + space.

What is the Eclipse keyboard shortcut for "public static void main(String[] args) " in Java?

Ramu Prasad
Updated on 20-Feb-2020 05:29:13

9K+ Views

To get public static void main(String[] args) line in eclipse without typing the whole line type main and press Ctrl + space then, you will get the option for the main method select it.

Does Java support default parameter values for a method?

Sravani S
Updated on 16-Jun-2020 11:12:26

3K+ Views

Java does not support the concept of default parameter however, you can achieve this usingMethod overloadingUsing method overloading if you define method with no arguments along with parametrized methods. Then you can call a method with zero arguments.Variable argumentsIn Java methods parameters accept arguments with three dots. These are known as variable arguments. Once you use variable arguments as a parameter method, while calling you can pass as many number of arguments to this method (variable number of arguments) or, you can simply call this method without passing any arguments.ExampleLive Demopublic class Sample {    void demoMethod(String... args) {   ... Read More

Advertisements