Home | | Sitemap ||Page number :5

Data Types And Operators

In our daily life we receive information as stimulus from our surrounding. Then we process and analyze it within our minds. A computer too gets input from several sources which it processes to give an output. So data handling is a core issue of programming.

CONSTANTS

The word “constant” means anything that does not change. Constants that are also known as “literals” have a fixed value in programming. Let us assume a number ‘6’, this digit represents a number. If I order two shopkeepers to give me six DVDs of a movie, both will supply me with the same number. The real world situation even applies here. In this way we can even call alphabets ‘S’‘t’ ‘u’ ‘V’ and Strings such as “Delhi” as constants.

A proper hierarchy will be --- Constants ---

  1. Numeric Constants----- (1). Integer Constants (2). Real Constants
  2. Character Constants---- (1).Characters (2).String

If you are confused by the terms “Real” and “Integer” constants then here is the answer… An integer constant contains no fractional part while Real Constants contains a decimal value.

VARIABLES

A variable as the names suggest is an entity whose values changes from time to time. Imagine that you are solving an algebraic equation where you are calculating values of ‘x’ and ‘y’ (two variables). After solving the question you might get the values 6, 17. Similarly in the next question the values of ‘x’ and ‘y’ may turn out to be 1, 14. This concept is also applicable in programming. When we create a variable, a part of temporary memory is assigned to it. The value is stored till the execution of program and later the memory is freed. Just like constants a variable can also be of several types.

Data Types

Each and Every variable and constant holds a certain data. The data can be classified under any of these types. While declaring variables we have to specify its type.

Remember: Java is said to be strictly typed language. This is because of the fact that you can not easily assign a variable with a value of another data type.

Integer Type

Integer (int) Holds digits without any fractional part. Short (short) Holds digits without any fractional part. The range of value it holds is less if compared with “int”. Long (long) Holds digits without any fractional part. The range of value it holds is more if compared with “int”. Byte (byte) Holds digits without any fractional part. The range of value it holds is least.

Float Type

Float (float) Holds digits with fractional part. Double (double) Holds digits with fractional part. The range of value it holds is higher in comparison with float.

Character Type

Char (char) Holds a single character.

Classification of Data Types

Data Types || ||

============================================================ || || || ||

Primitive (Intrinsic) Non-Primitive (Derived) || || || ====== ====================

|| || || Classes || || ================================= || Arrays || Interface
|| Numeric || Non-Numeric        
|| ============= || ============        
|| Integers || Float || Characters || Boolean        
Reserved Words        

There are certain predefined keywords in Java that help us in programming. Thus we cannot use them as variables name.

Special Printing Characters

Sometimes you want to format your output in a certain way. In such conditions you use these characters. Study this Example which demonstrates the use of one of the special character, it also shows the use of variables and data types.

class demo { public static void main(String args[]) { int no1,no2; //Two variables of data type int char name='N'; // Initialization at the tome of variable declaration

//Post Initialization no1=17; no2=12;

System.out.println ("Character is "+name+"\n"); // Here “\n” is the special printing

//character System.out.println("Numbers are "+no1+" "+no2); } }

x

Popular Printing Characters

Newline \n Use--- Prints a blank line.
Horizontal Tab \t Use---Prints a horizontal space of 5
Vertical Tab \v Use---Prints a vertical space of 5