|
|
Start of Tutorial > Start of Trail |
Search
Feedback Form |
The
This chapter is being updated to reflect features and conventions of the latest release, JDK 5.0. In particular, The for Statement will cover the for-each language feature, and enumerated types have been reflected in the keywords table and will be covered to some extent in The switch Statement. (The main coverage of enumerated types will be in another lesson, Classes and Inheritance.) We've published this preliminary version so you can get the most current information now, and so you can tell us (please!) about errors, omissions, or improvements we can make to this tutorial.
BasicsDemoprogram 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 traditional 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-elseandwhile.
|
|
Start of Tutorial > Start of Trail |
Search
Feedback Form |
Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.