Skip to main content

JAVA Identifiers and Code Comments

 

Lest's Start JAVA Programming

Part 6

Identifiers

Identifiers are the name we use in JAVA to identify variables, methods, classes etc. These identifiers are human readable words and we can use any word as identifiers. but we can't use any of the JAVA keywords as identifiers, that's just a one rule java have when creating identifiers there are more rules we need to follow.


Let's take look at what are the rules we need to follow when we creating identifiers in our code.

  1. Should be one word.
    • When we creating identifiers we must use one word for that. like "age", "score".
    • but there are some places we need to use two or more words to create meaning full identifiers.
    • In that scenarios we can use "_" to connect the words. or we can follow camel case practice to create identifiers.

  2. Can be any length.
    • Can use word of any length.
  3. Can't use keywords and reserve words.
    • JAVA have set of keywords that if use for language features. we can't use those words as our identifiers.
  4. First letter must be a character.
    • We can't start identifier name from a number. we must start from a character.


Comments

What is a comment ?

Comment is a line or multiple lines that skip when code get execute. If we put a comment when code execute or when code get compile those comments are not execute and also not effect compile process.

Why we need comments ? / Why we use them ?

We mainly use comments to improve the readability of the code. When we write a code that should be able to read by other developer or our self after sometime. Code comment help with that.

Another reason is for documentation purposes, in JAVA and other languages we can generate documentation for our code using some tools those tools depend on the comments we put in our code.

Another reason is we can skip some parts of our code while we are developing the program or application.

We can put comment to describe method logic, what are the parameters, what is this method returning or we can put comment to describe a class. We can use comments to describe every logic of the program or code.

There are different ways we can put a comment in our code.
  1. //
    • when we put // in front of code line that line become a comment. compiler and runtime will skip that line.
  2. /*  */
    • We can use this to put multiline comments. and this can also call block comment.
    • comment will start from /* and it will go until it found */ then comment is ended.
  3. /**      */
    • This is also can use to comment out multiple code lines.
    • and also really useful for describe and documenting process.
    • with this we can mention return type, parameters easily.

Comments

Popular Posts

What is a Computer Program ?

Let's Start JAVA Programming - [Part 01]

Lest's Start JAVA Programming - [Part 04]