UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

I want to know what are the differences between runnable and thread class implementation except they are class and interface and how to decide which is better at what time ...

Asked by Last Modified  

21 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Java/J2EE, B.E./B.Tech/MCA SubjectsTraining

1) Implementing Runnable is the preferred way to do it. Here, you’re not really specializing or modifying the thread’s behavior. You’re just giving the thread something to run. That means composition is the better way to go. 2) Java only supports single inheritance, so you can only extend one class. 3)...
read more
1) Implementing Runnable is the preferred way to do it. Here, you’re not really specializing or modifying the thread’s behavior. You’re just giving the thread something to run. That means composition is the better way to go. 2) Java only supports single inheritance, so you can only extend one class. 3) Instantiating an interface gives a cleaner separation between your code and the implementation of threads. 4) Implementing Runnable makes your class more flexible. If you extend thread then the action you’re doing is always going to be in a thread. However, if you extend Runnable it doesn’t have to be. You can run it in a thread, or pass it to some kind of executor service, or just pass it around as a task within a single threaded application. 5) By extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same runnable instance. read less
Comments

Industry expert and professional lecturer/trainer

Well it depends on your need. Generally you extend any class when either you want to over ride or use all or most of the methods and interface you want to implement the methods. In Thread class there are tons of methods but we override only one run() method and Runnable interface has only one method...
read more
Well it depends on your need. Generally you extend any class when either you want to over ride or use all or most of the methods and interface you want to implement the methods. In Thread class there are tons of methods but we override only one run() method and Runnable interface has only one method to implement that is run(). So its a performance benefit and common sens to use Runnable interface than Thread class. read less
Comments

IT Professional Trainer working with a reputed Institute. Headquarters: Hyderabad

Thread vs. Runnable in Java 1) Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance and can not extend or inherit another class in Java. 2) In Object oriented programming extending a class generally means...
read more
Thread vs. Runnable in Java 1) Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance and can not extend or inherit another class in Java. 2) In Object oriented programming extending a class generally means adding new functionality, modifying or improving behaviors. If we are not making any modification on Thread than use Runnable interface instead. 3) Runnable interface represent a Task which can be executed by either plain Thread or Executors or any other means. So logical separation of Task as Runnable than Thread is good design decision. 4) Separating task as Runnable means we can reuse the task and also has liberty to execute it from different means. Since you cannot restart a Thread once it completes. Again Runnable vs Thread for task, Runnable are winner. 5) Java designer recognizes this and that's why Executors accept Runnable as Task and they have worker thread which executes those task. read less
Comments

Java,J2EE,Spring,Webservices,Hibernate,Cloud And Android Expertise

Runnable is better if your class still wanted to extend or implement any other class. If your class is responsible only for thread activities and if you dont want to extend any other class then use Thread.
Comments

Here are some of my thoughts on whether I should use Thread or Runnable for implementing task in Java, though you have another choice as "Callable" for implementing thread which we will discuss later. 1) Java doesn't support multiple inheritance, which means you can only extend one class in Java so...
read more
Here are some of my thoughts on whether I should use Thread or Runnable for implementing task in Java, though you have another choice as "Callable" for implementing thread which we will discuss later. 1) Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance and can not extend or inherit another class in Java. 2) In Object oriented programming extending a class generally means adding new functionality, modifying or improving behaviors. If we are not making any modification on Thread than use Runnable interface instead. 3) Runnable interface represent a Task which can be executed by either plain Thread or Executors or any other means. so logical separation of Task as Runnable than Thread is good design decision. 4) Separating task as Runnable means we can reuse the task and also has liberty to execute it from different means. since you can not restart a Thread once it completes. again Runnable vs Thread for task, Runnable is winner. 5) Java designer recognizes this and that's why Executors accept Runnable as Task and they have worker thread which executes those task. 6) Inheriting all Thread methods are additional overhead just for representing a Task which can can be done easily with Runnable. These were some of notable difference between Thread and Runnable in Java, if you know any other differences on Thread vs Runnable than please share it via comments. I personally use Runnable over Thread for this scenario and recommends to use Runnable or Callable interface based on your requirement. read less
Comments

Trainer

If you dont have any parent class go for Thread . If you have any parent class then go for Runnable . Both are the same.
Comments

If we want to make a sub class as thread class, we must use Runnable interface instead of Thread class, because already the sub class is extends from another super class, hence it cannot extends another class (Thread). Multiple inheritance is not supported in java
Comments

explore the depth of 'C' language..

The difference is that when u r implementing an interface u will have to provide the bodies for all the functions inside the class in which u r implementing.
Comments

Java Trainer

Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance andcan not extend or inherit another class in Java. But by implementing Runnable Interface we can get a chance to extends one more class. By...
read more
Java doesn't support multiple inheritance, which means you can only extend one class in Java so once you extended Thread class you lost your chance andcan not extend or inherit another class in Java. But by implementing Runnable Interface we can get a chance to extends one more class. By extending Thread, each of your threads has a unique object associated with it, whereas implementing Runnable, many threads can share the same runnable instance. read less
Comments

IT Professional Trainer with 15 years of experience in IT Industry

Thread vs Runnable in Java is always been a confusing decision for beginners in java. Thread in Java seems easy in comparison of Runnable because you just deal with one class java.lang. Thread while in case of using Runnable to implement Thread you need to deal with both Thread and Runnable two classes....
read more
Thread vs Runnable in Java is always been a confusing decision for beginners in java. Thread in Java seems easy in comparison of Runnable because you just deal with one class java.lang. Thread while in case of using Runnable to implement Thread you need to deal with both Thread and Runnable two classes. Though decision of using Runnable or Thread should be taken considering differences between Runnable and Thread and pros and cons of both approaches. This is also a very popular thread interview questions and most of interviewer are really interested to know what is your point of view while choosing Thread vs Runnable or opposite. In this java article we will try to point out some differences between Thread and Runnable in Java which will help you to take an informed decision. read less
Comments

View 19 more Answers

Related Questions

As a fresher I have done Python training, but hardly getting response from any company. What should I do?
only having training in Python is not enough to be called for intervew. Better you should get real time certification course form reputed organisation with smart hand-on real project exposure. Try to have...
Yamini
0 0
6
What are the advanced Java topics?
Mainly divided in three parts JDBC,SERVLET,JSP and each one contains multiple sub topics
Ganesh
0 0
5
Anyone knows how to convert jsf primeface into bootstrap?
You already can use some bootstrap CSS classes and helpers but if you want give style to each UI control, you will need to set the primefaces theme to none.Then you will need to give some style to each...
Pradeep
1 0
9

Do you provide java full stack ?

Yes I can teach java fullstack
Bodem
0 0
5
What is the difference between abstraction and encapsulation?
Encapsulation is wrapping, just hiding properties and methods. Encapsulation is used for hide the code and data in a single unit to protect the data from the outside the world. Class is the best example...
Neval

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

A Tip for the beginners.
The world of programming languages right now is too dense, and too big for any beginner. But at the same time, because of so many options available, it's easier too. You can start with any language that...

Demand of java in industry
Java is one of the widest use language in the industry all around the world As in software market more than 80% software, platform developed using java. Java comes in three flavours:- j2se for window based...

Prashant Tomer

0 0
0

Basic Concepts of Web Designing
An introduction to domain names, web servers, and website hosting 1)What is the web? In a nutshell, the web is a whole bunch of interconnected computers talking to one another. The computers (on the...

Java complete reference-herbert schildt
Sample program: class Sample { public static void main(String args ) { System.out.println("Sample") ; } } Program explanation: Keyword used in line 1- class The name...

Inheritance In Java
Inheritance: The process of getting properties and behaviors from one class to another class is called inheritance. Properties: Variables Behaviors: Methods The main purpose of the inheritance...
D

Deleted U.

1 0
0

Recommended Articles

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more