Java Keywords

Java has a set of reserved words called keywords, which cannot be used as identifiers (such as variable names, object names, or class names) in a Java program. These keywords serve as fundamental elements of the language’s syntax, and they have predefined meanings and functionalities that cannot be altered.

List of Java Keywords

  1. abstract: Used to declare an abstract class, which can provide the implementation of an interface and have abstract and non-abstract methods.
  2. boolean: Used to declare a variable as a boolean type, which can hold only True and False values.
  3. break: Used to break out of a loop or switch statement and stop the current flow of the program at a specified condition.
  4. byte: Used to declare a variable that can hold 8-bit data values.
  5. case: Used with switch statements to mark blocks of text.
  6. catch: Used to catch exceptions generated by try statements, and must be used after the try block only.
  7. char: Used to declare a variable that can hold unsigned 16-bit Unicode characters.
  8. class: Used to declare a class.
  9. continue: Used to continue a loop and skip the remaining code at the specified condition.
  10. default: Used to specify the default block of code in a switch statement.
  11. do: The Java do keyword is used to declare a loop in control statements. It can repeat a part of the program multiple times until a certain condition is met.
  12. double: The Java double keyword is used to declare a variable that can hold a 64-bit floating-point number. It is used to store large decimal values with high precision.
  13. else: The Java else keyword is used to specify alternative branches in an if statement. It executes a block of code when the condition of the if statement is false.
  14. enum: The Java enum keyword is used to define a fixed set of constants. It is a special data type that can be used to represent a group of related constants.
  15. extends: The Java extends keyword is used to indicate that a class is derived from another class or interface. It is used in inheritance to create a new class that inherits properties and methods from an existing class.
  16. final: The Java final keyword is used to declare a variable as a constant. Once a variable is declared final, its value cannot be changed. It is also used to declare a class as a final class that cannot be inherited by other classes.
  17. finally: The Java finally keyword is used in a try-catch block to specify a block of code that is executed after the try block regardless of whether an exception is thrown or not.
  18. float: The Java float keyword is used to declare a variable that can hold a 32-bit floating-point number. It is used to store decimal values with moderate precision.
  19. for: Java for the keyword is used to start a loop. It is used to execute a set of instructions/functions repeatedly when a certain condition is true. If the number of iterations is known in advance, it is recommended to use a for loop.
  20. if: The Java if a keyword is used to test a condition. It executes a block of code if the condition is true and skips it if the condition is false.
  21. implements: Java implements keyword is used to indicate that a class is implementing an interface.
  22. import: Java import keyword is used to import classes, interfaces, or packages from another package into the current program.
  23. instanceof: Java instanceof keyword is used to check if an object is an instance of a particular class or interface.
  24. int: Java int keyword is used to declare a variable that can hold a 32-bit integer value.
  25. interface: Java interface keyword is used to declare an interface. An interface is a collection of abstract methods that can be implemented by a class.
  26. Long: Java long keyword is used to declare a variable that can hold a 64-bit integer value.
  27. native: Java native keyword is used to indicate that a method is implemented in platform-dependent native code.
  28. new: Java new keyword is used to create a new object or instance of a class.
  29. null: Java null keyword is used to indicate that a reference variable does not refer to any object.
  30. package: Java package keyword is used to group related classes, interfaces, and sub-packages into a single namespace.
  31. private: Java private keyword is an access modifier used to restrict access to methods or variables to the class where they are declared.
  32. protected: Java protected keyword is an access modifier that allows access to methods or variables within the same package and to subclasses of the class where they are declared.
  33. public: Java public keyword is an access modifier used to make methods or variables accessible from anywhere in the program.
  34. return: Java return keyword is used to exit a method and return a value.
  35. short: Java short keyword is used to declare a variable that can hold a 16-bit integer value.
  36. static: Java static keyword is used to indicate that a method or variable belongs to a class, rather than to any particular instance of the class.
  37. strictfp: Java strictfp keyword is used to ensure that floating-point calculations are done consistently across different platforms for portability.
  38. super: Java super keyword is used to refer to the parent class or its members.
  39. switch: Java switch keyword is used with a switch statement to perform different actions based on the value of a variable or expression.
  40. synchronized: Java synchronized keyword is used to ensure that only one thread at a time executes a synchronized method or block of code.
  41. this: In Java, this keyword is used to refer to the current object in a method or constructor. It can be used to access the instance variables and methods of the current object.
  42. throw: The throw keyword in Java is used to explicitly throw an exception. It is often used to throw custom exceptions to indicate errors or unexpected conditions in a program. The throw keyword is followed by an instance of the exception class.
  43. throws: In Java, the throws keyword is used to declare an exception in the method signature. It is used for checked exceptions that can be propagated to the calling method.
  44. transient: The Java transient keyword is used in serialization to indicate that a data member should not be serialized. If a field is marked as transient, it will be excluded from the serialized output.
  45. try: The Java try keyword is used to start a block of code that will be tested for exceptions. The code inside the try block may throw exceptions, which can be caught and handled in the catch block. The try block must be followed by either catch or a final block.
  46. void: Java void keyword is used to specify that a method does not return a value. A method is declared void as the return type cannot return any value.
  47. volatile: Java volatile keyword is used to indicate that a variable may be modified asynchronously by multiple threads. It is used to ensure that the value of a variable is always read from the main memory and not from a thread’s local cache.
  48. while: Java while keyword is used to start a while loop. The while loop iterates a block of code as long as the condition specified in the while statement is true. If the number of iterations is not fixed, it is recommended to use a while loop.

Please refer to tutorials.freshersnow.com to explore additional learnings on Java Keywords.