What is a keyword? List some Java keywords.
Short Answer
Views 1236
Answer:
Keywords have specific meaning to the compiler and cannot be used for other purposes in the program such as variables or method names.
Examples of keywords are class, static, and void.
Here is a list of some Java keywords:
Keyword | Description |
---|---|
abstract |
Used to declare an abstract class or method. |
assert |
Used for debugging purposes to make assertions about the program's behavior. |
boolean |
A primitive data type used to represent a Boolean value (true or false ). |
break |
Used to exit a loop or a switch statement. |
byte |
A primitive data type used to represent an 8-bit signed integer. |
case |
Used in a switch statement to specify a value to be compared with the expression. |
catch |
Used to catch exceptions thrown by a try block. |
char |
A primitive data type used to represent a single character. |
class |
Used to define a class. |
const |
Used to define a constant value. |
continue |
Used to skip the rest of the current iteration in a loop. |
default |
Used in a switch statement as a catch-all case. |
do |
Used to start a do-while loop. |
double |
A primitive data type used to represent a 64-bit floating-point number. |
else |
Used to define the alternative branch in an if statement. |
enum |
Used to define an enumerated type. |
extends |
Used in a class definition to indicate that the class is a subclass of another class. |
final |
Used to indicate that a variable, method, or class cannot be overridden. |
finally |
Used in a try-catch-finally block to specify a block of code to be executed after the try and catch blocks, regardless of whether an exception is thrown or not. |
float |
A primitive data type used to represent a 32-bit floating-point number. |
for |
Used to start a for loop. |
if |
Used to specify a condition in a branching statement. |
implements |
Used in a class definition to indicate that the class implements an interface. |
import |
Used to import classes or packages from another source file. |
instanceof |
Used to test if an object is an instance of a specified class. |
int |
A primitive data type used to represent a 32-bit signed integer. |
interface |
Used to define an interface. |
long |
A primitive data type used to represent a 64-bit signed integer. |
native |
Used to declare a native method. |
new |
Used to create a new instance of a class. |
package |
Used to define the package that a class belongs to. |
private |
Used to indicate that a member is accessible only within the same class. |
protected |
Used to indicate that a member is accessible within the same class and its subclasses. |
public |
Used to indicate that a member is accessible from any class. |
return |
Used to return a value from a method. |
short |
A primitive data type used to represent a 16-bit signed integer. |
static |
Used to indicate that a member belongs to the class rather than to an instance of the class. |
strictfp | Specifies that a floating-point operation must be performed strictly in accordance with the IEEE 754 standard |
super | Used to access the superclass's implementation of a method |
switch | Used to perform a multi-way branch based on the value of an expression |
synchronized | Used to ensure that only one thread can execute a method at a time |
this | Refers to the current object instance |
throw | Throws an exception |
throws | Declares that a method may throw an exception |
transient | Used to indicate that a field should not be serialized |
try | Marks the beginning of a block of code to be tested for exceptions |
finally | Provides a block of code that will be executed after a try/catch block, regardless of whether an exception was thrown or not |
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.