Data types
Upcoming SlideShare
Loading in...5
×
 

Data types

on

  • 1,983 views

 

Statistics

Views

Total Views
1,983
Views on SlideShare
1,972
Embed Views
11

Actions

Likes
0
Downloads
11
Comments
0

1 Embed 11

http://improvejava.blogspot.in 11

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Data types Data types Presentation Transcript

  • Data types and Literals 1
  • ObjectivesOn completion of this period, you would be able to know• Data types in Java• Literals in Java 2
  • RecapIn the previous class we have discussed • White spaces, separators, literals and keywords • Comments in Java 3
  • Data types in Java• Data types in Java are classified into • Primitive types • Non-primitive types• Primitive types are also known as simple data types• A primitive type is predefined by the language• Primitive types are further classified into • Numeric types • Non-numeric types 4
  • Data types in Java• Non-primitive types are also known as reference types• Non-primitive types are • Classes • Interfaces • Arrays 5
  • The classification of data types in Java Data types in Java Primitive Non-primitive Numeric Non-numeric classe Arrays s integer char InterfaceFloating point Boolea n Fig. 6.1 Data types in Java 6
  • Data types• Primitive Java data types can be grouped into • integers • floating point numbers • characters • boolean 7
  • Integer types• Java defines four integer types: byte, short, int and long• All these are signed, positive and negative values• Java does not support unsigned types• byte is 8 bit width , short is 16 bit width int is 32 bit width and long is 64 bit width 8
  • byte type• The smallest type is byte• Range from -128 to +128• Byte variables are declared by use of keyword ‘byte ‘ eg. byte x, y; 9
  • short type• short is a signed 16 bit type.• Its range is from -32,768 to +32,767• It is probably the least used data type in Java• Keyword used is ‘short’eg. short x; 10
  • int type• The most commonly used integer data type is int• It has a range of -2,147,483,648 to 2,147,483,647• Keyword used is ‘int’eg. int x; 11
  • long type• long is a signed 64 bit type• Useful where an int type is not large enough to hold the desired value• The range of large is quite large• This makes it useful when large, whole numbers are needed• Keyword used is ‘long’eg. : long seconds; 12
  • floating point types• floating point numbers are also known as real numbers• Are used when fractional components are required• float and double are two kinds of floating point types• Keywords used are ‘float’ and ‘double’ 13
  • Float type• float specify a single precision value that uses 32 bits of storage• float type is useful when you require fractional component, but does not require a large degree of precisioneg. float area; 14
  • double type• double uses 64 bits of storage• When you need to maintain accuracy over many iterative calculations or manipulating large valued numbers double is the best choiceeg. : double area; 15
  • character type• In Java the data type used to store character is char• char in Java is different from char in C and C++• Java used Unicode to represent characters• Unicode was selected because it would help in internationalization of Java as a programming language• Java character is 16 bit type. The range of the characters is 0 to 65,536 16
  • boolean type• boolean data type is used to represent logical values that can be either true or false• All relational, conditional and logical operators return boolean values• It used only one bit of storage• Keyword used is ‘boolean’• eg;. • boolean flag; 17
  • The simple data types in Java• In summary Java defines eight simple types of data. They are • byte • short • int • long • char • float • double • boolean 18
  • Summary• In this class we have discussed • Data types in Java • Literals in Java 19
  • Quiz1.Which of the following data type can store only two valuesa) intb) floatc) booleand) All of the above 20
  • Quiz2.String Literal Enclosed witha) ‘‘b) ““c) **d) All the Above 21
  • Frequently Asked Questions1. List the different data types available in Java2. Explain the various data types available in Java3. List the Literal in Java4. Explain the Literals in Java 22