Java Reference
In-Depth Information
Variables are the most basic elements in all programming languages which hold some val-
ues. You can create variables and then assign some values to them. After that you can do
some computation using those variables.
Let us see one example. There are 5 people and each person has 6 chocolates. You need to
find out how many chocolates are there in total owned by all these 5 people. In this case,
you want the computer to compute and return the result of 5X6. First let us understand how
a human will perform this task. The human sees 5 multiplied by 6. Using a multiplication
table; a human will computer and return the result as 30. Now the question is: how you go-
ing to tell the computer in a language which it can understand and give you the result.
In most programming languages, you will have to define some variables first. Then you will
create the computation statement. Finally you will give instruction as to how to display the
result of the computation.
So let us do it.
Create variable a;
Create variable b.
Assign a = 5;
Assign b = 6.
Compute a multiplied by b,
Display a multiplied by b on user screen.
Depending on the programming language you choose, statements given above may vary. I
have used the computation expression in pseudo code. But essentially all the steps given
above; need to be written in the computer program. Now you need to compile the program.
This will turn your program code into bytes. The computer will perfectly understand these
bytes. When you run it then the computer will promptly display 30 on your screen.
To make variables do various kinds of computation, they are defined in various ways. For
example, if we need to do computation involving mathematical expressions like we did in
the example provided above, we define the variables as Integer or Float or similar types. In
our example variables “a” and “b” are one of these types. If you need to do computation
involving characters or texts then we can have variable types like “Character”, “String” etc.
For example if we need to find how many letters are there in “December” then we can define
Search WWH ::

Custom Search