Wednesday 21 November 2012

DATA TYPES IN JAVA

DATA TYPES IN JAVA:
The primary objective of  Data types in coffee is to find out which type of value we can saved into the varying.
Variable can be used to shop some type of value.
EX:  int x;
Here we are announcing that x is a varying,which can shop int(integer) type data.This suggests int is comprising the characteristics of information to be saved into x.int is also known as a knowledge type.For example,x can shop an integer variety like 125 as:
x=125;
Here,x is a varying and = symbolizes that the value 125 is saved into x.This value 125 saved into x.This value 125 saved into x is also known as actual.There are various data types and literals described in Java,which we will be referring to in the section.
INTEGERAL DATA TYPES:
These data types signify integer figures,i.e. figures without any fraxel areas or decimal factors.For example:125,-225678,0,1022, etc .come under this classification.Integer data types are again sub separated into byte,short,int, and lengthy types.
Table information the information types.
LET US TRY TO UNDERSTAND THIS THROUGH AN EXAMPLE GIVEN HERE:
                   byte rno=10;
In the previous declaration,we are announcing byte data type for the varying rno and the value 10,which is saved into rno.Byte symbolizes any value between -128 to +127.
          
                   lengthy x= 150L;          
here,150 is saved into x,which is announced as lengthy type.Notice the L at the end of the declaration.If this L is not there,the JVM allots only 2 bytes of storage to x as against the regular 8 bytes storage that should be alloted to a lengthy type.the purpose for this is that 2 bytes are adequate to shop the value 150.But if we connect l or L at the end of the value as proven in the previous example,the JVM will consider it as a lengthy value and will assign 8 bytes to it.
FLOAT DATA TYPES:
These data types are useful to signify figures with decimal factor.For example,3.14,0.0012,-123.11,etc. are known as sailing factor figures.These are again categorized as float(single perfection sailing factor number) and double(double perfection sailing factor number).The distinction prevails basically in the variety of numbers,they can signify perfectly after the decimal factor.this precision is also known as perfection.Table represents the dimension flow and dual.
CHARACTER DATA TYPE:
This data type symbolizes only one personality like a,P,&,*, etc.Table reveals char data type information.
Here is an example of personality data type:
               char ch="X";
     Here,we are saving the individual personality 'X' into the varying ch.Here,'X' is also known as personality actual.Whenever personality literals are published,they should be surrounded within the individual estimates.
STRING DATA TYPES:
        A Series symbolizes a list of figures.like "NEW DELHI",AP123, etc.The easy way to make a Series is by saving a list of figures into a Series type varying as:
        Series str="New Delhi";
       Now,the Series type varying str contains "New Delhi".Note that any string published straight in a system should be surrounded by using dual estimates.
       There is a classification with the name Series in Java,where several techniques are offered to execute different functions on post.Any string is regarded as an item of Series classification.
But in C/C++,a string is regarded as a personality range containing some figures where the last personality would be /0.This is not legitimate in Java,we got post and personality arrays both independently.
       Now the query occurs that if Series is a classification,why are we discussing it as a knowledge type?
The response is that every classification is a knowledge type and is also known as user-defined data type.Boolean Information Types
BOOLEAN DATATYPES:
Boolean data types signify any of the two values-true or incorrect.
JVM uses 1 bit to signify a boolean value internal,for example:
        boolean response=true;
As proven previously,we should not include the boolean value true(or false) in any estimates represents.In C/C++, 0 symbolizes incorrect and any other variety signify real.this is not legitimate in Java.
LITERALS:
A actual symbolizes a value that is saved into a varying straight in the system.See the following examples:
                boolean result=false;
                char gender="M";
                brief s=10000;
                 int i=-1256;
 In the previous claims,the right side part principles are known as literals because these principles are being saved into the factors proven at the remaining part.As the information type of the varying changes,the type of the actual also changes.So we have different type of literals.
These are as follows:
      1.Integer Literals
      2.Float Literals
      3.Character Literals
      4.String Literals
      5.Boolean Literals.

Integer Literals: Integer literals signify the set integer principles like 100,-55,123450, etc.All these figures are part of decimal system,which uses 10 digits(from 0 to 9) to signify any variety.Suppose,we want to make an integer in octal variety system(octal variety techniques uses 8 numbers,from 0 to 7),then we should prefix o before the variety.To signify hexadecimal number(hexadecimal variety system uses 16 numbers from 0 to 9 and from A to F).we should prefix 0x before the value.
                int decVal=26;         //The variety 26,in decimal
                int octVal=032;       //The variety 26,in octal
                int hexVal=0x1a;     //The variety 26,in hexadecimal

Float Literals: Float literals signify fraxel figures.These are the figures with decimal factors like 2.0,-0.005,3.14,6.1e-22, etc.which should be used with flow or dual type factors.While composing these literals,we can use E or e for medical observe, F or f for flow actual, and D or d for dual literal(this is the standard and usually omitted).
                dual d1 = 123.4;
                dual d2 = 1.234e2;         //same value as d1,but medical notation
                flow f1     =  123.4f;

Character Literals:   Common figures,like A,b,9, etc
                               Unique figures,like ?,@,etc.
                               Unicode figures, like \u0042(this is in ISO Latina 1 figures set).
                               Evade sequence (backslash codes) like \n,\b, etc.
Character literals should be enclosed in individual estimates.The previous Unicode figures and escape sequence can also be showed as post.

String Literals: Series literals signify things of Series classification.For example,Hello,AnilKumar,AP1201,etc. will come under string literals,which can be straight saved into a Series item.

Boolean Literals: Boolean literals signify only two concepts -true and incorrect.It indicates we can shop either
 real or incorrect into a Boolean type varying.

No comments:

Post a Comment