Note

If you cannot find what you are looking for. Please visit our sitemap

Sunday, 22 February 2015

Java Data Types Literals Escape Sequence

                  Java Data Types Literals Escape Sequence

Java is a Strongly Types Language. It means every variable has a type, every expression has a type, and every type is strictly defined.

The Simple Data Types

Integers:

 byte, short, int and long.

Floating-point numbers:

 float and double.

Characters:

 char.

Boolean:

 Boolean

Integers:

Java has four integers: byte int, short and long. All of these are signed, positive and negative values. Java does not support unsigned, positive-only integers.

Name  Width  Range
long       64     -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
int          32     -2,147,483,648 to 2,147,483,647
short      16     -32,768 to 32,767
byte       8        -128 to 127

byte:

The smallest integer is byte. This is unsigned 8-bit type that has range from -128 to 127. Byte variable are declared by use of the keyword byte.

byte b,c; // where b and c byte variables.

short:

This is unsigned 16-bit type that has range from -32,768 to 32,767. Byte variable are declared by use of the keyword short.

short b;
short c; // where b and c short variables.

int:

The most commonly used integer is int. This is unsigned 32-bit type that has range from -2,147,483,648 to 2,147,483,647. Byte variable are declared by use of the keyword int.
int b;
int c; // where b and c int variables.

long:

This is unsigned 64-bit type that has range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Byte variable are declared by use of the keyword long. It is useful when, big whole numbers are needed.
long b;
long c; // where b and c log variables.

 

Floating-Point Numbers:

Floating- point numbers, also known as real numbers, are used when evaluating expressions that require fractional precision. For exp, calculations such as square root, or transcendentals such as sine and cosine. There are two kinds of floating-point types, float and double, which represent single and double precision.

Name  Width  Range
double   64     1.7e-308 to 1.7e+308
float       32     3.4e-038 to 3.4e+038

Float:

This is a single precision that used 32 bits of storage. it is declared using keyword float.
float temp; // where temp is a float type variable

Double:

This is a double precision that used 64 bits of storage. it is declared using double float.
double temp; // where temp is a double type variable

Characters:

The data types used to store characters is char. Java uses Unicode to represent characters. Unicode defines a fully International character set that can represent all of the characters found in all human languages. In Java char is a 16-bit type variable that has range of 0 to 65,536. char data type is used to declare characters.

ch1=65; // code for A
ch2="B";// where ch1 and ch2 are char type variables

Boolean:

Java has a simple type variable, called boolean, for logical values. It can have only one of these possible values, true or false. boolean type variable is declared by using keyword boolean.
boolean b; // where b is a boolean data type.

Literals

Integers Literals

 Integers are probably the most commonly used type int the typical program. Any number value 1,2,3,4. which are decimal number it also includes base 8 base 16 .

Floating-Point Literals

Floating-point numbers represent decimal values with a fractional component. They can be expressed in either standard or scientific notation.

Boolean Literals

There are only two logical values that a boolean value can have, true and false.

Character Literals

Characters in Java are indices into the Unicode character set. They are 16-bit values that can be converted  into integers and manipulated with the integers operators, such as the addition and subtraction operators.

Escape Sequence

Escape Sequence               Description
\ddd                                     Octal Character(ddd)
\uxxxx                                  Hexadecimal UNICODE character (xxxx)
\'                                          Single quote
\"                                          Double quote
\\                                          Backslash
\r                                         Carriage return
\n                                         New line
\f                                          form feed
\t                                          Tab
\b                                         Backspace

String Literals

String literals in java are specified like they are in the most other languages by enclosing a sequence of characters between a pair of double quotes. Examples are
"Hello World"

Written By: Asad Hussain

No comments:

Post a Comment