aspose file tools*
The moose likes Java in General and the fly likes Little confuson. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Little confuson." Watch "Little confuson." New topic
Author

Little confuson.

Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
Hi all I have little coufsion about interface and class.
I have to use some own defined Constant in my project what should be the best approach.Should I make an interface or a class which will have the dsired constant varaibles.
so please tell me whihc one is best in terms of memory,performace..


package com.test;
public class MyconstantClass {
static final int WXY=9;
static final int ABC=9;
}

or

package com.test;
public interface MyConstantInterface {
int ABC=1;
int xyz =3;
}


Thanks
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

A field in an interface can only be static, public and final. Its implicit. I would suggest you go for a class.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
and of course fields in interfaces are generally considered "not done" (Effective Java item 17).


42
Vijay Kumar
Ranch Hand

Joined: Jul 24, 2003
Posts: 260
Hi jhon acc to you A field in an interface can only be static, public and final. Its implicit. I would suggest you go for a class. I agreed but whts the harm if I am using it..... & why would you sugeest for class.
my requirment is for public constant which can be use in any class. so I have define in interface.
please tell me some concrete soloution..
Thanks
scotta irwin
Greenhorn

Joined: Sep 21, 2005
Posts: 10
Since you don't have any behavior or data to implement, developers typically would use an interface in these cases.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Little confuson.