The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail Search
Feedback Form

Trail: Learning the Java Language

Lesson: Language Basics

The BasicsDemo(in a .java source file) program that follows adds the numbers from 1 to 10 and displays the result.
public class BasicsDemo {
    public static void main(String[] args) {
        int sum = 0;
        for (int current = 1; current <= 10; current++) {
            sum += current;
        }
        System.out.println("Sum = " + sum);
    }
}

The output from this program is:

Sum = 55
Even a small program such as this uses many of the traditional features of the Java programming language, including variables, operators, and control flow statements. The code might look a little mysterious now. But this trail teaches what you need to know about the nuts and bolts of the Java programming language to understand this program.

Variables(in the Learning the Java Language trail)

You use variables in your program to hold data. This section discusses data types, how to initialize variables, and how to refer to variables within blocks of code.

Operators(in the Learning the Java Language trail)

This section details how you perform various operations, such as arithmetic and assignment operations.

Expressions, Statements, and Blocks(in the Learning the Java Language trail)

This section discusses how to combine operators and variables into sequences known as expressions. Expressions are the building blocks of your code. You will also learn how to construct statements and statement blocks.

Control Flow Statements(in the Learning the Java Language trail)

Programs use control flow statements to conditionally execute statements, to loop over statements, or to jump to another area in the program. This section shows you how to control your program's flow with such statements as if-else and while.

Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail Search
Feedback Form

Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.