SCJP – Java Identifiers

Java identifiers needs to be a Legal Identifier and it should adhere to Sun’s Java Code Conventions and  JavaBeans Naming standards

Rules for Legal Identifier.

  • Start with letters or $ (Currency Character) or _(Underscore).
  • After first character it can be any combination of letters, numbers currency characters.
  • case-sensitive
  • Java Keywords can not be used as Legal Identifier
  • No limit to the number of characters.

Java Code Conventions

Java Code Conventions is the coding standard published by Sun. this can be downloaded from here.

Classes and Interfaces :

  • First letter should be in capital.
  • If several words then camelCase
  • Class names should typically be Noun
  • Interface names should typically be Adjectives.

Methods

  • First letter should be lowercase
  • If several words then camelCase
  • Verb names should typically be verb-noun pairs.

Variables

  • First letter should be lowercase like cameCase format
  • meaning full names

Constants

  • Uppercase letters
  • Underscore separator between words.

JavaBeans Standards

  • JavaBeans standard helps all the Java developer to understand the tools and java component written by different Java developers.
  • Java classes with properties. Method that sets value are called setter methods and Method that retrieves value is called getter methods.
  • getter method prefix must be “get” and if the property is not Boolean “is” if the property is Boolean
  • setter method prefix must be set.
  • the first letter of the property name after the “get”, “set” or “is” must be uppercase.
  • Signature of setter method will be public and return type is void with argument whose value is set to the property.
  • Signature of getter method will  be public with no arguments and property type as return type.
  • Methods that are used to add or remove listeners must follow JavaBean n
In Category: Java, SCJP

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 0 Comments
No comments yet. Be the first.

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.