The JavaTM Tutorial

| Start of Tutorial > Start of Trail | Search Feedback Form

Trail: Learning the Java Language

## Lesson: Language Basics

> > Under Construction: We are in the process of updating and rewriting this lesson. Some sections are incomplete and are marked with [PENDING]. Continue to use our feedback form to tell us what you like and don't like about this lesson and the tutorial.

> The `SortDemo` program shown below sorts the numeric values stored in an array, a data structure that can hold multiple values of the same type, and displays the sorted list. The program uses the bubble sort algorithm, a simple but inefficient algorithm, to sort the items. Running the Sort Program shows you how to run the program and the output to expect from it.

> >     public class SortDemo {
> >         public static void main(String[] args) {
> >             int[] arrayOfInts = { 32, 87, 3, 589, 12, 1076,
> >                                   2000, 8, 622, 127 };

> >             for (int i = arrayOfInts.length; --i >= 0; ) {
> >                 for (int j = 0; j < i; j++) {
> >                     if (arrayOfInts[j] > arrayOfInts[j+1]) {
> >                         int temp = arrayOfInts[j];
> >                         arrayOfInts[j] = arrayOfInts[j+1];
> >                         arrayOfInts[j+1] = temp;
> >                     }
> >                 }
> >             }

> >             for (int i = 0; i < arrayOfInts.length; i++) {
> >                 System.out.print(arrayOfInts[i] + " ");
> >             }
> >             System.out.println();
> >         }
> >     }

> > Impurity Alert: This program using `System.out` to display its output. Using `System.out` is not 100% Pure Java because some systems don't have the notion of standard output.

> Even a small program such as this uses many of the traditional language features of the Java programming language. This lesson describes variables, operators, expressions, and control flow statements.

### Variables

> Like other programming languages, Java allows you to declare variables in your programs. You use variables to hold data. All variables in Java have a type, a name, and scope.

### Operators

> The Java programming language provides a set of operators that you use to perform a function on one, two, or three operands.

### Expressions, Statements, and Blocks

> This section discusses how to combine operators and variables into sequences known as expressions. 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.

| Start of Tutorial > Start of Trail | Search Feedback Form