Common Java Statements

Part of the Java All-in-One For Dummies Cheat Sheet

Java statements build programs. Every Java class must have a body, which is made up of one or more statements. You can write different kinds of statements, including declaration and expression.

The break statement

break;

The continue statement

continue;

The do statement

do
    {statements...}
while (expression);

The for statement

for (init; test; count)
    {statements...}

The enhanced for statement

for (type variable : array-or-
collection) {statements...}

The if statement

if (expression)
    {statements...}
else
    {statements...}

The throw statement

throw (exception)

The switch statement

switch (expression)
{
    case constant:
        statements;
        break;
    default:
        statements;
        break;  
}

The while statement

while (expression)
    {statements...}

The try statement

try
    {statements...}
catch (exception-class e)
    {statements...}...
finally
    {statements...}
try
    {statements...}
finally
    {statements...}
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus

SERIES
Java All-in-One For Dummies Cheat Sheet

Advertisement

Inside Dummies.com