Naming convention for objects in java

后端 未结 6 642
-上瘾入骨i
-上瘾入骨i 2021-01-04 09:12

I had started programming in java 2 years back. Seniors in our project at that time had advised me to append \'obj\' to the name of the object which is being created.

<
相关标签:
6条回答
  • 2021-01-04 09:38

    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.

    0 讨论(0)
  • 2021-01-04 09:41

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

    0 讨论(0)
  • 2021-01-04 09:47

    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.

    0 讨论(0)
  • 2021-01-04 09:47

    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.

    0 讨论(0)
  • 2021-01-04 09:48

    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;
    
    0 讨论(0)
  • 2021-01-04 09:52

    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();
    
    0 讨论(0)
提交回复
热议问题