Start of Tutorial > Start of Trail |
Search
Feedback Form |
TheBasicsDemo
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 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.Sum = 55Variables
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 as if-else and while.
Start of Tutorial > Start of Trail |
Search
Feedback Form |
Copyright 1995-2004 Sun Microsystems, Inc. All rights reserved.