Start of Tutorial > Start of Trail |
Search
Feedback Form |
The
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.
BasicsDemo
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:
Even a small program such as this 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 teaches what you need to know about the nuts and bolts of the Java programming language to understand this program.Sum = 55
Variables
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
This section details how you perform various operations, such as arithmetic and assignment operations.Expressions, Statements, and Blocks
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
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 asif-else
andwhile
.
Start of Tutorial > Start of Trail |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.