**  Data Types,Variables and Arrays**

Java strongly typed language:

  • Every variable has a type and every expression has a type and every type is strictly is defined.
  • All assignments in parameters or explicit passing through methods are checked for type compatibility.
  • Java type checks all expressions and parameters to ensure all types are compatible.

Primitive types:(simple types)

  • Java has eight types of primitive data as int,long,byte,short,char,float,double, and boolean.

Integer:

  • Unsigned integer are not needed in java.
  • The concept of unsigned was mostly specifies the high order bit.
  • It manages the high order bit separately by unsigned right shift operator.

Byte:

  • The smallest bit type is signed 8 it range from -128 to 127.

Short:

  • It signed 16 bit type and range from -32768 to 32767
  • Its the probably least used data type

Int:

  • Its the most commonly used method type.It has signed 32 bit type
  • It varies from -2147483648 to 214783647
  • It commonly used to control loops and to index arrays.

Long:

  • It signed 64 bit type is used where int type is not large to hold the desired value.
  • It acts upto an great extent of data is needed.
  • If you need a great value as a result you can use long integer(64 bit type)

Floating point types:(real numbers)

  • It used when evaluating expressions that require fractional precise.
  • It divides into float and double

Float:

  • It has decimal points
  • In integer it has no decimal points.

  • single precision value that use 32 bits of storage

  • single precision is faster as compared to double precision in some computers.

Double:

  • Double precision are denoted by double keyword and use 64 bits to store a value.
  • Double precision is faster than single precision on some modern processor that optimized on mathematical calculations.

Characters:

  • char is used to store the data type of character
  • char in java is not the same as char in C and C++.
  • Java char is 16 bit type.
  • It is used to hold uni code characters and it also hold or read the integer type to perform arithmetic operations.

25/4/17

Booleans:

  • Java has a primitive type for logical values.(return the value of booleans in primitive type)
  • It have two possible values True or False.
  • Operator uses < as boolean value.

  • println() display output by boolean values.

Literals:

  • Provide a means of expressing a specific values in a program.
  • Syntactic representation of boolean,character,numeric,string.

Floating point literals:

  • Decimal values with a fractional component is called floating point.(17.596)

Integer literals:

  • Any whole number value is an integer literal(1,2,40).

Boolean literal:

  • Literal is a numeric value without a decimal point as 65,-89.

Type Conversion and Casting:

  • The two kinds of conversion are implicit(cast and convert) and explicit(datatypes)

  • The value of one type is changed into value of another type without any special derivative from the programmer.

Casting incompatible types:

  • Automatic type conversions are not fullfil the needs.In some cases narrowing conversions are values are made narrower and fit into target type.
  • A cast is simply an explicit type conversion
  • Automatic type promotion and type promotion rules.

Example:

{
return height*width*depth;
}
vol= mybox1.volume();
  • In these statement vol stores the value of mybox1.volume executed values.
  • void setdim{

}

  • In these setdim sets the dimensions of the each box.

results matching ""

    No results matching ""