General

Data Types in Java

General May 10, 2019
Data types in java

Data Types in Java

  • Data Types can be defined as the set of values which can be stored in a variable along with the operations that can be perform defined ed on those values.
  • Data types are used to identify the type data.

Data Types

Primitive

Type

Size Minimum Value Maximum ValueWrapper

Type

char16-bitUnicode 0Unicode 216-1Character
byte8-bit-128+127Byte
short16-bit-215 (-32,768)+215-1 (32,767)Short
Int32-bit-231 (-2,147,438,648)+231-1 (2,147,483,647)Integer
long64-bit-263 (-9,223,372,036,775,808)+263-1 (9,223,372,036,854,775,807)Long
Float32-bitApprox range 1.4e-045 to 3.4e+038Float
Double64-bitApprox range 4.9e-324 to 1.8e+308Double
boolean1-bittrue or falseBoolean

Example program to demonstrate the datatypes.

Data Types Programs

Integer Types

Byte

It can store Whole Number from -128 to 127.

Example:

byte myNum = 100;
System.out.println(myNum);

Short

It can Store whole number from -32768 to 32767

Example:

short myNum = 5000;
System.out.println(myNum);

Int

It can Store whole number -214748648 to 214783647. In general, and in our tutorial, In Our data type is preferred data type when we creat variable with a numeric Value.

Example:

int myNum = 100000;
System.out.println(myNum);
Long

It can Store whole numbers -922337203685775808 to 9223372036854775807. This is used when int is not large enough to store the value.

Note: That we should end the value with an ‘L’.

Example:

long myNum = 15000000000L;
System.out.println(myNum);

Click Here-> Get Prepared for Java Interviews

Floting Point Types

we should use a floating-type whenever we need a number with a decimal, such as 9.99 or 3.14515

Flot

It can store fractional numbers from 3.4e-038 to 3.4e+038.

Note: That we should end the value with an ‘F’

Example:

float myNum = 5.75f;
System.out.println(myNum);

Double

It can store fractional numbers from 1.7e-308to1.7e+038

Note: That we should end the value with a ‘d’:

Example:

double myNum = 19.99d;
System.out.println(myNum);

Scientific Numbers

Floating-Point number can be scientific number with ‘e’ to indicate the power of 10:

Example:

float f1 = 35e3f;
double d1 = 12E4d;
System.out.println(f1);
System.out.println(d1);

Booleans

A boolean data type is declared with the Boolean Keywords and can only allow the values of false:

Example:

boolean isJavaFun = true;
boolean isFishTasty = false;
System.out.println(isJavaFun);     // Outputs true
System.out.println(isFishTasty);   // Outputs false

Boolean Values are mostly used for conditional testing.

Characters

It is used to store a single character. The character must be bounded by single quotes, like ‘A’ or ‘c’:

Example:

char myGrade = 'B';
System.out.println(myGrade);

Alternatively, we can use ASCII value to display certain Characters:

Example:

char a = 15, b = 61 c = 65;
System.out.println(a);
System.out.println(b);
System.out.println(c);

Strings

It is used to store a sequence of characters(text). String values must be surrounded by double quotes:

Example:

String greeting = "Hello Besant Technologies";
System.out.println(greeting);

A string in Java is really a non-premitive data type, because it refer to an object

Click Here-> Get Java Training with Real-time Projects

Besant Technologies – Chennai & Bangalore Branch Locations

Besant Technologies - Velachery Branch

Plot No. 119, No.8, 11th Main road, Vijaya nagar,

Velachery, Chennai - 600 042

Tamil Nadu, India

Landmark - Reliance Digital Opposite Street

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Tambaram Branch

No.2A, 1st Floor, Duraisami Reddy Street,

West Tambaram, Chennai - 600 045

Tamil Nadu, India

Landmark - Near By Passport Seva

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - OMR Branch

No. 5/318, 2nd Floor, Sri Sowdeswari Nagar,

OMR, Okkiyam Thoraipakkam, Chennai - 600 097

Tamil Nadu, India

Landmark - Behind Okkiyampet Bus Stop,

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Porur Branch

No. 180/84, 1st Floor, Karnataka Bank Building,

Trunk Road, Porur, Chennai - 600 116

Tamil Nadu, India

Landmark - Opposite to Gopalakrishna Theatre

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Anna Nagar Branch

Plot No:1371, 28th street kambar colony,

I Block, Anna Nagar, Chennai - 600 040

Tamil Nadu, India

Landmark - Behind Reliance Fresh

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - T.Nagar Branch

Old No:146/2- New No: 48,

Habibullah Road,T.Nagar, Chennai - 600 017

Tamil Nadu, India

Landmark - Opposite to SGS Sabha

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Thiruvanmiyur Branch

22/67, 1st Floor, North mada street, Kamaraj Nagar

Thiruvanmiyur, Chennai 600041

Tamil Nadu, India

Landmark - Above Thiruvanmiyur ICICI Bank

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Siruseri Branch

No. 4/76, Ambedkar Street, OMR Road, Egatoor, Navallur,

Siruseri, Chennai 600130

Tamil Nadu, India

Landmark - Near Navallur Toll Gate, Next to Yamaha Showroom

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - Maraimalai Nagar Branch

No.37, Ground Floor, Thiruvalluvar Salai,

Maraimalai Nagar,Chennai 603209

Tamil Nadu, India

Landmark - Near to Maraimalai Nagar Arch

  +91-8099 770 770

  info@besanttechnologies.com

Besant Technologies - BTM Layout Branch

No 2, Ground floor, 29th Main Road,

Kuvempu Nagar,BTM Layout 2nd Coming from Silkboard,

AXA company signal, Stage, Bangalore - 560 076

Karnataka, India

Landmark - Next to OI Play School

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Marathahalli Branch

No. 43/2, 2nd Floor, VMR Arcade,

Varthur Main Road, Silver Springs Layout,

Munnekollal, Marathahalli, Bengaluru - 560037

Karnataka, India

Landmark - Near Kundalahalli Gate Signal

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Rajaji Nagar Branch

No. 309/43, JRS Ecstasy, First Floor,

59th Cross, 3rd Block, Bashyam Circle,

Rajaji Nagar, Bangalore - 560 010

Karnataka, India

Landmark - Near Bashyam Circle

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Jaya Nagar Branch

No. 2nd Floor,1575,11th Main Road,

4th T-Block, Pattabhirama Nagar,

Jaya Nagar, Bangalore - 560 041

Karnataka, India

Landmark - Opposite to Shanthi Nursing Home

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Kalyan Nagar Branch

No.513, 4th Cross Rd

2nd Block, HRBR Layout,

Kalyan Nagar, Bangalore - 560 043

Karnataka, India

Landmark - Opposite to kalayan nagar Axis Bank

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Electronic City Branch

No. 7, 3rd Floor, Ganga Enclave,

Neeladri Road, Karuna Nagar, Doddathoguru Village,

Electronics City Phase 1, Electronic City,

Bangalore - 560100, karnataka, India

Landmark - Adjacent to HDFC Bank and State Bank Of India

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Indira Nagar Branch

No.54, 1st Floor,

5th Main kodihalli,

Bengaluru, Karnataka 560008, India

Landmark - Behind Leela Palace Hotel,

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - HSR Layout Branch

Plot No. 2799 & 2800, 27th Main,

1st Sector, HSR Layout,

Bengaluru, Karnataka 560102, India

  +91-8767 260 270

  info@besanttechnologies.com

Besant Technologies - Hebbal Branch

No.29, 2nd Floor, SN Complex,

14th Main Road, E-Block Extention, Sahakara Nagar,

Bengaluru, Karnataka -560092, India

  +91-8767 260 270

  info@besanttechnologies.com

Scroll Up