1 / 12

Java Data types and Conversions

Java Data types and Conversions. By Srinivas Reddy.S. www.java9s.com. Primitive Data Types. E.g. 10 -15 30000 555 4567. byte short int long. www.java9s.com. Primitive Data Types. 25.6 44.567 -23.46. float double. ‘a’ ‘u0000 ’. char boolean. true / false. www.java9s.com.

helia
Télécharger la présentation

Java Data types and Conversions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Data types and Conversions By SrinivasReddy.S www.java9s.com

  2. Primitive Data Types E.g. 10 -15 30000 555 4567 byte short int long www.java9s.com

  3. Primitive Data Types 25.6 44.567 -23.46 • float • double ‘a’ ‘\u0000’ • char • boolean true / false www.java9s.com

  4. Declaration • byte a = 20; • short b = 22; • int c = 34567; • long l = 34905857; • float e = 324.5f; / 324.5F; • double g = 2234.5; / 2234.5d; / 2234.5D; • char h = ‘a’; • boolean = true; / false; www.java9s.com

  5. Memory Allocation -Ve +Ve • byte – 8bits – 28 - 256  -128 -1 |0 - 127 128 128 • short – 16 bits – 216 - 65536  -32768 -1 | 0-32767 • int – 32 bits – 232 - 4,294,967,296 • long – 64 bits – 264 - 18,446,744,073,709,551,616 www.java9s.com

  6. Memory Allocation • float – 32 bits • double – 64 bits • char – 16 bits - Unicode • boolean – JVM Dependent www.java9s.com

  7. Understanding the Storage limit Ariane 5 www.java9s.com

  8. Default values • byte • short • int • long • float • double • char - ‘\u0000’ • boolean - false 0 0.0 www.java9s.com

  9. Type Conversion • byte  short int  long (implicitly) • byteshortintlong (Explicit casting) • float  double (implicit) • floatdouble (explicit) • boolean(Cannot be casted) www.java9s.com

  10. Type Casting Implicit Casting byte c = 120; short d = c; Explicit Casting short c = 234; byte d = (byte)c; (We need to explicitly mention to cast) www.java9s.com

  11. Representing +ve and –ve numbers • byte b = 120 • b 01111000 (8 bits) • byte c = -120 • Twos complement • Flip all the bytes • Add 1 • 120  01111000 • Flip  10000111 • Add 1 1 • -120 10001000 • If you have 1 at the MSB, then it will be interpreted as a negative number. www.java9s.com

  12. WWW.JAVA9S.COM www.java9s.com

More Related