An Introduction to the Basics of Java



Learning a new programming language always starts with the definition of terms used in the language syntax. Learning java basics takes the same approach. In all programming languages, there are what are called variables. Variables are containers that are used to store values. These values can then be used to do a bunch of things. Variables can be used to represent an objects state, perform calculations or other things. This is made possible due to the fact that the values in the variables can be altered and in turn this alters an objects state. Variables in java must first be declared before they can be used. To declare a variable one has to provide the data type e.g. if it is a number of a string of words and also the declaration must contain an identifier which is used to associate a name with that variable. A basic declaration would look something like this:

Int gradient;

Here, the Int identifiers the variable as an integer and gradient as the name of the variable.

Another of the java basics are expressions. Expressions are statements that result in a value when they are executed. Expressions usually are composed of several much smaller expressions that are connected by operators, as the example below shows:

Int x 200, y;
Y (x + 100) / 10;

It is also important to become familiar with the java basics of inheritance and polymorphism. In inheritance, new classes are created from existing ones and these new classes absorb or inherit the behaviors and attributes of the existing classes in addition to new defined capabilities. Control-flow statements are also commonly used in Java to direct program execution. Similar to C++ flow statements, if statements are of two types and both use Boolean expressions in their syntax. Some of the most fundamental java basics that you will need to learn are if statements. In these statements, if an expression evaluates to true, it is executed otherwise the code is skipped.

Some of the control-flow statements that you will likely use often in your code are loops. There are three kinds of loops; the while loops, the do-while loops and the for loops. In the while and do-while loops, the Boolean expression is evaluated each time through the body until it evaluates to false. The do-while loop executes once regardless of whether it evaluates to a true or a false. The for loop on the other hand repeats program execution through a number of expressions until the condition is no longer met. Usually it follows the pattern:

For ( expression; Boolean Expression; expression{
. . .
}

with the first expression initializing the loop, the Boolean Expression being the condition that must be met for the loop body to be executed and with the third expression specifying how the loop variable changes each time. The above java basics are just a step into the amazing world of Java and as you get deeper into Java, you will discover the capabilities of this versatile language.

An Introduction to the Basics of Java Rating: 4.5 Diposkan Oleh: Unknown