Java interview questions: Java variable naming

Face questions related searches:
the Java programming foundation spring recruit class face questions of (a)

Spring Java programming trick interview questions of the base class (B)

Today give you about a lower common interview questions:

Java variable naming

Please name the following variables.

Here Insert Picture Description
Test sites : The interview questions job seekers mainly on programming habits, good programming habits are essential qualities of a good Java developers. Job seekers should master the basic Java naming convention, so write out code to do enough to regulate and easy to read.

The frequency of occurrence : ★★★

[A] face questions in object-oriented programming, for the class, a variable named object, a method is very skilled, for example, case sensitivity, and the like used at the beginning of different letters. But their book, chasing its source, when named as a resource, should describe the spirit and uniqueness of the two characteristics, in order to ensure no conflict between resources, and easy to remember.

1. Naming packages

Java package name is lowercase-word. Every Java programmer can write their own Java package, in order to protect the uniqueness of the latest Java programming specification for each Java package naming of a programmer is required before the name of the package you define plus a unique prefix. Since the domain name on the Internet will not be repeated, so programmers generally use their own domain name on the Internet as a unique prefix own package.

For example: net.frontfree.javagroup.

2. Class naming

Class names must begin with a capital letter, other letters in the word lowercase. If the class name consists of several words, it is recommended that the first letter of each word are in uppercase, such as TestPage. If the class name contains the word abbreviations, it is recommended that each letter of the word are in uppercase, such as XMLExample. As the classes are designed to represent objects, it is recommended to select a noun should be named class.

3. Naming of

The name of the method in the first word should begin with a lowercase letter, after the word it is recommended to begin with a capital letter.

For example: sendMessge.

4. Constant naming

Constant names should use uppercase letters, and pointed out that the full meaning of the constants. If a constant name consists of multiple words, it is recommended to separate these words with an underscore.

For example: MAX_VALUE.

5. Named parameters
naming naming method parameters and specifications of the same, and to avoid confusion caused by reading program, please try to ensure in the parameter name is a word of the situation, named parameters as clear as possible.

6. Javadoc comments

In addition to the common Java annotations may employ addition, Java language specification also defines a special comment, also known as Javadoc comments, API code which is used for recording. Javadoc comment is a multi-line comments, with / * begin with, and to / end, comments may contain some HTML tags and specific keywords. The benefits of using Javadoc comments, written comments can be automatically translated into a document, eliminating the hassle of separate programming documents. E.g:

   /**

   *This is an example of

   * Javadoc

   *

   *@author darchon

   *@version 0.1, 10/11/2002

   */

In the very beginning of each program, usually a general description and copyright information program with Javadoc comments. May be added in the main program for each class, interface, method, variable Javadoc annotation, each annotation beginning with the first sentence of this class, interface, method, variable functions performed, these words should be a single line summarized to highlight its role in the back of this sentence can follow a more detailed description paragraphs.

After the description of paragraphs to be accompanied by some special Javadoc comments at the beginning of paragraph tag, e.g. @auther and @version in the example above, these passages will be displayed in a particular manner in the generated document.
While adding a comment does not make a poor design procedure into a good program, but if you write a program in accordance with the programming specification, and add comments to a good program, but it can help to write a beautiful design, efficient operation, and easy to understand program. Especially in multiplayer collaboration of the same project, programming specifications it is very important. As the saying goes, "Preparation may quicken the workers", it takes a little time to adapt to the Java programming specification is good.

Answers :( conform to the naming rules.)
Here Insert Picture Description

Above book "Java programmer interview secrets" from the interview

Here Insert Picture Description

The book has been added to the VIP membership card, as long as the purchase of VIP membership card to receive free reading hundreds of e-books, in addition to this free VIP cards let you read, there is more interest in waiting for you to lead, pull down ↓
Here Insert Picture Description

The method of reading e-books are as follows:

Open CSDN APP (software store search "CSDN" to find Oh) -> Login CSDN account -> Learning -> e-book

Here Insert Picture Description

Published 16 original articles · won praise 48 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_37649168/article/details/104398511