SlideServe
Menu
Préférences
© SlideServe · v2026

Primitive Variables

nash avatar
16 diapositives · 285 Views · Oct 12, 2014

Explore the basics of primitive variables in JAVA, including integers, real numbers, characters, and more. Learn about naming rules, conventions, and initialization of variables. Prepare for the AP Exam with key concepts and examples.

Primitive Variables - slide 1
01 / 16Primitive Variables
1 / 17

Télécharger la présentation

Primitive Variables
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Primitive Variables

  2. What’s a Variable? • A quantity or function that may assume any given value or set of values (source – Dictionary.com) • What types of values have we assigned to variables in mathematics and science? • Integers and Real Numbers • Temperature and Weight • Names and Places

  3. What’s a Primitive? • Being the first or earliest of the kind or in existence • Given just one group of binary digits, what types of things could we come up with? • A Binary Value (True/False) • Numbers (1, 4, 21) • Characters (A, k, &)

  4. JAVA’s Primitive Variables • Binary Value (boolean) • Numbers • Integer (byte, short, int, long) • Real Numbers (float, double) • Character (char) • Text (String) – not a regular primitive variable!

  5. Why so many Integer names? • Each one consists of a different number of bits. • For example, a byte consists of 8 bits and holds a value from –128 to 127. • Calculate • 28 = • 128 + 127 + 1 =

  6. The other Integer Variables • shortOccupies 16 bits or 2 bytes • intOccupies 32 bits or 4 bytes • longOccupies 64 bits or 8 bytes • Can you guess the range of values each one stores?

  7. Why so many? • It’s a tradeoff • The greater number of bytes each one stores, the greater the range of values it can represent. • But the larger number of bytes used put more demand on memory resources.

  8. Real Numbers • float • Occupies 32 bits or 4 bytes, with 6 or 7 significant digits. • double • Occupies 64 bits or 8 bytes, with 14 or 15 significant digits.

  9. Characters & Booleans • char • Contains a standard ASCII character • boolean • Contains a TRUE/FALSE value • String • Contains a line of text

  10. AP Exam • The only ones that you need to be familiar with for the AP Exam are: • int • double • boolean • char • String

  11. Declaration • variable_type variable_name; • Example: • int x; • double temperature; • char initial; • boolean light; • String sentence;

  12. Naming Rules • Must start with a letter, underscore(_), or dollar sign($) • After 1st letter, you can use numbers • Can NOT be a JAVA keyword • White Space is not permitted (space). • No Special Characters • They are case sensitive so “BOX” is not the same name as “box”

  13. JAVA keywords

  14. Naming Convention • The first letter of the variable is lower case. • When using more than one word in the variable name, the first letter of each word after the first is capitalized. • Be descriptive (to a limit)

  15. Example • If we wanted to have a double that stores the room’s temperature: • The Good double roomTemperature; • The Bad double ZED; double theTemperatureInOurComputerRoomOnSeptemberTheTenth; • The Ugly (Illegal) double case; double room Temperature; double 9/10/07Temperature;

  16. Initialization • Variables can be initialized when they are declared: • int butterbeerBottles = 99; • double bodyTemperature = 98.6; • char display = ‘a’; • boolean light = false; • String insult = “You Strink!”; • A variable can be turned into a constant by adding the word final at the beginning of the declaration.