giri
giri

Reputation: 27199

How can I recognize whether it is a class or interface in java by seeing the name?

I like to know how can I recognize whether it is a class or interface by seeing the name .. For example all class name starts with capital letters.. method name starts with small name.. Is there any specific way to recognize it?

Thanks

Upvotes: 3

Views: 209

Answers (5)

pavel
pavel

Reputation: 377

It depends on a naming convention. Some people follow IMap and Map; Map and MapImpl; Map and HashMap and etc. However, if the name is an adjective (like Serializable or Comparable) it is hard to imagine it would be a class. You can also use java.lang.Class.forName("MyInterface").isInterface() for that purpose.

Upvotes: 0

bdonlan
bdonlan

Reputation: 231103

The Java language makes no specific requirements on naming conventions. Indeed, you can define a method CamelCase() or a class lowercase. There are some recommended conventions, but the language won't stop you from breaking them - and they don't give a distinction between classes and interfaces.

Upvotes: 2

seanmonstar
seanmonstar

Reputation: 11444

Some people make all their interfaces start with an I. Like IPopup, or IController. I personally hate this.

I was taught that an interface should be an adjective, a class should be a noun. For example: Class: Controller, Interface: Controllable

Upvotes: 10

Sands
Sands

Reputation: 547

It all depends on the convention that the development teams are using. However, as a practice in java(including JDK) interface names are not different from classnames in terms of convention.

Upvotes: 1

bmargulies
bmargulies

Reputation: 100013

You cannot. Some people use a naming convention that distinguishes, but many people do not. For example, Sun does not.

Upvotes: 5

Related Questions