Teaching girls to learn Java (22): Come on, one article thoroughly understands Java naming conventions, linux virtual machine technology

  • Preferably an adjective such as Runnable

  • Try not to omit the first letter of the word

Let's look at an example:

interface Printable {}

03. Method

Method naming should follow the following rules:

  • Must start with a lowercase letter

  • Preferably a verb, such asprint()

  • Can contain multiple words, the first letter of the first word is lowercase, and the first letter of other words is capitalized, for exampleactionPerformed()

Let's look at an example:

void writeBook(){}

04. Variables

Variable naming should follow the following rules:

  • Must start with a lowercase letter

  • Cannot start with special symbols, such as &, $, _

  • Can contain multiple words, the first letter of the first word is lowercase, and the first letter of other words is capitalized, for examplefirstName

  • It's best not to use single characters, unless int ait's a local variable, say

Let's look at an example:

int age;

05. package

Package naming should follow the following rules:

  • Should be all lowercase

  • Can contain multiple words, use "." between words to connect, for examplejava.lang

Let's look at an example:

package com.cmower

06. Constant

Constants should be named according to the following rules:

  • Should be all caps

  • Can contain multiple words, use "_" between words to connect, for exampleMAX_PRIORITY

  • Can contain numbers, but cannot start with a number

Let's look at an example:

static final int MIN_AGE = 18;

07. CamelCase naming

The naming convention in Java follows the camel case rule, that is, the first letter of the first word is lowercase, the first letter of the second word is capitalized, the third is also capitalized, and so on, just like the hump of a camel, one high and one low, It looks more coordinated.

Based on actual work experience, methods, classes, interfaces, etc. are named in camel case, and (some programmers like) variables are separated by English underscores, and words are all lowercase.

I think both methods are advisable.

08. Thanks

Well, my dear readers and friends, the above is the entire content of the twenty-second article of "Teaching Girls to Learn Java". Isn't it relaxed and lively, and learning technology is no longer boring, right? The students who bought the column came for the second brother's reputation, I can only say that you are very discerning.

Teaching girls to learn Java (21): This article takes you to understand all the concepts of object-oriented programming

Teaching Girls to Learn Java (Twenty): This article takes you to a thorough understanding of annotations in Java

Teaching sisters to learn Java (19): Detailed explanation of the continue keyword

Teaching Girls to Learn Java (18): Break Keyword Detailed Explanation

Teaching girls to learn Java (17): do-while loop

Teaching Girls to Learn Java (16): Detailed explanation of while loop

Teaching Girls to Learn Java (15): Detailed explanation of for loop

Teaching girls to learn Java (14): Detailed explanation of switch statement

Teaching Girls to Learn Java (13): Detailed explanation of if-else statement

Teaching Girls to Learn Java (12): Java Keyword Encyclopedia

Teaching Girls to Learn Java (11): Introduction to Operators

Teaching Girls to Learn Java (10): Introduction to Unicode Character Set

Teaching Girls to Learn Java (9): Data Types in Java

Teaching girls to learn Java (8): Getting to know Java variables for the first time

Teaching girls to learn Java (7): What is JVM?

Teaching girls to learn Java (6): What is the difference between JDK, JRE and JVM?

Guess you like

Origin blog.csdn.net/m0_65484000/article/details/122032424