What is the role of naming convention rule in java?

Hii

Please describe............

Last updated:7/22/2019 12:44:16 AM

1 Answers

Rahul Roi
Rahul Roi

Java Naming Convention Rule:- 

  • It is a rule that is used to identify our identifiers in a code such as class, package, variable, constant, method, etc.
  • If we don’t follow naming convention rules, it may generate confusion in the code.

Advantages of naming convention rules:-

  • The code can be read easily.
  • The name should not start with a special character such as $, %, @.
  • Easy to understand the code.
  • If we know about the naming convention rule, we can easily write or implement the things in code.

Types:-

CamelCase (camelCase): If the name contains multiple words, the first letter of the word always in small letter and after that each word with a capital letter.

Example: lastName, mostTalented, etc.

PascalCase: If the name contains multiple words, the first letter of every word is in capital letter.

Example: ActionListner, AudioWriter, etc.

Method:-

  • Always use camelcase for the method name.
  • Such as println(), main(), etc.

Syntax:-

Class Student

{
Void M1()
{
Code
}
}

Class:-

  • Always use PascalCase.
  • Such as Employee, Student, etc.

Syntax:-

class Student
{
code
}

Variable:-

  • Always use camelcase.
  • Such as id, temp, etc.

Syntax:-

class Student
{
int id;
code
}

Package:-

  • Always use camelcase.
  • Such as java, lang, etc.
  • If the name contains multiple words, they are separated by dots (.) like java.lang.package.

Syntax:-

package java.lang.package; 
class Student
{  
code  
}  










Answer