answersLogoWhite

0

chase that feeling like ive been looking for something thats good for the rich and the blind and the poor

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

What java interface must be implemented by all threads?

Runnable interface


If Runnable interface is better than Thread class than why you are using Thread class What is the need for Thread class?

Though implementing Runnable interface is better approach than inheriting from Thread class but there are certain methods available in Thread class like join,sleep or yield which does not available in Runnable interface and programmer can not use them unless he has object of Thread class. This is why we should have Thread class Object. Rupesh Raghani


Why do you need runnable interface?

A Runnable Interface is one that is used to create a Java Thread... A Thread can be created in two ways and using the Runnable Interface is one of them. Example: public class Test implements Runnable { public void run(){ .... } } The Runnable interface would have an abstract instance of the method run() which needs to be implemented in the class which wants to create a Thread.


Explain the concept of interfaces in java with a suitable example for the same?

interface works like an abstract class it has methods which are not defined its job is to give a general idea about the class(generic) the class can have its own functions but interface makes java program to include all the functions or methods present in the interface there are ibuilt interfaces like runnable example in threads it is runnable it makes compulsory to the class to include all the methods in interface if you dont want that then use abstract key word before class eg: interface a{void meth(int i);} class one implements a{ void meth(int i) System.out.print(i); //all other members of class// if dont use meth function it will give an error for big projects certain general functions are necessary which have to be there everywhere it gives general idea of what the program is doing


What is the Difference between header file and package?

A header file is a file in C and C++ programming languages that contains function declarations and macro definitions that can be shared across multiple source files. It typically has a .h extension. On the other hand, a package is a collection of related classes, interfaces, and sub-packages in Java programming. Packages provide a way to organize code and prevent naming conflicts. In summary, a header file is specific to C and C++ languages, while a package is specific to Java.

Related Questions

How do you implement runnable interface?

By implementing Runnable in our class and by overriding the run() method of Runnable interface


What java interface must be implemented by all threads?

Runnable interface


If Runnable interface is better than Thread class than why you are using Thread class What is the need for Thread class?

Though implementing Runnable interface is better approach than inheriting from Thread class but there are certain methods available in Thread class like join,sleep or yield which does not available in Runnable interface and programmer can not use them unless he has object of Thread class. This is why we should have Thread class Object. Rupesh Raghani


Why do you need runnable interface?

A Runnable Interface is one that is used to create a Java Thread... A Thread can be created in two ways and using the Runnable Interface is one of them. Example: public class Test implements Runnable { public void run(){ .... } } The Runnable interface would have an abstract instance of the method run() which needs to be implemented in the class which wants to create a Thread.


What is the difference of interface and class?

A (concrete) class defines all his methods and can have any kind of instance variable and is declared with the 'class' keyword. Unlike an interface that doesn't implements any of his methods and his variables must be static and final. An interface is defined with the 'interface' keyword.//This is a classpublic class MyClass{public String name;private int age;public void myMethod(){//do something}}//This is a interfaceinterface MyInterface {public static final String name;public static final int age;public void myMethod(); // This method is not implemented}An other difference is that a class can be inheritance by other class but a interface must be implemented using the keyword 'implements'.interface Runnable(){void run();}public class MyOtherClass implements Runnable{public void run(){// insert interesting code here}}


What are the two ways of spawning a thread in Java?

You can create a Thread in Java by using two ways. 1. Extending the Thread class public class Test extends Thread { ..... } 2. Implementing the Runnable Interface public class Test implements Runnable { ... }


Explain the concept of interfaces in java with a suitable example for the same?

interface works like an abstract class it has methods which are not defined its job is to give a general idea about the class(generic) the class can have its own functions but interface makes java program to include all the functions or methods present in the interface there are ibuilt interfaces like runnable example in threads it is runnable it makes compulsory to the class to include all the methods in interface if you dont want that then use abstract key word before class eg: interface a{void meth(int i);} class one implements a{ void meth(int i) System.out.print(i); //all other members of class// if dont use meth function it will give an error for big projects certain general functions are necessary which have to be there everywhere it gives general idea of what the program is doing


What is a tagging interface type?

A tagging interface type in Java is an interface that has not defined methods such as the java.io.Serializable interface.


What is intrface in java?

interface is a list of methods which implements that interface


What is the Difference between header file and package?

A header file is a file in C and C++ programming languages that contains function declarations and macro definitions that can be shared across multiple source files. It typically has a .h extension. On the other hand, a package is a collection of related classes, interfaces, and sub-packages in Java programming. Packages provide a way to organize code and prevent naming conflicts. In summary, a header file is specific to C and C++ languages, while a package is specific to Java.


What is interface in java?

Interface is collection of abstract methods which has only declaration and no implementation


What is interface incompatibility?

interface incompatibility means two inherited methods are not Override