IDENTIFIRES: Identifiers
are the names of variables, methods, classes, packages and interfaces.
Unlike literals they are not the things themselves, just ways of
referring to them. In the HelloWorld program, HelloWorld , String , args
, main and println are identifiers.
It must begin with either a later or an underscore(_) or a dolor sign ($). It can contain digits in the middle. Non of the following characters can be used while naming variables :
#%&"()'*+,:-./?<=>@[\]~!;{|}`.
white spaces (space/ tab) are also note allowed in variable name.
It must not be a keyword. It must not be a reserved word like "true", "false" and "null".
It will be unique within the scope.
VARIABLES: If you create a program used to perform calculations as
introduced above, when a user enters a new value that would be involved in the
calculation, to manage that value, you can (temporarily) store it in the
computer memory. Since the values entered in a reserved memory area change
regularly, they are called variables. Because neither you nor the compiler can
predict all possible values that would be used, there are safeguards you can
use. First, you must ask the compiler to reserve an area of memory for a value
you intend to use. Asking the compiler to reserve an area of memory is referred
to as Declaring a Variable. Remember that when you declare a variable, the
compiler reserves an area of the compiler memory for you.
VARIABLE DECLARATION:
VARIABLE DECLARATION:
After declaring a variable, when you need the value stored
in its memory area, you can ask the compiler to retrieve it and hand it to you.
To effectively handle this transaction, the compiler would need two pieces of
information from you: a name of your choice for the memory area that will be
reserved, and the type of value that will be stored in that area of memory.
Based on this, the formula to declare a variable is:
TypeOfValue VariableName
As done in some languages like Pascal or Basic, we will
start with the name.
VARIABLE INITIALIZATION:
After declaration of variables can be initialized in the following manner :
variable_name = value;
To initialize a variable, on the right side of its name,
type the assignment operator, followed by the value you want to put in the
reserved memory. As we will see in the next few sections, you cannot and should
not put just any type of value in a variable. We will see that there are
different types used for different variables.
Introduction To Data Types:
when declaring a variable, besides
its name, you must provide the type of information that the variable will hold.
The role of this type is to tell the compiler how much memory will be needed to
store the value(s) of that variable. Since your program is not the only one used
in the computer, memory has to be effectively managed Introduction To Data Types:
The type of value that a variable will hold is called a data
type. As you ay imagine, different variables can be meant to hold different
types of values. Each data type uses a Java keyword to be characterized. As a
modern language, Java provides even more support for its traditional data types.
To do this, a class was created for each data type. This allows you to get more
information from a variable declared with the particular data type you want to
use.
The Primitive Data Types Of Java:
Java is strongly typed language, every variable must have a data type. Java has two forms of data types (1) Primitive (2) Reference. A primitive type of variable hold only a single value in memory. if we declare a variable to be of a specific primitive data type, that variable will always hold value of that data type.
Java define 8 primitive data types. These can be put in four groups - Integer, Floating-point numbers, Characters and Boolean. Let us describes the groups one by one.
Integer Data Type: Integer can hold signed whole numbers like 123, -76 and 256. Signed whole numbers means positive(+ve) and negative(-ve) whole numbers. The size of the value which it can store depends on the integer data type we choose. Java support four types of integers, which are shown bellow.
Name Size Range
byte 8 bits 2
The Primitive Data Types Of Java:
Java is strongly typed language, every variable must have a data type. Java has two forms of data types (1) Primitive (2) Reference. A primitive type of variable hold only a single value in memory. if we declare a variable to be of a specific primitive data type, that variable will always hold value of that data type.
Java define 8 primitive data types. These can be put in four groups - Integer, Floating-point numbers, Characters and Boolean. Let us describes the groups one by one.
Integer Data Type: Integer can hold signed whole numbers like 123, -76 and 256. Signed whole numbers means positive(+ve) and negative(-ve) whole numbers. The size of the value which it can store depends on the integer data type we choose. Java support four types of integers, which are shown bellow.
Name Size Range
byte 8 bits 2
0 comments:
Post a Comment