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.

Comments

Popular posts from this blog

Extend and reuse an existing AirByte destination connector

AirByte is an open-source ELT (Extract, Load, and Transformation) application. It heavily uses containerization for the deployment of its various components. On the local machine, we need docker to run it. AirByte has an impressive list of source and destination connectors available. One of my use case data destinations is the  ClickHouse data warehouse and its destination connector is not yet (2021-12-08) available. As per the documentation, It seems that creating a destination connector is a non-trivial job. It's a great idea to build an open-source ClickHouse destination connector. However, I tried avoiding the temptation to create one because of the required effort. AirByte has a  MySql destination connector available. ClickHouse provides a MySQL connector for access from any MySQL client. We need to configure Clickhouse to give support for the MySQL connector. Accessing ClickHouse from AirByte using its MySQL destination connector looks promising. However, when ...

Understanding Type Checking

A few examples of types in the context of programming language can be integer, float, character, string, array, etc.  When a program executes then data flow between instructions and values of specific types are assigned to a variable after some operation. It's important for the system to verify if the correct types are used as operands in operations. For e.g. In a sum operation, the expectation for operands to be of numeric type. The program's execution should fail in the case there is inconsistency. We can classify programming languages into two categories based as per their ability to cater to type safety: Dynamically Typed Language Statically Typed Language

Setting Clickhouse column data warehouse at Google Cloud Compute Engine VM

I didn't have a Google Cloud account associated with my email, so I signed up for one. It needs a valid Credit Card and mobile number to check if you are human. On successful sign up I get 300$ to spend within 3 months. Creating a free forever Google Cloud Compute Engine VM As per Google Cloud documentation you can have 1 non-preemptible e2-micro VM instance (1GB 2vCPU, 30GB Disk, etc.) per month free forever in some regions with some restrictions. I wanted the following stuff in my VM before I can install Clickhouse on to that: Ubuntu 20.x LTS SSH access from my machine Enabling SSH-based access to Google Compute Engine VM Step 1 Created an ssh private and public key on my mac using the following command ssh-keygen -t rsa -f ~/.ssh/gcloud-ssh-key -C mrityunjay -b 2048 Step 2 Copied the public key from the console using the following command: cat ~/.ssh/gcloud-ssh-key.pub output ssh-rsa <Gibrish :)> mrityunjay Step 3 I went to Google Cloud Console > Co...