Home > Java > javaTutorial > body text

Why should we follow Java naming conventions?

王林
Release: 2023-09-19 13:57:05
forward
744 people have browsed it

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;
Copy after login

Interface

  • Interface names should start with a capital letter.

Example

interface TutorialsPointInterface {
  // some statements
}
Copy after login

Class

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

Example

class TutorialsPointClass {
  // some statements
}
Copy after login

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() {
   }
}
Copy after login

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;
}
Copy after login

Constant

  • All characters should be uppercase.

Example

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!