Keyword, Identifiers, Comments

Keywords

In a computer language, keywords are reserved word for particular uses.

Identifiers

The names of classes, variables, and methods are collectively called identifiers.
Java identifiers must adhere to the following rules:

  1. Begin with an alphabet character
  2. White space is not permitted
  3. Special characters are not allowed excpet the $ and the _
  4. Java keyword is not permitted

There are the naming conventions that most Java programmers follow.

  1. Class names should be nouns which start with an uppercase letter, in mixed case with the first letter of each internal word capitalized. (ex, Account)
  2. Method names should be verbs which start with a lowercase letter, in mixed case with the first letter of each internal word capitalized. (ex, getAccountNo())
  3. Variable names should be nouns which start with a lowercase letter, in mixed case with the first letter of each internal word capitalized. Variable names should not start with underscore _ or dollar sign $ characters.(ex, accountNo)
  4. Constant names should be all uppercase with words separated by underscore _. (ex, SWIFT_CODE)

We haven't coverd Java constants yet.
How to create constants in Java wille be explained later.

In the real world, bank accounts are not objects because they are invisible.
But in the software world, it can be objects.
Follow the naming conventions and create a bank account class.

class Account {
  String accountNo; 
  int balance;
	
  String getAccountNo() { 
    return accountNo;
  }
	
  void setAccountNo(String account) { 
    accountNo = account;
  }

  int getBalance() { 
    return balance;
  }
  void deposit(int amount) {
    balance = balance + amount;
  }

  void withdraw(int amount) {
    balance = balance - amount;
  }
}

Comments

Keywords and identifiers are essential elements of the code.
Althouah not required, comments are also a component of the code.
Comments are text which is added to make the source code easier to understand by a programmer.
Comments are ignored by compilers.
The Java language supports three kinds of comments.

//text

The compiler ignores everything from // to the end of the line.

/*
 text
*/

The compiler ignores everything between /* and */.

/**
 text
*/

The compiler ignores everything between /** and */.
These comments are used when automatically generationg Java documentation using the JDK's Javadoc.