Download the JDK - Download the JDK Search the Tutorials...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Download the JDK Search the Tutorials Hide the TOC Trail: Learning the Java Language Lesson: Language Basics Section: Variables Language Basics Variables Primitive Data Types Arrays Summary of Variables Questions and Exercises Operators Assignment, Arithmetic, and Unary Operators Equality, Relational, and Conditional Operators Bitwise and Bit Shift Operators Summary of Operators Questions and Exercises Expressions, Statements, and Blocks Questions and Exercises Control Flow Statements The if-then and if-then-else Statements The switch Statement The while and do-while Statements The for Statement Branching Statements Summary of Control Flow Statements Questions and Exercises Home Page > Learning the Java Language > Language Basics « Previous Trail Next » Primitive Data Types The Java programming language is strongly-typed, which means that all variables must first be declared before they can be used. This involves stating the variable's type and name, as you've already seen: int gear = 1; Doing so tells your program that a field named "gear" exists, holds numerical data, and has an initial value of "1". A variable's data type determines the values it may contain, plus the operations that may be performed on it. In addition to int , the Java programming language supports seven other primitive data types . A primitive type is predefined by the language and is named by a reserved keyword. Primitive values do not share state with other primitive values. The eight primitive data types supported by the Java programming language are: byte : The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays , where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
short : The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte , the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters. int
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Download the JDK - Download the JDK Search the Tutorials...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online