Keywords In Java Programming Language

Keywords are reserved words in a programming language. It's a token that helps the Java compiler to understand the Java code efficiently. Each keyword has its own property that helps to develop any application. As per the official site, Java has a total of 50 keywords.  In Java keywords are predefined hence it's not allowed to be a variable, method name, class name, or object name. As a programmer, it's necessary to know about all the Java keywords.

Important key points

  • Java keywords are always in lowercase
  • Keywords can't act as identifiers or else the Java compiler will throw a compile-time error
  • true, false, and null are not keywords they are literals in Java
  • const and goto are deprecated Java keywords
  • Keyword count may increase when a new Java version is released in the market

List of Java Keywords

  1. abstract: Used to create an abstract class and abstract methods(method just declared no implementation). Abstract Java keyword helps to achieve abstraction.
  2. assert: Used in assertion testing to check the condition is true. Assert Java keyword used in testing and debugging code.  
  3. boolean: Used as a data type in Java that can hold either true or false values only. Boolean java keyword are helpful in condition and logical-based operations.
  4. break: Used only in running loop or switch to break the flow of the program. Break java keyword are declared inside a condition of loop or switch.    
  5. byte: Used as a data type in Java that can hold integer values from -128 to 127. Byte java keyword size is 1 byte.
  6. case: Used in the switch-case statement to add different cases to match the expression.   
  7. catch: Used in exception handling to catch the exception throws by try block. Catch java keyword is used as a block in exception handling.
  8. char: Used as a data type in Java that can hold single 16-bit Unicode characters. Char java keyword size is 2 bytes.
  9. class: Used to create a class and it's a blueprint or template in Java program.
  10. const: It's a deprecated keyword  (reserved but not used). It was used to define constants in Java.
  11. continue: Used in a running loop that can skip the current iteration and execute the next iteration.
  12. default: Used in a switch-case statement, the default case will execute only when no other cases match in the switch.
  13. do: Used to create a do-while loop which executes first and checks the condition. So this behavior guarantees that this loop is executed at least once.
  14. double: Used as a data type that can hold decimal values up to 16 decimal digits. Decimal Java keyword size is 8 bytes.
  15. else: Used along with the if statement, else will execute only when the if condition fails. 
  16. enum: Used to create enumerated types, the enum java keyword consists of a fixed set of constants.
  17. extends: Used to achieve inheritance and abstraction. Extends Java keyword helps to inherit the property from one class to another class.
  18. final: Used in class, method, and variable. Final java keyword makes the value in the variable constant, the method can't be overridden and the class is not allowed to inherited.
  19. finally: Used in exception handling, finally block will always execute in a Java program.  
  20. float: Used as a data type that can hold decimal values upto 9 digits. Float java keyword size is 4 bytes.
  21. for: Used to create a for-loop statement that does iterative operations
  22. goto: It's a deprecated keyword(reserved but not used). Goto java keyword was used as a label to change the flow of the program.
  23. if: Used to create a conditional statement. If Java keyword execute a block of code when the condition matches.
  24. implements: Used in the class header to implements one or an interface.
  25. import: Used before a class header to import all required classes or packages from the Java library.
  26. instanceof: Used to check whether an object is an instance of a specific class, subclass, or interface. 
  27. int: Used as a data type in Java that can hold integers from -2,147,483,648 to 2,147,483,647. Int java keyword size is 4 bytes.
  28. interface: Used to create an interface that contain 100% abstract classes before Java 8. After the Java 8 release interface has static and default concrete methods. 
  29. long: Used as a data type in Java that can hold integers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Long Java keyword size is 8 bytes.
  30. native: Used in the method to indicate that this method includes native code(other programming languages like C and C++).
  31. new: Used to instantiate a class by providing required memory for the new object. New Java keyword is also used to create object of the array.
  32. package: Used to organize the class, interface, and other files efficiently. Package java keyword declared at the top and it indicates the location of the class/interface.
  33. private: Used as an access modifier in method and data variable. Private java keyword restrict access within the same class. 
  34. protected: Used as an access modifier in inner class, data variable, and methods. Protected java keyword restrict the access within the same package and child class of an outside class.
  35. public: Used as an access modifier in class, data variables, and methods. Public Java keyword including method, class, and data variables can be accessed from anywhere. 
  36. return: Used in nonvoid methods to return an output. Return java keyword should be the last statement to execute in a method.
  37. short: Used as a data type that can hold integer values from -32,768 to 32,767. Short Java keyword size is 2 bytes. 
  38. static: Used in data variables, nested classes, blocks, and methods that make it a class-level property or a class can directly access the data variable and method without object creation when the static java keyword is declared.
  39. strictfp: Used to get the same result from the floating or decimal point calculation on every platform. Strictfp java keyword helps to achieve Java as a platform independence programming language. 
  40. super: Used to call the constructor or methods of the superclass(immediate parent) from the child class.
  41. switch: Used to create a switch-case statement that contains multiple cases with the condition to match and one default case that executes when none of the cases matches.
  42. synchronized: Used to synchronize the multi threads execution. Synchronized java keyword ensure that only one thread can access a synchronized block at a time.
  43. this: Used to refer current object that can call the method or constructor of the current object. This Java keyword avoids ambiguity in the program.
  44. throw: Used in exception handling that can throw the exception to the system. Throw java keyword plays an important role in throwing inbuilt or custom exceptions.
  45. throws: Used in the methods to inform the number of exceptions this method can handle. Throws are used at the method header.
  46. transient: Used in POJO class data variables. Transient Java keyword doesn't allow the data variable to get serialized when the POJO class object is serialized.
  47. try: Used in exception handling to throw exceptions to catch. Try is used in a block of code that may throw exceptions in specific conditions.
  48. void: Used in method declaration that indicates the method doesn't return any value. 
  49. volatile: Used in the data variable. Volatile java keyword indicates that the data variable value can be modified by multiple threads
  50. while: Used to create while loop. While loop can be used when the programmer doesn't know the number of iterations in a loop and the loop stops only when the condition doesn't match.

Post a Comment

Previous Post Next Post
B