Вопрос

I’m interested to know this as they are part of Java api [J2SE].

Generally it a convention to use "_" in variables name to indicate that they're instance variable or for some other special purpose [but defiantly it depends on programmer’s taste].

But there are few classes listed in Java API [J2SE], whose names are starting with underscore ("_").

Really Oracle have any special meaning/purpose for this underscore? [If yes,] Why kind of difference these classes have when compared with other classes in same API?

http://docs.oracle.com/javase/7/docs/api/

_BindingIteratorImplBase
_BindingIteratorStub
_DynAnyFactoryStub
_DynAnyStub
_DynArrayStub
_DynEnumStub
_DynFixedStub
_DynSequenceStub
_DynStructStub
_DynUnionStub
_DynValueStub
_IDLTypeStub
_NamingContextExtStub
_NamingContextImplBase
_NamingContextStub
_PolicyStub
_Remote_Stub
_ServantActivatorStub
_ServantLocatorStub

Это было полезно?

Решение 2

Those classes are not really Java classes, they are part of the CORBA implementation and are generated from programming-language-independent IDL definitions - the naming convention is a CORBA one.

Другие советы

Generally it a convention to use "_" in variables name to indicate that they're instance variable or for some other special purpose

Not in Java. A convention of this kind is required in C++ because of the constructor syntax for member variables. There is no such requirement in Java, hence it is rarely used, and only by people who appear to think they're still programming in C++.

The classes you mention were all defined by OMG in the early 1990s according to the naming restriction imposed by CORBA IDL, which again have nothing to do with Java.

There is no special reason for that, again.. it's a matter of taste.

However, if you want to fully follow the Java Naming Conventions, you should avoid appending _ to the name of a class.

It's redundant to append _ to class members as well, most IDEs color these fields with a different color and you can easily distinguish them from local variables. I see this piece of code more elegant:

public MyConstructor(int field) {
    this.field = field;
}

Than

public MyConstructor(int field) {
    _field = field;
}

But again, it's still a mater of taste and it might be that your company works with it, so you don't want to be the first one to break it.

Naming Conventions for Packages, Class and variables

Here's the table of naming convention that one should follow while writing java code.

You can start a class name by '_' but it is not recommended.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top