Java/Control Statements

From Meshplex

Jump to: navigation, search
Image:Java_programming.jpg
Introduction to Java
Overview of Java
How to Setup Java on your PC
Data Types, Variables,and Arrays
Operators
Packages, Classes, and Interfaces
Java Program
Modifiers
Control Statements
* Selection Statements
* Iteration Statements
* Jump Statements
Exception Handling
Object Oriented Programming
Wrappers
Strings
Math
Arrays
Random Numbers
Date and Time
Regular Expressions
Java Collections
Generics
Java Thread and Multithreading
Java IO and file Handling
Java Network Programming
RMI
Image, Audio, Video
GUI
Applets
Internationalization
JDBC
Java and XML
The control statements provided in Java are basically used to cause the proper flow of execution in the advanced and branched Java programs.These control statements can be categorised into the following:

[edit] Java Selection Statements

Selection statements, as self explainatory helps the programmer to choose different paths of execution based upon the outcome of an expression or the state of a variable.
  1. if(isOpen) { //isOpen is a boolean variable
  2.  
  3. System.out.println("The Door is OPEN");
  4.  
  5. } else {
  6.  
  7. System.out.println("The Door is CLOSE);
  8.  
  9. }

[edit] Java Loops/Iteration Statements

Iteration statements as the term states, is the repeatition of the block of code in a program.
  1. int i = 1;
  2. while(i < 5) {
  3.  
  4. System.out.println("The current value of variable i is " + i);
  5. i = i + 1;
  6.  
  7. }

[edit] Java Jump Statements

Jump statements allow your program to execute in a nonlinear fashion.
  1. // break is a jump statement
  2.  
  3. int count = 5;
  4. while(true) {
  5. if(count == 5) {
  6.  
  7. System.out.println("We will use break statement " +
  8. "to jump out of the while block");
  9. break;
  10. }
  11. // code for some process.
  12. }

Previous Next