Naming convention for objects in java

自闭症网瘾萝莉.ら 提交于 2019-11-30 18:21:00

Just call it car. Hungarian notation is not used by Sun/Oracle.

Name your variables in a manner which describes their use. But you don't need to indicate the type in the variable name. You already specified the type in the variable declaration. IDEs will show you the type of the variable if you mouse-over them so that information is always readily available.

You should use lowercaseStartingCamelCase for variable names and method names, and UppercaseStartingCamelCase for class names.

If you want to read how Sun/Oracle do things, you can read their Code Conventions for the Java Programming Language.

Your example is a bit too trivial. In reality you would never name a field of object type "Car" as "car". Likewise you never name an "Integer" type as "integer".

Instead, the use names that tell the reader what the field is used for. Some examples:

private Transport preferredTransportMethod;

private int invoiceCounter;

Prefixing field type is not used commonly is Java. However, class member are sometimes prefixed with lower case "m" to prevent accidental self assignments in setter methods.

private long mTripDurationMillis;

Name your objects what they are, it makes reading and refactoring easier.

naming conventions for objects in java are just names. For example

Car car = new Car("Ferrari");

The remnants of Hungarian notation have been abandoned mainly because of the added support the IDE's have provided for navigation.

class name in small letters is Sun/Oracle standard.

when you are working for a company,

depending upon project naming conventions it may vary.

Car car=new Car(); //good to follow

if It is Singleton pattern,you may give a name like below

 private static final Car singletonCar=new Car();

Being you are senior , after all I can suggest you some naming convention related to your doubts. As we know all class name are started with first capital letter, suppose class "MyTest" when object we need to create of this class it should be "mytest". Object name should be in this format. According to the jakarta project menifesto I found this type of convection and the are following . Other than jakarta, Sun API including IDE for development also they are using this. Hope ,it will help you.Yes I am new.Thanks for your helpful information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!