
Java has keywords which are the words that act like keys for the code. However, please note those cannot be used as variable or class or object names. Those are the special words that need to start with lowercase letters. We have already learnt some of them, such as; class, void, int, … etc. And you can see the rest of them in the following table.
| Keyword | Description |
| abstract | Specifies that a class or method will be implemented later, in a subclass |
| assert | For debugging |
| boolean | A data type that can only store true and false values |
| break | Breaks out of a loop or a switch block |
| byte | A data type that can hold 8-bit data values |
| case | Marks a block of code in switch statement |
| catch | Catches exceptions generated by try statements |
| char | A data type that is used to store a single character |
| class | Defines a class |
| continue | Sends control back outside a loop |
| default | Specifies the default block of code in a switch statement |
| do | Starts a do-while loop |
| double | A data type that can hold 64-bit floating-point numbers |
| else | Indicates alternative branches in an if statement |
| enum | Declares an enumerated (unchangeable) type and extend the base class |
| exports | Exports a package with a module. New in Java 9 |
| extends | Indicates that a class is derived from another class or interface |
| final | Indicates that a variable holds a constant value or that a method will not be overridden |
| finally | Indicates a block of code in a try-catch structure that will always be executed |
| float | A data type that holds a 32-bit floating-point number |
| for | Create a for loop |
| if | Makes a conditional statement |
| implements | Implements an interface |
| import | Used to import a package, class or interface |
| instanceof | Indicates whether an object is an instance of a specific class or implements an interface |
| int | A data type that can hold a 32-bit signed integer |
| interface | Declares an interface |
| long | A data type that holds a 64-bit integer |
| module | Declares a module. New in Java 9 |
| native | Specifies that a method is implemented with native (platform-specific) code |
| new | Creates new objects |
| package | Declares a package |
| private | An access modifier used for attributes, methods and constructors, making them only accessible within the declared class |
| protected | An access modifier used for attributes, methods and constructors, making them accessible in the same package and subclasses |
| public | An access modifier used for classes, attributes, methods and constructors, making them accessible by any other class |
| requires | Specifies required libraries inside a module. New in Java 9 |
| return | Finished the execution of a method, and can be used to return a value from a method |
| short | A data type that can store whole numbers from -32768 to 32767 |
| static | A non-access modifier used for methods and attributes. Static methods/attributes can be accessed without creating an object of a class |
| strictfp | Restrict the precision and rounding of floating point calculations |
| super | Refers to superclass (parent) objects |
| switch | Selects one of many code blocks to be executed |
| synchronized | A non-access modifier, which specifies that methods can only be accessed by one thread at a time |
| this | Refers to the current object in a method or constructor |
| throw | Creates a custom error |
| throws | Indicates what exceptions may be thrown by a method |
| transient | A non-accesss modifier, which specifies that an attribute is not part of an object’s persistent state |
| try | Creates a try…catch statement |
| var | Declares a variable. New in Java 10 |
| void | Specifies that a method should not have a return value |
| volatile | Indicates that an attribute is not cached thread-locally, and is always read from the “main memory” |
| while | Creates a while loop |
Example:
This is an example for finding the smallest and largest numbers from a given set of numbers. In our example we enter three numbers and the program tells us smallest and largest. You will see that we used multiple keywords; int, do, while, if and else.
