Coding Standards in Java: Naming Classes and Variables - Prof. Fathima, Slides of Programming Languages

The importance of coding standards in java programming and provides guidelines for naming classes and variables according to established conventions. It also identifies issues with a given program and suggests improvements.

Typology: Slides

2022/2023

Uploaded on 02/05/2024

nasreen-manalath-v
nasreen-manalath-v 🇮🇳

4 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Unit 1 -
Programmi
ng
HNC
pf3
pf4
pf5
pf8

Partial preview of the text

Download Coding Standards in Java: Naming Classes and Variables - Prof. Fathima and more Slides Programming Languages in PDF only on Docsity!

Unit 1 -

Programmi

ng

HNC

Objectives

  • (^) To describe the purpose of coding standards.
  • (^) To implement some coding standards supported in Java.

Coding Standards

  • (^) Programming is a way to communicate with computers by giving instructions

to them to perform a particular task.

  • Thus, our act of writing codes is a form of communication not only with

machines but also with other developers.

  • (^) Coding standards, otherwise known as coding conventions, is a set of rules

that programmers adhere to improve the standards of writing code.

  • (^) Adhering to coding standards helps in producing code that is easier to

understand, debug, modify, and collaborate on by multiple developers.

Revisiting Variable Program

The following program does not adhere to

the coding conventions.

Can you identify what the problems are?

Coding Standards – Class Name

  • (^) When naming a class, it is advisable to follow these conventions:
    • (^) Class names should be nouns, in upper camel case with the first letter of each

internal word capitalized.

  • (^) Try to keep your class names simple and descriptive.
  • (^) Use whole words-avoid acronyms and abbreviations (unless the abbreviation is

much more widely used than the long form, such as URL or HTML).

  • (^) Example: class MyDetails, MyFirstJavaProgram

Coding Standards – Variable Name

  • (^) When naming a variable, it is advisable to follow these conventions:
    • (^) Variable names follow lower camel case where the first word is in lowercase and subsequent words begin with a capital letter.
    • Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.
    • (^) Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use.
    • One-character variable names should be avoided except for temporary "throwaway" variables.
    • Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.