• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Little confuson.

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A field in an interface can only be static, public and final. Its implicit. I would suggest you go for a class.
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and of course fields in interfaces are generally considered "not done" (Effective Java item 17).
 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you don't have any behavior or data to implement, developers typically would use an interface in these cases.
 
reply
    Bookmark Topic Watch Topic
  • New Topic