Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes Difference between object and instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Difference between object and instance" Watch "Difference between object and instance" New topic
Author

Difference between object and instance

Ramya Dhurga
Greenhorn

Joined: Jun 15, 2004
Posts: 10
What is the difference between object that we are creating for class and the instance we are creating for interface
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You cannot create an instance of an interface, since interfaces cannot be instantiated.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ramya Dhurga
Greenhorn

Joined: Jun 15, 2004
Posts: 10
I didnt get u?
eg:

MyInterface f=new MyClass();
MyClass m=new MyClass();

What is the difference between these two?
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hi,
I am quite sure that this is not the correct place to post this question. Any way let me answer your question.

interface MyInterface {
}

class MyClass implements MyInterface {
}


number one rule you have to remember is that, you can't have like this;
MyInterface m = new MyInterface(); // error
reason is that interfaces don't have constructos.

But when you have a 'has a' or 'is a' relationship like the one I havwe shown the above example, it's possible to have
MyInterface m = new MyClass(); cause, MyClass has implemented MyInterface. Hope I have explained in a way that you can understand. ....


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Originally posted by Ramya Dhurga:
What is the difference between object that we are creating for class and the instance we are creating for interface


Interface -> you are defining the contracts and leaving the implementation details to class.

class -> Can have general methods & variables. Class can implement n number of interfaces..

Say for example, You can have a customer class

class Customer
{
private String name;
private String customerID;
private String address;

public String getName(){ }
public String getCustomerID() {}
public String getAddress(){}

.... you will have corresponding getter & Setter methods.
}


and if you are defining CustomerInterface to get the customer ID and Name

class CustomerInterface
{
public String getName();
public String getCustomerID();
}


Now you are defining the CustomerImpl class which this interface

class CustomerImpl implements CustomerInterface
{
private String name;
private String customerID;
private String address;

public String getName(){ }
public String getCustomerID() {}
public String getAddress(){}

}


Now in the client program,

Customer customer1 = new Customer();
CustomerInterface customer2 = new CustomerImpl();
you can call all the methods defined in the customer class but in the customer2 object you can call only the interface methods & not the other methods. if you call getAddress() will give you compile time error.

The basic thing is the second one will make sure that it has implemented the contracts definec the interface.

Regards,
M.S.Raman
Siplin Ayishoto
Greenhorn

Joined: Nov 25, 2002
Posts: 9
. o O (Only if I could guess the context correctly)

IMHO interfaces are used indicating classes, in conjunction with factories,
etc., in a design similar to IOC/design-by-contract.

Hope this helps.

-Siplin
Garry Garrson
Greenhorn

Joined: Nov 24, 2004
Posts: 5
What is LDAP & Active Directory?


I am going to take a stab at my questions so as to help direct your answers if that makes any sense.


1.) What is Active Directory (is active directory the repository for user name, PWD other confidential information like access rights and what groups this user belongs to ? )

2.) What is LDAP (is L D A P - a standard if so, for what?)

3.) How do they relate to each other ?


If someone could help me understand these concepts (for the purpose of a single user sign on to more than one application from differnt vendors better I would much appreciate it.

From what I understand (although no experience so probably wrong) if an application (say one you built) needs to integrate to a third party application where both your application and the 3rd party require authentication each product must support LDAP . Where does Active Directory come into it? I guess there are different LDAP & Active Directory vendors?



Question: This probably sounds ridiculous but why could you not just use encrypted XML to get authenticated on the 3rd party application (to send user name & password)?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between object and instance
 
Similar Threads
java
difference between creating instance of a class and using class.forname()
Related to Object
object Vs instance
what is the difference??