Skip to main content

JAVA: Identifiers and Keywords.

JAVA

Want to know what is identifier ? what are keywords? to know that read the following carefully and completely.

Identifier and keywords are Tokens, unit of instructions.

Identifiers:

Identifiers are user defined names which consists of sequence of letters and digits.

As the name itself says identifiers are used for identification to know what is what purpose.

Identifiers are used to name objects, class methods variable, packages, label and interfaces in the program.

As we know keywords are user defined, the one who writes the program should follow the rules and name it accordingly to their convenient.

Rules to write identifiers.
  • The first letter must be in alphabet following can be of letter or digits
  • Special characters are not allowed except underscore sign
  • It cannot be keyword or reserved words
  • Can be any length, keeping short will reduce complications
  • They are case-sensitive uppercase and lowercase are different

Some valid examples
            Subject_1
            Balance
            acc_no
            TOTAL

Some in valid examples
            subject-1
            10_bal
            import

Keywords

Keywords are also known as Reserved words.There are around 48 keywords.

By the name itself we can indicate all the words has special operation and it has a fixed meaning.

Keywords can not be variables.

Key words are:
  1. Abstract - to declare abstract class, implementation of interface.
  2. Assert - used to define assert statement exception Boolean condition in a program.
  3. Boolean - to declare a variable as Boolean that is true or false.
  4. Break - used to break current flow of loop switch statement at some conditions.
  5. Byte - to declare variable that can store 8-bit data.
  6. Case - catch the exception generated by true statement.
  7. Char - Declares variable as character which can hold 16-bit.
  8. Continue - used to continue the flow of loop at specific conditions.
  9. default - specifies the default block of statement in switch statements.
  10. goto* - used just in case wanted to add in the latest version but it does not support.
  11. do - uses in control statement to declare a loop.
  12. Double - declare a variable that can hold a 64-bit floating point number.
  13. else - used to indicate the alternative branch in an if statement.
  14. enum - used to define a fixed set of constant.
  15. Extends - used to indicate that a class is derived from another class or interface.
  16. Final - used to indicate the variable holds a constant value.
  17. Finally - block of code in true catch structure.
  18. Float - used to declare a variable that can hold 32-bit floating point number.
  19. For -used to start a for loop, execute a set of instructions repeatedly when some conditions become true.
  20. If - used to test the condition, a block of statement is executed, if condition is true.
  21. Implements - used to implement an interface.
  22. Interfaces -  makes available and accessible to the current source code.
  23. Instanceof - used to test whether the object is an instance of a specific class or implements an interface.
  24. int - used to declare a variable that can hold 32-bit signed integer.
  25. Interface - declare an interface that have only abstract method.
  26. Long - used to declare a variable that can hold 64-bit integer.
  27. Native - used to specify that a method is implemented in native code using JNI.
  28. New - used to create a new objects.
  29. Null - used to indicate that a reference does not refer to anything.
  30. Package - used to declare a java package that includes classes.
  31. Private - it is used to indicate that a method or a variable may be accessed only in a class in which it is.
  32. Protected - accessibility is within packet and outside the package but with proper inheritance only.
  33. Public - used to indicate that a item is accessible everywhere.
  34. Return - used to return from a method when its execution is completed.
  35. Short - Used to declare a variable that can hold 16-bit integer.
  36. Static - used to indicate that a variable or a method is a class method.
  37. Strictfp - used to restrict the floating point calculation to ensure probability.
  38. Super - reference variable that is used to refer parent class object.
  39. Switch - contains switch statements that executes code based on test values.
  40. Synchronized - used to specify the critical section or method in multi-threaded code.
  41. This - used to refer the current object in the method or a constructor.
  42. Throw - used to explicitly throw an exception, mainly used to throw.
  43. Throws - used to declare exception.
  44. Transient - used in serialization. If any data member is defined as transient, it will not be serialized.
  45. Try - used to start a block of code that will be tested for exception.
  46. Void - used to specify that a method does not have a return value.
  47. Volatile - used to indicate a variable which may change asynchronously.
  48. While - used to start a while loop.


Check out the interesting history of Java.

The important features of java.

The structure of java.

The environment of java.

Also the complete process to execute java program.

Comments