Variables And Constant
If you have already know other computer languages, you must be familiar with variables and constant. If you have a primitive knowledge of mathematics then again you are familiar with these terms. If you don't know about that don't worry we will go the necessary information of the variables and constant.
Why we write software?
You may say to help the business, improve productivity, easiness, etc. Yes you are right but behind all the things we calculate data and want to get desired results.
In the computer programming the data is the important. Suppose you have a very big program which calculate the whole year tax with lot of programming instructions but it gives you wrong results, it is useless. Or, if you have a game in computer but it is calculating wrong distance from the enemies, it must annoying you because of the wrong data calculation.
So, the data is everything we want from the computer. If you will learn the data manipulation efficiently and accurately in the computer programming then you are called expert programmer.
The data is represent in computer programming in Variables and Constant. Lets see what are the variables and constant.
Variables
All the data in computer is reside in memory for the computer programs. I am not going to the memory details. Just consider memory is a location in your cupboard. If you put something in it and want me to bring this, you have to tell me the address in the cupboard. Same thing is variable. You can put your data in memory and keep its address in a readable format. Suppose you have a space in memory named x has value 2 but when you finished your work with 2 get rid of ir and save another value in the same place named x.Constants
Constants are same but it contain only one fixed value during the program execution. It is very useful but for the time we are not going to discussed it. I want you to remember that the location name and value cannot change in constant. You better to understand when we use it.Now we know the basics concept of variables and constant. Now suppose you have different size of cupboard in your room and you want to put your stuff in it, I am sure you use the appropriate size for the things to save the space. Suppose you have 6" X 6" one box and the other one is 18" X 18". Now you want to keep your small cup in your cupboard, suppose your cup is 4" X 3", where you will keep it? Any of the empty space but now you have a very big15" X 10" book, you must keep your cup in small box and book in big box. It is logical, isn't it? Same thing we apply in programming languages. The space is called data types and what you can save in it is called literals.
Data Types
If you want to save small data you must use small data types. We have different data types with different literals. Lets discuss it one at a time.Integer
This data type has whole number values. The number could be minus, zero or plus but cannot contain decimal places. All the whole numbers are literals of the integer. But in Java you get further division to keep your memory efficient. But how much for small space you need small number.byte
It is 8 bit data type and the literal value range is -128 to 1274
short
It is 16 bit data type the literal value range is -32768 to 32767
int
This is the most common used data type for the whole numbers. It takes 32 bits and its literal value range is -231 to 231-1
No comments:
Post a Comment