Showing posts with label data types. Show all posts
Showing posts with label data types. Show all posts

Tuesday, August 17, 2021

# 6. Data types

 Data types

Whenever we define some data in java, compulsory we should tell what type of data it is.

By using data type we can tell what type of data it is

 There are two data types

1. Primitive data types

Byte ----> 1 byte (8 bits)

Short ----> 2 bytes (16 bits)

Int --------> 4 bytes (32 bits)

Long ------> 8 bytes (64 bits)

Float-------> 4 bytes (32 bits)

Double------> 8 bytes(64 bits)

Char ---------> 2 bytes (16 bits)

Boolean-------> 1 bit

2. Non-primitive data types

String

Arrays

etc

Integer data types

----------------------------

Whole numbers

byte -------> -128 to + 127

Ex: 45

short ------> -32768 to +32767

Ex: 456

int ---------> -2147483648 to +2147483647  ( -2^31 to 2^31-1 )

Ex: 98768765

long -------> -2^63 to +263-1

Ex: 9166691345 l

In java whenever we want to convey the data as long suffix the data with l

Floating-point data types:

-----------------------------------

real numbers

To represent real numbers we have a data type called floating-point data

whenever our data have 0-6 decimal place of accuracy then go for float.

float -----------> 0-6 (f) ---------------> 4 bytes(32 bits)  //suffix with f

Ex: 32.12f, 34567231.1f,56677.99f

double ---------> 6+ -------------------> 8 bytes (64 bits)

Ex: 546.98768767, 5.97865423


under integer, we have whole numbers and under floating-point, we have real numbers.


>>> class Data_Types{        // access specifier optional, class keyword, class name, start of a class


// data is constant, access specifier, data type, variable name, data.

// static

static public byte bnum=100;

static public short snum=1000;

static public int inum= 1000000;

static public long lnum=8890768768l;

static public float fnum=98.89f;

static public double dnum=78.9876597;


// data is constant, access specifier is optional, data type, variable name, data.

// static

static byte bnum=100;

static short snum=1000;

static int inum= 1000000;

static long lnum=8890768768l;

static float fnum=98.89f;

static double dnum=78.9876597;


// data is not constant, access specifier, data type, variable name,data

// non-static

public byte bnum=100;

public short snum=1000;

public int inum= 1000000;

public long lnum=8890768768l;

public float fnum=98.89f;

public double dnum=78.9876597;


// data is going to change means constant, access specifier is optional, data type, variable name, data

// non-static

 byte bnum=100;

 short snum=1000;

 int inum= 1000000;

 long lnum=8890768768l;

 float fnum=98.89f;

 double dnum=78.9876597;

}        // end of a class






# 16. control statements

 Control statements: In java, by using control statements we can tell the flow of execution. in which order the statements should execute. d...