Java Application FAQ

Source: Internet
Author: User
Tags variables variable
Q: In Java, what is a local Variable, a member Variable, a Instance Variable? What are the similarities and differences between them?








A: Local variable is a partial variable that is defined within a method or a block of statements. When the procedure or statement block is executed, the local variable variable is immediately released.








Instance variable is corresponding to class variable. Simply put, Instance Variable is not required to be decorated with static, each instance creates a new Instance Variable, and class Variable is decorated with static and is not created with the creation of class instances. Instances of all classes share a copy of the class variable.








As for member Variable, it is not accurate to say. My understanding is instance Variable +class Variable. In the language specification, no member variable this claim.








asked: What conditions must be met to reset the method?








Answer:








1. The method name is the same;








2. The return type is the same;








3. The parameters are exactly the same, including the type, number, and order of the parameters.








Q: What are the Java naming conventions?








Answer: 1. Use the full descriptor to accurately describe a variable, field, or class.








For example, the name used can be FirstName, grandtotal, or Corporate Customer. Although names like X1, y1, or FN are shorter and easier to enter, they do not provide any information on what they represent. This makes it difficult to understand, maintain, and enhance the code.








2. Use the terminology applicable to the domain.








If your users refer to their customers as customers, use the term customer for this class instead of the client. Many developers have made the mistake of trying to create generic terminology for concepts when more relevant terminology already exists in the industry or domain.








3. Use abbreviations cleverly and sparingly.








This means that you should maintain a list of standard short form (abbreviated), select them wisely, and maintain consistency when you use them. For example, if you want to use the short form of character arithmetic, select one of AR, Ari, or art, record the selected abbreviation (which is not important), and use only this one.








4. Use case mixing to enhance the readability of names.








should usually use lowercase letters, but capitalize the first letter of the class name and interface name and capitalize the first letter of all non-starting words.








5. Capitalize the first letter of a standard acronym.







The
name often contains standard abbreviations, such as SQL representing "Standard Query Language". Names such as SQLDatabase that represent properties, or sqldatabase of classes, are easier to read than SQLDatabase and SQLDatabase.








6. Avoid long names (a maximum of 15 characters is appropriate).








Although the class name allimplemented Iterfacesandsubclass may be a better class name (which, of course, is somewhat exaggerated in this example), the name is obviously too long and should be renamed to a shorter name.








7. Avoid names that are too similar or only differ in capitalization.








should not use both variable names MyObject and myobjects, and neither myoradatabase nor anoradatabase should be used at the same time.








asked: I want to use the TAB key to move between the input fields, what should I do?








: This feature is especially useful when users have to type a lot of text. The following program will show you how to enable users to switch input focus between input fields:








public boolean KeyDown (Event evt,int key)





{





if ((char) key== ' \ t ')





{





Component current_field= (Component) evt.target;





if (Current_filed!=last_field)





Current_field.nextfocus ();





Else





First_field.requestfocus ();





return true;





}





}














Note: Pressing the TAB key when the last component Last_field gets the focus moves the focus back to the first component First_field.








Q: In Java, what exactly is a static variable?








: In program development, we often hope that a variable and method do not change with the object, even when the object is not created to access the data and methods, then the data and methods can be added static keyword, Data that is modified by static is called a static variable (data) and the method is called a static method. Static variables have the same address in memory, so the values of static variables are definitely the same for different objects of the same class.











Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.