Home » Data Structures using Java »
Expressions, Statements, and Blocks in Java
Now it's time to learn about expressions, statements, and blocks in Java. Operators may be used in building expressions, which compute values; expressions are the core components of statements; statements may be grouped into blocks.
Expressions
An expression is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value.
Examples of expressions, illustrated in bold below:
int cadence = 0;
anArray[0] = 100;
System.out.println("Element 1 at index 0: " + anArray[0]);
int result = 1 + 2; // result is now 3
if(value1 == value2) System.out.println("value1 == value2");
aValue = 8933.234; // assignment statement
aValue++; // increment statement
System.out.println("Hello World!"); // method invocation statement
Bicycle myBike = new Bicycle(); // object creation statement
Blocks
A block is a group of zero or more statements between balanced braces and can be used anywhere a single statement is allowed.
The following example, BlockDemo, illustrates the use of blocks:
class BlockDemo {
public static void main(String[] args) {
boolean condition = true;
if (condition) { // begin block 1
System.out.println("Condition is true.");
} // end block one
else { // begin block 2
System.out.println("Condition is false.");
} // end block 2
}
}
Posted in
Data Structures using Java
Related posts:
If you enjoyed this article, subscribe to receive more great content just like it.
Recent Stories
Recent Comments
Tag Cloud
Disclaimer
JUST LIKE IN ANY OTHER BLOGGER IN THE BLOG SPHERE, THIS BLOGGER DOES NOT CLAIM OWNERSHIP IN ANY INFORMATION HEREIN POSTED. INFOTECHGUIDE.BLOGSPOT.COM IS DESIGNED TO PROVIDE BASIC INFORMATION ABOUT INFORMATION TECHNOLOGY THAT INTEREST USUAL ONLINE READERS. IF YOU HAVE ANY CONCERN AND SUGGESTION ABOUT THIS SITE PLEASE FEEL FREE TO CONTACT US OR LEAVE A COMMENT FOR THE APPROPRIATE ADJUSTMENT
Labels
- Computer Tips and Tricks (8)
- Content Management System (1)
- Data Structures using Java (15)
- Database Management Systems (2)
- File Formats (7)
- Gadgets Reviews (2)
- Games Reviews (2)
- hardware (16)
- Internet Terms (7)
- Management Information System (5)
- networking (8)
- Programming (15)
- sofware (17)
- Tech News (4)
- Web Design (4)
0 comments for this post
Leave a reply