简体   繁体   中英

Can someone correct me if i'm wrong with this naming rules please?

i have a big test tomorrow and i'm new to java and computer science and i have a little blackout and need your help, i will write the naming rules in java according to what i think it is and please correct me if i'm wrong:

naming classes = every word will start with uppercase letter and each other word will start with uppercase letter. for instance: TodaysDate, Tester2.

naming final values each word will be written with uppercase letters with '_' sign separate them. for instance : MAX_SPEED,TESTER_2; naming instance variables : every word will start with a lowercase letter and each other word will start with uppercase letter. for instance: maxSpeed, speed1;

naming methods : every word will start with lowercase letter and each other word will start with uppercase letter. for instance: public int getX();

naming local variables in methods every word will start with lowercase letter and a '_' sign will separate each other word. all other words will start with lowercase letters.for instance: int max_speed,tester_1;

i think that's it. please correct me if i forgot something or wrote a wrong rule. Thank you !

It's rather uncommon to use _ to separate words in local variables, which are lowercase. Usually _ is reserved for things written in uppercase to clearly separate words eg static final fields.

There is no right and wrong answer here. You project is free to pick up any naming convention but it's important to stick to it. Choosing a well established convention might be desirable, the two most common are Sun/Oracle Naming Convention and Google Java Style Guide . They are usually well supported by various tools eg code formatter in IDE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM