Skip to main content

What are the reserved keywords and literals in Java?

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

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 objects 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. case - case is used in switch case statement. switch case statement is used for conditional logic.
  7. catch - catch block is used with try block to handle exceptions.
  8. char - char 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. class - class 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. continuecontinue in iteration to skip execution of code after this term is found. It doesn't break the iteration though.
  12. default - default 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 that 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 that 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 a variable, once initialised not able to take another value, we use final for that variable.
  19. finally - finally block will always executed, there is an exception or not.
  20. float - float 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. private - private 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.


Popular posts from this blog

Working with request header in Jersey (JAX-RS) guide

In the  previous post , we talked about, how to get parameters and their values from the request query string. In this guide learn how to get request header values in Jersey (JAX-RS) based application. We had tested or used the following tools and technologies in this project: Jersey (v 2.21) Gradle Build System (v 2.9) Spring Boot (v 1.3) Java (v 1.8) Eclipse IDE This is a part of  Jersey (JAX-RS) Restful Web Services Development Guides series. Please read Jersey + Spring Boot getting started guide . Gradle Build File We are using Gradle for our build and dependency management (Using Maven rather than Gradle is a very trivial task). File: build.gradle buildscript { ext { springBootVersion = '1.3.0.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' a

Ajax Cross Domain Resource Access Using jQuery

Some time back in our project we faced a problem while making an Ajax call using jQuery. Chrome Browser console had given some weird error message like below when we try to access one of our web pages: When we try to access the same web page in the Firefox browser, it doesn't give any error in the console but some parsing error occurred. In our case, we were accessing XML as an Ajax request resource. I was curious to check if the non-XML cross-domain resource was successfully loading or not. But finally, I realized that it is not going through. jersey-spring-boot-quick-starter-guide In our Ajax call, requesting domain was not the same as the requested URL domain. $.ajax({ url: "" , type : "get" , success: function (response) { alert( "Load was performed." ); }, error : function (xhr, status) {

FastAPI first shot

Setup on my Mac (Macbook Pro 15 inch Retina, Mid 2014) Prerequisite Python 3.6+ (I used 3.7.x. I recently reinstalled OS after cleaning up disk, where stock Python 2.7 was available. I installed Pyenv and then used it to install 3.7.x). I already had a git repo initialized at Github for this project. I checked that out. I use this approach to keep all the source code safe or at a specific place 😀. I set the Python version in .python-version file. I also initialize the virtual environment using pyenv in venv folder. I started the virtual environment. FastAPI specific dependencies setup Now I started with basic pip commands to install dependency for the project. I saved dependencies in requirements.txt  the file. Minimal viable code to spin an API Server FastAPI is as cool as NodeJS or Go Lang (?) to demonstrate the ability to spin an API endpoint up and running in no time. I had the same feeling for the Flask too, which was also super cool. app/ from typing i