Keywords in Java
Below is the list of keywords in Java:
abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, final, finally, float, for, goto, if, implements, import, instanceof, int, interface, long, native, new, null, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while
Example:
/*package whatever //do not write package name here */
import java.io.*;
class GFG {
public static void main(String[] args)
{
// int, char, double, float
int age = 25;
char initial = 'J';
double pi = 3.14159;
float discount = 0.1f;
// break keyword
for (int i = 0; i < 5; i++) {
if (i == 2) {
break;
}
System.out.println(i);
}
// final keyword
final String name = "Alice";
// null keyword
String emptyString = null;
System.out.println("Age: " + age);
System.out.println("Initial: " + initial);
System.out.println("Pi: " + pi);
System.out.println("Discount: " + discount);
System.out.println("Name: " + name);
System.out.println("Empty String: " + emptyString);
}
}
Output
0 1 Age: 25 Initial: J Pi: 3.14159 Discount: 0.1 Name: Alice Empty String: null
What is Keyword in Programming?
Keywords are predefined or reserved words that have special meaning to the compiler. In this article, we will discuss about keywords in programming, its importance, and usage in different languages.
Contact Us