phone: 016-6933793
e-mail: darknessofsorrow@hotmail.com

Friday 26 October 2012

Basic Computationc( Variables and Expressions )

~VARIABLES~


*Variables is a storage location to hold a temporary values.
*It used to store data such as number and letters.
*They are implemented as memory locations.
*The data stored by a variable is called its value.
*The value is stored in the memory location.
*Its value can be changed.
*All variables must be declared before they can be used.


#The type of variable:




#SIMPLE OF DECLARATION VARIABLE JAVA PROGRAM


~CONSTANTS~
*Similar to variables but once initialized, their contents may 
NOT be changed.
*Declared with the reserved word final
*Syntax:
   final datatype CONSTANTNAME = value
*Example:
   final double CENTIMETERS_PER_INCH =2.54;
 final int NO_OF_STUDENTS = 20;
 final char BLANK = ' ';
   final double PAY_RATE =15.75;
~DATA TYPE~

*A data type specifies a set of values and their operations.
*Has two main kinds of data:1)class type  2)primitive types.
*A class type is used for a class of objects and has both data and methods.
="Java is fun" is a value of class type String
*A primitive type is used for simple,nondecomposable value such as an 
individual number or individual character.
=int, double, and char are primitive types.
# PRIMITIVE TYPES
example for primitive type

*Four type for integers,namely, byte, short, int, long.The only 
differences among the various integer types are the range of integers they
 represent and the amount of computer memory they used.
*A number having a fraction part such as the number 9.99, 3.14159,
-5.67 and 5.0 is called a floating point number.Java have two data 
types for floating point numbers,float and double.
*Char is used for single characters such as letters, digits, or punctuation.
*Boolean has two values, true and false.
EXAMPLE



~JAVA IDENTIFIER~
*An identifier is a name such as the name of a variable.
*Identifiers may contain only
     =Letters
     =Digit (0 through 9)
     =The underscore character ( _ )
     =And the dollar sign symbol ( $ ) which has a special meaning
*The first character cannot be a digit.
*Identifiers may not contain any spaces, dots (.),asterisks (*), or other
 characters.
*Since Java is case sensitive,stuff ,Stuff  and STUFF are
different identifiers.

#LEGAL AND ILLEGAL VARIABLE NAMES

#Assignment Statements
*An assignment statement is used to assign a value to a variable
       answer = 42;
*The "equal sign" is called the assignment operator.
*We say, "The variable named answer is assigned a value of 42," or
 more simply,"answer is assigned 42."

















0 comments: