1 / 13

Java

Java. Primitive Data Types. Non-Decimal Numbers are integers. The types byte, short, int , and long are used to store Non-Decimal N umbers. Non-decimal numbers. byte. Non-Decimal N umbers. Size 8 bits Range -128 to 127 (inclusive) Use

Télécharger la présentation

Java

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 Primitive Data Types

  2. Non-Decimal Numbers are integers. The types byte, short, int, and long are used to store Non-Decimal Numbers. Non-decimal numbers

  3. byte • Non-Decimal Numbers • Size • 8 bits • Range • -128 to 127 (inclusive) • Use • - Only use if you KNOW you will not need to include numbers outside the range. • Only use if memory saving is a top priority. Implementation byte b = 98;

  4. short • Non-Decimal Numbers • Size • 16 bits • Range • -32,768 to 32,767 (inclusive) • Use • - Only use if you KNOW you will not need to include numbers outside the range. • - Only use if memory saving is a priority. Implementation short s = 7456;

  5. int • Non-Decimal Numbers • Size • 32 bits • Range • -2,147,483,648 to 2,147,483,647 (inclusive) • Use • - This is the default data type for non-decimal numbers. • - Use this type unless numbers in your program exceed the range. Implementation inti = 82945;

  6. long • Non-Decimal Numbers • Size • 64 bits • Range • -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (inclusive) • Use • - Use only if numbers in the program exceed the range of int. Implementation long l = 28947302;

  7. Decimal Numbers can be used to store any number. The types float and double are used to store Decimal Numbers. Decimal numbers

  8. float • Decimal Numbers • Size • 32 bits • Use • Smaller than standard data type. • Use only if memory usage needs to be very small. • DO NOT use for values that require great precision. Implementation float f = 12.54;

  9. double • Decimal Numbers • Size • 64 bits • Use • This is the default data type for decimal numbers. • DO NOT use for values that require great precision. Instead use the java.math.BigDecimal class. Implementation double d = 823.9483;

  10. These primitive data types are used to store other values. They include boolean and char. Other values

  11. boolean • Other Values • Use • Can only contain true or false. • Use only to track and flag true/false conditions Implementation boolean b = true;

  12. char • Other Values • Size • 16 bits • Use • Used for storage of characters other than numbers, such as letters, spaces, and other symbols. Implementation char = ‘h’;

  13. A Final Note No primitive data type needs “new” to be initialized since all are built into JAVA. Also, although string is not considered a primitive data type, programmers often think of it as so, since it is also built into JAVA.

More Related