{"id":78995,"date":"2020-06-05T09:00:24","date_gmt":"2020-06-05T03:30:24","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=78995"},"modified":"2020-06-05T09:00:24","modified_gmt":"2020-06-05T03:30:24","slug":"keywords-in-java","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/","title":{"rendered":"Keywords in Java &#8211; Java Reserved Words"},"content":{"rendered":"<p>In any programming language, there are some fundamental concepts that you need to know before you can write even the most elementary programs, such as the case with Java programming language as well.<\/p>\n<p>This article introduces you to one of the Java fundamentals where you will learn the Java keywords. This is one of the basic units which helps to form a class in Java.<\/p>\n<p>Let us start our discussion with what is keywords in Java and then we will discuss some main keywords in Java that we frequently use in our Java programs.<\/p>\n<h3>What is Keyword in Java?<\/h3>\n<p>The smallest individual unit in a Java program is called a Token in Java.Java has 5 tokens and the keyword is one of the tokens in Java.<\/p>\n<p>A keyword is a reserved word that conveys special meaning to the Java compiler.<\/p>\n<p>These are reserved for special purposes and we cannot use them as identifier names otherwise the compiler will give an error.<\/p>\n<p>In Java. there are <strong>51 keywords<\/strong>, but 2 of them are not used which are-goto and const. Only <strong>49 keywords<\/strong> are used in Java. All of them have different purposes and meanings.<\/p>\n<p>Below is the Java Keyword List:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/List-of-Java-Keywords.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79016\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/06\/List-of-Java-Keywords.jpg\" alt=\"List of Java Keywords\" width=\"750\" height=\"442\" \/><\/a><\/p>\n<p>Let\u2019s discuss each of them briefly:<\/p>\n<h4>1. abstract keyword<\/h4>\n<p>The abstract keyword in Java is used when we declare a class as an abstract class. Making a class as an abstract class restricts itself from creating its object.<\/p>\n<p>The abstract class can contain both abstract or non-abstract methods. We can extend this class but can not instantiate it. The keyword is placed before the class name as:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">abstract class ClassName {\n  \/\/code inside the abstract class\n}<\/pre>\n<h4>2. boolean keyword in java<\/h4>\n<p>The boolean keyword in Java is used to declare the variables of a boolean data type. If we declare any variable with a boolean keyword, then it holds boolean values.<\/p>\n<p>There can be only two boolean values which are &#8211; true and false.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">boolean myVar;\nmyVar = false;<\/pre>\n<h4>3. assert keyword in java<\/h4>\n<p>The assert keyword in Java is used to achieve an assertion in Java. Assertion helps in checking the assumptions made in the Java programs.<\/p>\n<p>The assert keyword is used with boolean expressions in two different ways:<\/p>\n<p>The first way of using assert keyword is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">assert booleanExpression;<\/pre>\n<p>The second way of using assert keyword is:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">assert booleanExpression1: booleanExpression2;<\/pre>\n<h4>4. break keyword<\/h4>\n<p>The break keyword in Java is used to break from a looping statement of Java. We can use the break keyword as a statement. We write in a single line with a semicolon.<\/p>\n<p>When we use it with either for, while or do-while loop, the control flow reaches to the end of the respective loop. We also use it in the switch statement.<\/p>\n<p>For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for (int num = 0; num &lt; 10; num++)\nif (num % 2 == 0) break;<\/pre>\n<h4>5. byte keyword<\/h4>\n<p>The byte keyword in Java is used to define a variable with a byte data type. The byte data type can hold 8-bit values.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">byte myVar = 100;<\/pre>\n<h4>6. case keyword<\/h4>\n<p>The case keyword in Java is used in switch statements to write different options. We write each option with the case statement and the condition is checked around each case of the switch statement.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">switch (expression) {\ncase option1:\n  \/\/statement\ncase option2:\n  \/\/statement\ncase option3:\n  \/\/statement\ncase option4:\n  \/\/statement\ncase option5:\n  \/\/statement\n}<\/pre>\n<h4>7. catch keyword<\/h4>\n<p>The catch keyword in Java is used together with the try statements. It is used to catch the exceptions generated by the try block.<\/p>\n<p>The catch block cannot be used alone; it has to be used only after the catch block.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">try {\n  \/\/statements\n}\ncatch {\n  \/\/statements\n}<\/pre>\n<h4>8. class keyword<\/h4>\n<p>The class keyword in Java is used to declare a class in Java. A class is a collection of methods and data members.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class MyClass {\n  \/\/fields\n  \/\/member functions\n}<\/pre>\n<h4>9. char keyword<\/h4>\n<p>The char keyword in Java is used to declare a variable of a char data type. The char data type can be used to hold a value of 16-bit Unicode characters.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">char myChar = \u2018T\u2019;<\/pre>\n<h4>10. continue keyword<\/h4>\n<p>The continue keyword is used with the looping statement to send the current control flow back to the starting of the loop without executing the further statements after the continue statement.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">while (i &lt; 10) {\n  if (i % 3 == 0) continue;\n}<\/pre>\n<h4>11. default keyword<\/h4>\n<p>The default keyword in Java is used with the switch statements when we want to specify the default block of code.<\/p>\n<p>When no condition matches any case statement, then the default case is executed.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">switch (expression) {\ncase option1:\n  \/\/statement\ncase option2:\n  \/\/statement\ncase option3:\n  \/\/statement\ndefault:\n  \/\/statement\n}<\/pre>\n<h4>12. do keyword<\/h4>\n<p>The do keyword in Java is used in control flow statements with the while statement. They are collectively known as- do-while loop.<\/p>\n<p>Using the do statement allows the statement(s) to iterate multiple times until the condition matches.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">do {\n  \/\/statements\n} while ( test - expression )<\/pre>\n<h4>13. double keyword<\/h4>\n<p>The double keyword is used to declare a variable with a double data type. The double data type holds 64-bit floating-point values.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">double myDouble = 344.78;<\/pre>\n<h4>14. else keyword<\/h4>\n<p>The else keyword in Java is used as a decision-making statement and it is used after the if statement. If the condition of the if statement evaluates to false then the else statement is executed.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (condition) {\n  Statements\n  if condition is true\n}\nelse {\n  Statement\n  if condition is false\n}<\/pre>\n<h4>15. enum keyword<\/h4>\n<p>The enum keyword in Java is used to specify the fixed value of constants. With the enum keyword, we can declare the enumerated type.<\/p>\n<p>Enums in Java represents a class that contains a fixed set of constant values that can\u2019t be changed. We cannot declare an enum inside a method but we can declare it inside or outside class.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public enum Colors {\n  RED,\n  YELLOW,\n  BLUE,\n  GREEN\n}<\/pre>\n<h4>16. extends keyword<\/h4>\n<p>The extends keyword is another important keyword in Java that is used to inherit the parent class.<\/p>\n<p>If a class wants to inherit the properties from another class, it can inherit it using the extends keyword.<\/p>\n<p>The Child class is written before the extends keyword and the parent class is written after the extends keyword. We use this keyword to achieve one of the OOPs concept i.e. Inheritance in Java.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class ParentClass {\n  \/\/code inside the parent class\n}\nclass ChildClass extends ParentClass {\n  \/\/code inside the child class\u2019\n}<\/pre>\n<h4>17. for keyword<\/h4>\n<p>The for keyword in Java is used as a looping statement in Java. In for loop, all the looping statements are written in the same line.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for (initialization expression; test - expressions; update - expression) {\n  \/\/statement inside the for loop\n}<\/pre>\n<h4>18. final keyword<\/h4>\n<p>The final keyword in Java is used to restrict the variable, class, or methods in Java. If we declare a variable as final, then we can\u2019t change its value again.<\/p>\n<p>If we use the final keyword with a class, then no other class can inherit the final class. When you declare a method as final then the method can not be overridden in the child class.<\/p>\n<p><strong>How to Declare final variables:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">final int myVar = 10;<\/pre>\n<p><strong>Declaring the final method:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">final myMethod {\n  \/\/code inside final method\n}<\/pre>\n<p><strong>Declaring final class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">final class MyClass {\n  \/\/code inside final class\n}<\/pre>\n<h4>19. finally keyword<\/h4>\n<p>The finally keyword in Java is used in Exception Handling. It is used in a try-catch structure.<\/p>\n<p>The statements inside the finally block always executes no matter if the exception is handled or not. The finally statement always comes after the try-catch block.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">try {\n  \/\/statements\n}\ncatch {\n  \/\/statements\n}\nfinally {\n  \/\/statements\n}<\/pre>\n<h4>20. float keyword<\/h4>\n<p>The float keyword in Java is used to declare a variable of a float data type. The float data type can hold a 32-bit floating number. We need to use the letter F or f to denote a float variable.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">float myFloat = 15.7F;<\/pre>\n<h4>21. if keyword<\/h4>\n<p>The if keyword in Java is used as a decision-making statement.<\/p>\n<p>We put the test condition inside the if statement and if the condition evaluates to true then the statements inside the if block is executed, otherwise they are skipped.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (test - condition) {\n  \/\/statement if the condition is true\n}<\/pre>\n<h4>22. int keyword<\/h4>\n<p>The int keyword in Java is used to declare an integer type variable. The int data type is used to hold a 32-bit integer signed value.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">int myNumber = 345;<\/pre>\n<h4>23. implements keyword<\/h4>\n<p>The implements keyword in Java is used by a class to implement an interface. Implementing an interface allows a class to use the methods defined in an interface.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class MyClass implements MyInterface {\n  \/\/code inside class\n}<\/pre>\n<h4>24. instanceof keyword<\/h4>\n<p>The instanceOf keyword in Java is used to check whether an object belongs to a class , interface, or a subclass. It indicates whether an object is an instance of a particular class or not.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if (objectName instanceof ClassName)<\/pre>\n<h4>25. import keyword<\/h4>\n<p>The import keyword is used to access the classes and interfaces inside the current source code. We can import packages and classes at the starting of the source code.<\/p>\n<p>Example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import package com.techvidvan.javatutorials.MyClass;\n\/\/imports the MyClass. \n\nimport package com.techvidvan.javatutorials. * ;\n\/\/imports all the classes and provides access to them.\n<\/pre>\n<h4>26. interface keyword<\/h4>\n<p>The interface keyword in Java is used when we want to create an interface in Java. An interface in Java can only contain abstract methods.<\/p>\n<p>The abstract methods are the methods that have no method body or implementation.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">interface MyInterface {\n  \/\/abstract methods\n}<\/pre>\n<h4>27. long keyword<\/h4>\n<p>The long keyword in Java is used to declare a variable with a long data type. It holds a 64-bit long integer value. We use the letter l or L to denote a long value.<br \/>\nExample:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">long myValue = 234345L;<\/pre>\n<h4>28. new keyword<\/h4>\n<p>The new keyword in Java is used when we instantiate a class or create objects of a class. Creating objects with a new keyword is the most common way of creating objects.<\/p>\n<p>Syntax of using the new keyword<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">MyClass object = new MyClass();<\/pre>\n<h4>29. native keyword<\/h4>\n<p>The native keyword in Java is used to specify that the method is implemented using the Java Native Interface(JNI).<\/p>\n<p>We can use native as a modifier for only a method. We can\u2019t apply it with any other entity.<\/p>\n<p>Example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class NativeDemo {\n  \/\/statements\n}\npublic native String getLines();\nclass Main {\n  NativeDemo obj = new NativeDemo();\n  obj.getLines();\n}<\/pre>\n<h4>30. null keyword<\/h4>\n<p>The null keyword in Java is used to indicate the null value. The null value represents a reference variable.<\/p>\n<p>If we declare a reference variable as null then it refers to nothing. If we declare a variable as null then the object refers to nothing.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">String myString;\nmyString = null;\n\/\/Now myString is an empty string that holds no value.\n\nMyClass obj = new MyClass();\nobj = null;\n\/\/Now, the object does not hold the reference of MyClass.\n<\/pre>\n<h4>31. package keyword<\/h4>\n<p>The package keyword in Java is used to create a package. A package is a collection of same type classes and interfaces for better readability and proper distribution of multiple classes.<\/p>\n<p>To include a class in a package we write it on the very first line of the Java program.<\/p>\n<p>For Example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.techvidvan.javatutorials.operators;\n\/\/This line creates a class inside the operators subpackage\n\npublic class ArithmeticOperators {\n  \/\/Code inside the class\n}<\/pre>\n<h4>32. public keyword<\/h4>\n<p>The public keyword in Java denotes the access specifier in Java. This keyword can be used with class, constructor, variable, interface or a method.<\/p>\n<p>If we use the public keyword with any entity that it can be accessed from anywhere. It has the widest scope as compared to all the access specifiers of Java.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class MyClass {\n  public int myVar;\n  public void printName();\n}<\/pre>\n<h4>33. private keyword<\/h4>\n<p>The private keyword in Java is another access specifier that can be used with a class, variable or a method.<\/p>\n<p>Any entity declared as private can only be accessed within the class itself in which it has been declared. It can\u2019t be accessed from outside that class.<\/p>\n<p>It has the narrowest scope and is the most restricted access specifier in Java.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">private class MyClass {\n  private int myVar;\n  private void printName();\n}<\/pre>\n<h4>34. protected keyword<\/h4>\n<p>The protected keyword is also an access specifier in Java.<\/p>\n<p>The entities declared with a protected keyword can be accessed within the same package and also from the different packages but only through the subclasses of that class.<\/p>\n<p>It can only be used with a variable or a method; not with a class or an interface.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">protected int myVar;\nprotected void printName();<\/pre>\n<h4>35. return keyword<\/h4>\n<p>The return keyword in Java is used inside the methods to return from the method.<\/p>\n<p>When the return keyword is encountered, the control flow reaches to the code where the method was being called. The return keyword can also return a value from a function or a method.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public int getNumber(int num) {\n  num = 5;\n  return num;\n}<\/pre>\n<h4>36. static keyword<\/h4>\n<p>The static keyword in Java is used with a variable, method or a block. It is used to share the same variable or a method within a class.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public static void display()\nstatic int number = 10;<\/pre>\n<h4>37. short keyword<\/h4>\n<p>The short keyword in Java is used to declare a variable of a short data type. The short data type can hold 16-bit (2 bytes) integer value and can store a range of -32,768 to 32,767 numbers.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">short myNum = 38;<\/pre>\n<h4>38. super keyword<\/h4>\n<p>The super keyword in Java is used to refer to the object of the parent or superclass. It is used to call the immediate parent class methods.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Parent {\n  String color = \u201cRed\u201d;\n}\n\nclass Child extends Parent {\n  void getColor() {\n    System.out.println(super.color);\n  }\n}\n\npublic class Main() {\n  public static void main(String args[]) {\n    Child obj = new Child();\n    obj.getColor();\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nRed<\/p>\n<h3>39. switch keyword<\/h3>\n<p>The switch keyword in Java is used for the switch as a conditional statement.<\/p>\n<p>The switch keyword is very effective against the if statement as with the help of switch the compiler directly jumps to the particular case rather than executing all the conditions which are in the if statement.<\/p>\n<p><strong>Code to understand the switch statement:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public class Main {\n  public static void main(String args[]) {\n    int dayOfNumber = 2;\n\n    switch (dayOfNumber) {\n    case 0:\n      System.out.println(\u201cSunday\u201d);\n      break;\n    case 1:\n      System.out.println(\u201cMonday\u201d);\n      Break;\n    case 2:\n      System.out.println(\u201cTuesday\u201d);\n      Break;\n    case 3:\n      System.out.println(\u201cWednesday\u201d);\n      break;\n    case 4:\n      System.out.println(\u201cThursday\u201d);\n      Break;\n    case 5:\n      System.out.println(\u201cFriday\u201d);\n      break;\n    case 6:\n      System.out.println(\u201cSaturday\u201d);\n      break;\n    default:\n      System.out.println(\u201cNot the vaild number of the Day\u201d);\n    }\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nTuesday<\/p>\n<h4>40. synchronized keyword<\/h4>\n<p>The synchronized keyword in Java is used to achieve synchronization in Java in a multi-threaded environment.<\/p>\n<p>The methods that are critical and need to be accessed by only a single resource at the same time, then these methods are declared as synchronized with the help of a synchronized keyword.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">synchronized void methodName {\n  \/\/code inside the method\n}<\/pre>\n<h4>41. strictfp keyword<\/h4>\n<p>The strictfp keyword in Java Programming Language is used to provide the platform-independent facility i.e. the piece of code will return the same result in different platforms.<\/p>\n<p>There are some priorities that may differ from platform to platform. That is the reason why Java introduces the strictfp keywords to ensure that every platform may run the code in the same precision.<\/p>\n<p>The strictfp keyword is used with classes, interfaces, and methods. The Example is given below:<\/p>\n<p><strong>strictfp use in the Class:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">strictfp class Keywords {\n  \/\/ the methods of the class.\n}<\/pre>\n<p><strong>Use in the interface:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">strictfp interface Keywords {\n  \/\/ methods of the interface\n}<\/pre>\n<p><strong>Use in the methods:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Keywords {\n  strictfp void StrictfpKeyword {\n    \/\/ the logic of the method\n  }\n}<\/pre>\n<h4>42. this keyword<\/h4>\n<p>The this keyword in Java is used to refer to the current object of the class inside the method or a constructor.<\/p>\n<p>The this keyword is used to remove the ambiguity between the instance variables and parameters.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class ClassName {\n  int number;\n\n  \/\/constructor\n  ClassName(int number) {\n    this.number = number;\n  }\n}<\/pre>\n<h4>43. throw keyword<\/h4>\n<p>The throw keyword in Java Programming Language is used to explicitly throw an exception.<\/p>\n<p>For example if the user enters a number greater than 10 then the program will throw an exception. In this case to throw the custom exception the Java introduces the throw keyword.<\/p>\n<p>The throw keyword allows the developer to throw the custom exception.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public classThrowKeyword {\n  public static void ageRestriction(int age) {\n    if (age &lt; 18) throw new ArithmeticException(\"Age restriction to vote\");\n    else System.out.println(\"Allow to Vote\");\n  }\n  public static void main(String args[]) {\n    System.out.println(\"Enter your age: \");\n    ageRestriction(13);\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nEnter your age<br \/>\nException in thread main java.lang.ArithmeticException: Age restriction to vote<\/p>\n<h4>44. throws keyword<\/h4>\n<p>The throws keyword in Java is used in Exceptions. We use the throws keyword for only the checked exceptions in Java.<\/p>\n<p>It indicates the programmer that to be on the safe side you should use it to avoid exceptions.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public void getNames() throws IOException {\n  \/\/code inside the method\n}<\/pre>\n<h4>45. try keyword<\/h4>\n<p>The try keyword in Java is useful for exception handling. Whenever we want a block to be tested for exceptions, then we put in the try block. But the try block must end with the catch or finally block.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">try {\n  \/\/statements\n}\ncatch {\n  \/\/statements\n}<\/pre>\n<h4>46. transient keyword<\/h4>\n<p>The transient keyword in Java Programming Language is useful to accomplish serialization in the Java Environment.<\/p>\n<p>When we declare the data member with a transient keyword then that data member will not be serialized.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">transient int age;<\/pre>\n<h4>47. void keyword<\/h4>\n<p>The void keyword in Java is useful with methods to specify that the method returns nothing. There is no return value of the method.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">public void display() {\n  \/\/code inside method\n}<\/pre>\n<h4>48. volatile keyword<\/h4>\n<p>The volatile keyword in Java is useful with a variable to indicate that the value of a variable may be modified asynchronously by different threads. We also use it with classes to make them thread-safe.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Demo {\n  static volatile int myvar = 5;\n}<\/pre>\n<h4>49. while keyword<\/h4>\n<p>The while keyword in the Java Programming Language is useful to iterate a piece of code as many times as you want.<\/p>\n<p>If there is no information about the terminating condition, then it is better to use a while loop. The while loop also offers the infinite looping structure.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">while (condition) {\n  \/\/ the piece of code\n}<\/pre>\n<h4>Conclusion<\/h4>\n<p>Keywords in Java are special words that we can use only for the situation when they are meant to be used. We can\u2019t use them as identifiers.<\/p>\n<p>In this article, we have discussed different keywords in Java. Basically there are 51 keywords in java but two of them<strong> goto and const<\/strong> are for future purpose.<\/p>\n<p>So only 49 keywords are useful currently in Java. We hope you might have understood the use of each keyword in Java along with their syntax.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In any programming language, there are some fundamental concepts that you need to know before you can write even the most elementary programs, such as the case with Java programming language as well. This&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79015,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2805,2806,2807,2808,2809],"class_list":["post-78995","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-enum","tag-java-enum","tag-java-keyword-list","tag-java-keywords","tag-keywords-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Keywords in Java - Java Reserved Words - TechVidvan<\/title>\n<meta name=\"description\" content=\"Java Keywords - What are keywords in java and list of java keywords with examples - boolean, short, for, case, catch,final,interface,protected, this, byte\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Keywords in Java - Java Reserved Words - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Java Keywords - What are keywords in java and list of java keywords with examples - boolean, short, for, case, catch,final,interface,protected, this, byte\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-05T03:30:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Keywords-in-Java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Keywords in Java - Java Reserved Words - TechVidvan","description":"Java Keywords - What are keywords in java and list of java keywords with examples - boolean, short, for, case, catch,final,interface,protected, this, byte","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/","og_locale":"en_US","og_type":"article","og_title":"Keywords in Java - Java Reserved Words - TechVidvan","og_description":"Java Keywords - What are keywords in java and list of java keywords with examples - boolean, short, for, case, catch,final,interface,protected, this, byte","og_url":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-06-05T03:30:24+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Keywords-in-Java.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Keywords in Java &#8211; Java Reserved Words","datePublished":"2020-06-05T03:30:24+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/"},"wordCount":2488,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Keywords-in-Java.jpg","keywords":["enum","java enum","java keyword list","Java keywords","keywords in Java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/","url":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/","name":"Keywords in Java - Java Reserved Words - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Keywords-in-Java.jpg","datePublished":"2020-06-05T03:30:24+00:00","description":"Java Keywords - What are keywords in java and list of java keywords with examples - boolean, short, for, case, catch,final,interface,protected, this, byte","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Keywords-in-Java.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/Keywords-in-Java.jpg","width":802,"height":420,"caption":"Keywords in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/keywords-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Keywords in Java &#8211; Java Reserved Words"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/78995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=78995"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/78995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79015"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=78995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=78995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=78995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}