站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Java Tutorial 5.0 英文版

Language Basics - Java Tutorial 5.0 英文版

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


This chapter has been updated to reflect features and conventions of the latest release, JDK 5.0. The for Statement now covers the enhanced for language feature, and enumerated types are reflected in the keywords table and covered as they pertain to The switch Statement. (The main coverage of enumerated types is in Classes and Inheritance.) If you notice any errors or omissions (or something you really like), please tell us.
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);
    }
}

This is the output from the program.

Sum = 55
Even a small program like this one uses many of the most basic features of the Java programming language, including variables, operators, and control flow statements. The code might look a little mysterious now, but this chapter's purpose is to teach you 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-2005 Sun Microsystems, Inc. All rights reserved.