Complete Tutorial on Java Keywords or Reserved Words .

Java Keywords - Keywords in Java , List of all Java Keywords

Java Keywords and Definitions

Keywords in Java

Java Keywords

Java keywords are also known as reserved words . Keywords are particular words which acts as a key to a code . In the Java programming language , a keyword is any one of 57 reserved words . Java keywords have a predefined meaning in the language because of this , programmers cannot use keywords as names for variables , methods , classes , or as any other identifier . Out of 57 keywords , 55 are in use and 2 are not in use . This definition is also same for the following questions .

  • what are keywords in Java ?
  • What are Java programming language keywords ?
  • What are java keywords and their definitions ?
  • Different keywords in Java
  • Java Keywords and their uses

What is Keyword in Java ?

The keyword is any one of 57 reserved words in Java .

What is Reserved Word in Java ?

Reserved Word have a predefined meaning in the Java programming language .

How many keywords in Java ?

There are 57 keywords in Java programming language . Programmers cannot use keywords as names for variables , methods , classes , or as any other identifier .

Following are the List of all Java Keywords or reserved words and their Definitions . In the list all the Java keywords are covered .

List of all Java Keywords and their Definitions

What are the List of all Java Keywords ?

Java Keywords or Java Reserved words are the words in a language that are used for some internal process or represent some predefined actions . These words are therefore not allowed to use as a variable names or objects . Doing this will result into a compile time error .

assert

An assertion is a statement in the Java programming language that enables you to test your assumptions about your program . Assert describes a predicate (a true–false statement) placed in a Java program to indicate that the developer thinks that the predicate is always true at that place . If an assertion evaluates to false at run-time , an assertion failure results , which typically causes execution to abort . Optionally enable by ClassLoader method .

abstract

Java abstract keyword is used to declare abstract class . Abstract class can provide the implementation of interface . It can have abstract and non-abstract methods . Java abstract keyword used in a class definition to specify that a class is not to be instantiated , but rather inherited by other classes . An abstract class can have abstract methods that are not implemented in the abstract class , but in subclasses .

abstract class

Java abstract class that contains one or more abstract methods , and therefore can never be instantiated . Abstract classes are defined so that other classes can extend them and make them concrete by implementing the abstract methods .

abstract method

Java abstract method that has no implementation .

assert

An assertion is a statement in the Java programming language that enables you to test your assumptions about your program . Assert describes a predicate (a true–false statement) placed in a Java program to indicate that the developer thinks that the predicate is always true at that place . If an assertion evaluates to false at run-time , an assertion failure results , which typically causes execution to abort . Optionally enable by ClassLoader method .

boolean

Java boolean keyword is used to declare a variable as a boolean type . It can hold True and False values only . Refers to an expression or variable that can have only a true or false value . The Java programming language provides the boolean type and the literal values true and false . The default value of boolean is false . This keyword is also used to declare that a method returns a value of the primitive type boolean .

break

Java break keyword is used to break loop or switch statement . It breaks the current flow of the program at specified condition . Java break keyword used to resume program execution at the statement immediately following the current statement . If followed by a label , the program resumes execution at the labeled statement .

byte

Java byte keyword is used to declare a variable that can hold an 8-bit data values . The byte keyword is used to declare a field that can hold an 8-bit signed two's complement integer . This keyword is also used to declare that a method returns a value of the primitive type byte .

case

Java case keyword is used to with the switch statements to mark blocks of text . The Java case keyword that defines a group of statements to begin executing if a value specified matches the value defined by a preceding switch keyword . A statement in the switch block can be labeled with one or more case or default labels . The switch statement evaluates its expression , then executes all statements that follow the matching case label; see switch .

catch

Java catch keyword is used to catch the exceptions generated by try statements . It must be used after the try block only . The Java catch keyword is used to declare a block of statements to be executed in the event that a Java exception , or run time error , occurs in a preceding try block .

char

Java char keyword is used to declare a variable that can hold unsigned 16-bit Unicode characters . Defines a character variable capable of holding any character of the java source file's character set . The default value of a char data type is '\u0000' .

class

Java class keyword is used to declare a class . In the Java programming language , a type that defines the implementation of a particular kind of object . A class definition defines instance and class variables and methods , as well as specifying the interfaces the class implements and the immediate superclass of the class . If the superclass is not explicitly specified , the superclass will implicitly be Object . The class keyword can also be used in the form Class .class to get a Class object without needing an instance of that class . For example , String.class can be used instead of doing new String().getClass() .

class method

A method that is invoked without reference to a particular object . Class methods affect the class as a whole , not a particular instance of the class . Also called a static method .

class variable

A data item associated with a particular class as a whole--not with particular instances of the class . Class variables are defined in class definitions . Also called a static field .

Classpath

An environmental variable which tells the Java Virtual Machine and Java technology-based applications where to find the class libraries , including user-defined class libraries .

const

A reserved Java keyword not used by current versions of the Java programming language .

continue

Java continue keyword is used to continue the loop . It continues the current flow of the program and skips the remaining code at the specified condition . A Java keyword used to resume program execution at the end of the current loop . If followed by a label , continue resumes execution where the label occurs .

default

Java default keyword is used to specify the default block of code in a switch statement . A Java keyword optionally used after all case conditions in a switch statement . If all case conditions are not matched by the value of the switch variable , the default keyword will be executed .

do

Java do keyword is used in control statement to declare a loop . It can iterate a part of the program several times . A Java keyword used to declare a loop that will iterate a block of statements . The loop's exit condition can be specified with the while keyword .

double

Java double keyword is used to declare a variable that can hold a 64-bit floating-point numbers . A Java keyword used to define a variable of type double .

double precision

In the Java programming language specification , describes a floating point number that holds 64 bits of data .

else

Java else keyword is used to indicate the alternative branches in an if statement . A Java keyword used to execute a block of statements in the case that the test condition with the if keyword evaluates to false .

enum

Java enum keyword is used to define a fixed set of constants . enum constructors are always private or default . A Java keyword used to declare an enumerated type .

exports

Used in modular java to export a package with a module . This keyword is only available in Java 9 and later .

extends

Java extends keyword is used to indicate that a class is derived from another class or interface . extends is a Java keyword used to inherit the properties and methods of another class . class X extends class Y to add functionality , either by adding fields or methods to class Y , or by overriding methods of class Y . An interface extends another interface by adding methods . Class X is said to be a subclass of class Y .

final

Java final keyword is used to indicate that a variable holds a constant value . If you declare class , method or field those are not modifiable at any point after declaration . A final class cannot be subclassed , a final method cannot be overridden and a final variable cannot change from its initialized value .

finally

Java finally keyword indicates a block of code in a try-catch structure . This block is always executed whether exception is handled or not . A Java keyword that executes a block of statements regardless of whether a Java Exception , or run time error , occurred in a block defined previously by the try keyword .

float

Java float keyword is used to declare a variable that can hold a 32-bit floating-point number . A Java keyword used to define a floating point number variable .

for

Java for keyword is used to start a for loop . It is used to execute a set of instructions or functions repeatedly when some conditions become true . If the number of iteration is fixed , it is recommended to use for loop . A Java keyword used to declare a loop that reiterates statements . The programmer can specify the statements to be executed , exit conditions , and initialization variables for the loop .

goto

It is not used by current versions of the Java programming language .

if

Java if keyword tests the condition . It executes the if block if condition is true . A Java keyword used to conduct a conditional test and execute a block of statements if the test evaluates to true .

implements

Java implements keyword is used to implement an interface . A Java keyword included in the class declaration to specify any interfaces that are implemented by the current class .

import

Java import keyword makes classes and interfaces available and accessible to the current source code . A Java keyword used at the beginning of a source file that can specify classes or entire packages to be referred to later without including their package names in the reference .

instanceof

Java instanceof keyword is used to test whether the object is an instance of the specified class or implements an interface . A two-argument Java keyword that tests whether the runtime type of its first argument is assignment compatible with its second argument .

int

Java int keyword is used to declare a variable that can hold a 32-bit signed integer . A Java keyword used to define a variable of type integer .

interface

Java interface keyword is used to declare an interface . It can have only abstract methods . A Java keyword used to define a collection of method definitions and constant values . It can later be implemented by classes that define this interface with the " implements " keyword .

long

Java long keyword is used to declare a variable that can hold a 64-bit integer . A Java keyword used to define a variable of type long .

module

The module keyword is used to declare a module inside of a Java application . This keyword is only available in Java 9 and later .

native

Java native keyword is used to specify that a method is implemented in native code using JNI ( Java Native Interface ). A Java keyword that is used in method declarations to specify that the method is not implemented in the same Java source file , but rather in another language .

new

Java new keyword is used to create new objects . A Java keyword used to create an instance of a class .

package

Java package keyword is used to declare a Java package that includes the classes . A group of types . Packages are declared with the package keyword .

private

Java private keyword is an access modifier . It is used to indicate that a method or variable may be accessed only in the class in which it is declared . A Java keyword used in a method or variable declaration . It signifies that the method or variable can only be accessed by other elements of its class .

protected

Java protected keyword is an access modifier . It can be accessible within package and outside the package but through inheritance only . It can't be applied on the class . A Java keyword used in a method or variable declaration . It signifies that the method or variable can only be accessed by elements residing in its class , subclasses , or classes in the same package .

public

Java public keyword is an access modifier . It is used to indicate that an item is accessible anywhere . It has the widest scope among all other modifiers . A Java keyword used in a class , method or variable declaration . It signifies that the method or variable can be accessed by elements residing in other classes .

requires

Used to specify the required libraries inside of a module . This keyword is only available in Java 9 and later .

return

Java return keyword is used to return from a method when its execution is complete . A Java keyword used to finish the execution of a method . It can be followed by a value required by the method definition .

short

Java short keyword is used to declare a variable that can hold a 16-bit integer . A Java keyword used to define a variable of type short .

static

Java static keyword is used to indicate that a variable or method is a class method . The static keyword in Java is used for memory management mainly . A Java keyword used to define a variable as a class variable . Classes maintain one copy of class variables regardless of how many instances exist of that class . static can also be used to define a method as a class method . Class methods are invoked by the class instead of a specific instance , and can only operate on class variables .

strictfp

strictfp is a Java keyword used to restrict floating-point calculations to ensure portability . The modifier was introduced into the Java programming language with the Java virtual machine version 1.2 . Basically , what it all boils down to is whether or not you care that the results of floating-point expressions in your code are fast or predictable . For example , if you need the answers that your code comes up with which uses floating-point values to be consistent across multiple platforms then use strictfp .

What Does "strictfp" Do? , When this modifier is specified , the JVM sticks to the Java specifications and returns the consistent value independent of the platform . That is , if you want the answers from your code (which uses floating point values) to be consistent in all platforms , then you need to specify the strictfp modifier . Java's default class Math uses this strictfp modifier as shown below

public final strictfp class Math{ }

super

Java super keyword is a reference variable that is used to refer parent class object . It can be used to invoke immediate parent class method . A Java keyword used to access members of a class inherited by the class in which it appears .

switch

Java switch keyword contains a switch statement that executes code based on test value . The switch statement tests the equality of a variable against multiple values . A Java keyword used to evaluate a variable that can later be matched with a value specified by the case keyword in order to execute a group of statements .

synchronized

Java synchronized keyword is used to specify the critical sections or methods in multithreaded code . If synchronized keyword applied to a method or code block , guarantees that at most one thread at a time executes that code .

this

Java this keyword can be used to refer the current object in a method or constructor . It is used to represent an instance of the class in which it appears . this can be used to access class variables and methods .

throw

The Java throw keyword is used to explicitly throw an exception . The throw keyword is mainly used to throw custom exception . It is used to throw an exception or any class that implements the " throwable " interface .

throws

The Java throws keyword is used to declare an exception . Checked exception can be propagated with throws . It is used in method declarations that specify which exceptions are not handled within the method but rather passed to the next higher level of the program .

transient

Java transient keyword is used in serialization . If you define any data member as transient , it will not be serialized . It indicates that a field is not part of the serialized form of an object . When an object is serialized , the values of its transient fields are not included in the serial representation , while the values of its non-transient fields are included .

try

Java try keyword is used to start a block of code that will be tested for exceptions . The try block must be followed by either catch or finally block . A Java keyword that defines a block of statements that may throw a Java language exception . If an exception is thrown , an optional catch block can handle specific exceptions thrown within the try block . Also , an optional finally block will be executed regardless of whether an exception is thrown or not .

void

Java void keyword is used to specify that a method does not have a return value . It is used in method declarations to specify that the method does not return any value . void can also be used as a nonfunctional statement .

volatile

Java volatile keyword is used in variable declarations that specifies that the variable is modified asynchronously by concurrently running threads .

while

Java while keyword is used to start a while loop . This loop iterates a part of the program several times . If the number of iteration is not fixed , it is recommended to use while loop . A Java keyword used to declare a loop that iterates a block of statements . The loop's exit condition is specified as part of the while statement .

true

A boolean literal value .

false

A boolean literal value .

null

Java null keyword is used to indicate that a reference does not refer to anything . It removes the garbage value . A reference literal value .

var

A special identifier that cannot be used as a type name ( since Java 10 ) .