Statements, Expressions, and Keywords
To create meaningful and effective program source code in the Java programming language, it is essential for any Java programmer or developer to know and understand the concepts of statements, expressions, and reserved Java keywords used in programs. All these elements help in grouping, structuring, and executing your Java program.

So, let’s better understand statements, expressions, and keywords in Java programming.
Statements in Java Programming.
A user-defined statement in a Java program is a complete execution collection that performs a specific action in the user-defined program. Statements form the building blocks of Java program code. In a Java program, each custom-defined statement is executed one by one in sequence, unless the control flow of the defined program changes it through loop statements or conditional execution.
Types of Statements in the Java Language.
Declaration Java Statement – These are used to declare variables or parameters in a Java program as per the programmer’s requirement.
int p = 3; // Here p is declared as an integer variable, and this assigns it the value 3.
Assignment Java Statement – These are used to assign a value to a declared variable in a Java program.
q = 7; // This assigns the numeric value 7 to the variable ‘q’ in a Java program.
Expression Java Statement – These are the variables in a Java program that create a value for a variable or program. They are used to assign or calculate the variable value.
p + 9; // Here the program expression statement calculates the value of ‘p + 9’ but does not store it in the system.
Control Flow Java Statements – These help you control and modify the control flow of execution in a Java program.
Java conditional statements (if, switch).
if (p > 1) {
System.out.println(“p is greater than 1 value”);
}
For, while, and do-while looping statements (for, while, do-while).
for (int q = 0; q < 10; q++) {
System.out.println(q);
}
Method Calls – Calling a method in a Java program is a statement that executes a sequence of statements inside a Java program method one by one
System.out.println(“Welcome to Java programming!”); // Calls the method to print to the console screen
Return Java statements – Used in Java programs to exit a method and return a program value.
return 9; // This returns the value 9 from the method in the program.
Complete program example of a multiple statement in Java.
public class Main
{
public static void main(String[] args) {
int p = 1; // declare a p as an int statement
p = 2; // use assignment variable statement
if (p > 2) { // use program control flow statement
System.out.println(“p is greater than 2”);
} else {
System.out.println(“p is less than or equal to 2”);
}
for (int q = 0; q < 9; q++) { // use for loop statement
System.out.println(q);
}
System.out.println(“Have a nice day!”); // Use program method call
}
}
Expressions in Java Programs.
In Java programming, an expression is a group combination of variables, operators, and class method calls that evaluate to a single value given in the program. Expressions in Java programming are used to perform program operations and return variable parameter values. Unlike Java statements, expressions always provide a result.
Types of Java Program Expressions.
Arithmetic expressions – These are used to perform arithmetic Java mathematical operations such as add, subtract, multiply, divide, etc.
int total = 1 + 2; // Here the total arithmetic expression is 3
int multiply = 2 * 3; // Here the multiplication arithmetic expression is 6
Relational expression – It is used to compare variable values and display the Boolean program expression result.
boolean isGreater = 2 > 1; // Here the relational expression displays true.
Logical expression – It is used to perform logical condition operations in the program.
boolean output = (p > 2) && (p < 9); // Here the user-defined logical AND expression can be true or false.
String expression – It involves adding and displaying a string in a Java program.
String message = “Welcome to, ” + “java!”; // Here the string expression outputs “Welcome to, java!”
Method call expression – A method call in a Java program can be an expression if it returns a value to the program.
int length = “Welcome”.length(); // Here the method call expression means 7.
Conditional (ternary) expression – This is a shorthand method for the if-else statement in Java programs.
String output = (p > 7) ? “greater value” : “smaller value”; // This controls the flow of ternary expression output.
Example of an Expression in a Java program.
public class Main
{
public static void main(String[] args) {
int p = 4;
int q = 7;
int addition = p + q; // Confirm an arithmetic expression value
boolean isEqual = (p == q); // Use relational expression in Java
System.out.println(“The addition is – ” + addition);
System.out.println(“Is value equal? ” + isEqual);
}
}
Reserved Keywords in Java.
Keywords in Java programming are reserved words or text that have a pre-defined meaning or use in the Java programming syntax. Java programmers cannot use these reserved keywords as identifiers, such as variable parameter names, class method names, or class names. They define or preview the structure of a Java program and help programmers control and manage the program’s flow.
Common Java Keywords.
Java control flow keywords.
if, else, switch, case, break, continue, return
These keywords are used in Java programs to control and manage the flow of user-defined program execution based on program conditions and loops.
if (p > 1) {
System.out.println(“p is greater than 1”);
}
Java data type keywords.
int, float, char, boolean, double, byte, short, long, etc. are Java data type keywords.
Data type keywords define the data type nature of variables in a Java program.
int p = 7;
float q = 99.78;
Class and object Java keywords.
class, interface, extends, implements, this, super
These keywords define classes, interfaces, inheritance, and references to the current or parent class in a Java program.
class Course { … }
class Java extends Course { … }
Java access modifiers.
public, private, protected
Java access modifier keywords control the visibility of classes, methods, and variables in the current program.
public class TestClass { … }
private int unique; // This variable can only be called and accessed within the same class in the program.
Method and variable declaration keywords.
static, final, void
These keywords help define the behavior of methods and variables in a Java program.
static int count; // declare as a static data type variable
final int MAX = 70; // declare as final constant
void display() { … } // declare as a method without a return value
Exception handling keywords.
try, catch, throw, throws, finally
These keywords are used to handle and control exceptions and errors in Java programs.
try {
int output = 20 / 0; // This will display an exception in the program
} catch (ArithmeticException e) {
System.out.println(“Display Error – Divide by zero value”);
}
Other types of Java keywords.
package, import, new, null, instanceof, enum, assert
Other types of keywords can have multiple uses, such as creating new class objects, defining class packages, or working with enums data types.
TestClass obj = new TestClass(); // Using ‘new’ keyword to create a new class object
Example of using multiple keywords in a Java program.
public class Main
{
public static void main(String[] args) {
final int MAX_VALUE = 70; // here ‘final’ keyword – use as constant
int value = 20; // here value Variable declaration using as ‘int’ data type
if (value < MAX_VALUE) { // here we use ‘if’ control flow keyword in program
System.out.println(“Here value is less than MAX_VALUE”);
}
try { //let ceate a ‘try’ block for any type program exception handling
int result = 20 / 0; // use to display Arithmetic program exception
} catch (ArithmeticException e) {
System.out.println(“Display Error – Divide by zero value”);
}
}
}
Conclusion of Statements, Expressions, and Keywords in Java Programming.
- Statements in Java programming are actions or controls that perform actions in a program created by a Java programmer, and include program declarations, assignments, method calls, and control flow operations.
- Expressions in Java programs are grouped combinations of variables, operators, and method calls that evaluate to a value defined in the Java program. They are used in statements in a Java program to display results.
- Keywords in Java programming are reserved or pre-defined words of text that are part or structure of each Java programming language syntax. They indicate how a user-created Java program is structured, and how these keywords control and manage the program’s behavior.
