What are the reserved keywords and literals in Java?

Reserved Keywords and literals in any programming language are those word which can’t be used as variable or function name (Identifiers). For Java programming as of Release 1.8, there are 50 keywords and 3 reserved literals.

Java Reserved Keyword List

List of Java Keywords

  1. abstract – It is used for defining abstract class. An abstract class is a class which can only be extended, we can’t create object from that.
  2. assert – It is used for testing the value of an expression. For E.g. assert isTrueExpression; It will throw AssertionException if isTrueExpression is false.
  3. boolean – It denotes boolean data type. It store either 0 (false) or 1 (true).
  4. break – When we use break statement inside loop and switch case block, It is used to break the flow of loop and switch case block.
  5. byte – It denotes byte data type. 1 byte = 8 bits. Range is -128 to 127
  6. casecase is used in switch case statement. switch case statement is used for conditional logic.
  7. catchcatch block is used with try block to handle exceptions.
  8. charchar is data type to represent unicode character. It need 2 bytes to store it. 2 bytes = 16 bits. It can represent 65536 unicode characters.
  9. classclass keyword use for declaration of class to be used for object creation.
  10. const – This is not used but might be reserved for future purpose.
  11. continue – continue in iteration to skip execution of code after this term found. It doesn’t break the iteration though.
  12. defaultdefault block in switch case statement called, if none of the case equals to value exposed through switch statement.
  13. do do keyword used along with do while iteration loop. do while loop will always execute at least once.
  14. double double is a primitive data type which can hold decimal values. 8 bytes (64 bits) are used for representing one double data.
  15. else – else keyword is used along with if for conditional branching. 
  16. enum – enum keyword is used to define data which can be enumerated.
  17. extends – This keyword is used for the support of inheritance. A Base Class extends Parent Class.
  18. final – When we want variable, once initialised not able to take another value, we use final for that variable.
  19. finallyfinally block will always executed, there is an exception or not.
  20. floatfloat is a data type for holding decimal value for range -4294967296 to 4294967295 (-2^32 to 2^32 – 1)
  21. for – An iteration loop keyword.
  22. goto – Reserved keyword but not used.
  23. if – Used for conditional branching.
  24. implements – Used in inheritance for implementing Interfaces.
  25. import – Used to import packages or classes to be exposed in java file or class.
  26. instanceof – method to be used on any object to check if its instance of specific class.
  27. int – Data type to hold integer data. It takes 4 bytes or 32 bits to store it.
  28. interface – To define 100% abstract class, which will be implemented for concrete class.
  29. long – Data type to hold Integers. It takes 8 bytes or 64 bits to store.
  30. native – When a method is implemented by some native language by JNI (Java Native Interface), that method is denoted with native keyword.
  31. new – We use new keyword to create a new object.
  32. package – We use package to define organising class into namespace.
  33. privateprivate is a access modifier used on method, field and inner class so they can be only accessed from other member of same class.
  34. protected  protected used on method, field and inner class can only be accessed from other member of same class, member of inner class or member of class in same packages.
  35. public – public used on method, field and inner class can be accessed by member of any class.
  36. return – using return keyword we send back the required value to called method and terminate the execution of method.
  37. short – primitive data type which takes 2 bytes (16 bits) to hold values from -32,768 to 32,767.
  38. static – method and member variable marked with static modifier can be accessed on Class name without creating object of that class.
  39. strictfp – When used it restrict floating point calculation to ensure portability.
  40. super – used in inheritance to access overridden super class method and constructor.
  41. switch – used in switch case conditional logic.
  42. synchronised – make sure only one thread is accessing method or code blocks where synchronised has been used.
  43. this –  It can be used to point current class constructor, method , instance variable, passed in method argument, constructor argument and use to return instance of current class.
  44. throw – can be use to explicitly throw checked or unchecked exception.
  45. throws – can be use to create checked exception which need to be handle explicitly.
  46. transient – variable can’t be serialised.
  47. try – block exception will be caught.
  48. void – method return nothing.
  49. volatile – keyword guarantees the write operation to the variable will be in main memory not in the cache, hence letting all threads accessing same value.
  50. while – use for iteration till provided condition not become false.
  51. true, false, and null are literal and they also can’t be used as identifier.

One Reply to “What are the reserved keywords and literals in Java?”

Leave a Reply

Your email address will not be published. Required fields are marked *