Home  >  Article  >  Java  >  Why should we follow Java naming conventions?

Why should we follow Java naming conventions?

王林
王林forward
2023-09-19 13:57:05745browse

Why should we follow Java naming conventions?

Java Naming ConventionMake your program easier to understand by making it easier to read.

In Java, class names should usually be noun, in title form starting with a capital letter, with the first letter of each word capitalized. Interface names should usually be adjective, in title form starting with a capital letter, with the first letter of each word capitalized.

Why you should follow Java naming standards

  • Reduce the amount of effort required to read and understand source code.
  • Enables code reviews to focus on more important issues than syntax and naming standards.
  • Enable code quality review tools to focus primarily on important issues rather than syntax and style preferences.

Naming conventions for different types of identifiers

Package

  • Package names should be all lowercase.

Example

package com.tutorialspoint;

Interface

  • Interface names should start with a capital letter.

Example

interface TutorialsPointInterface {
  // some statements
}

Class

  • All words in the class name should begin with an uppercase character.

Example

class TutorialsPointClass {
  // some statements
}

Method

  • Method should be a verb that starts with a lowercase letter and has the first letter of each internal word capitalized.

Example

class TutorialsPointClass {
   void printMessage() {
   }
}

Variables

  • The first word should be lowercase and inner words should start with a capital letter.
  • Variable names should not begin with an underscore_ or dollar sign $ character.

Example

class TutorialsPointClass {
   int rollNum;
   String firstName;
   String lastName;
}

Constant

  • All characters should be uppercase.

Example

class TutorialsPointClass {
   public static final int MAX_score = 100;
}

The above is the detailed content of Why should we follow Java naming conventions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete