CH2 Notes - Primitive Types, Strings, and Console I/O...

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

View Full Document Right Arrow Icon
Primitive Types, Strings, and Console I/O Chapter 2 Objectives become familiar with Java primitive types (numbers, characters, etc.) learn about assignment statements and expressions learn about strings become familiar with classes, methods, and objects Objectives, cont. learn about simple keyboard input and screen output (optional) learn about windows-based input and output using the JOptionPane class Outline Primitive Types and Expressions The Class String Keyboard and Screen I/O Documentation and Style (optional) Graphics Supplement Prerequisite familiarity with the notions of class , method , and object Primitive Types and Expressions: Outline Variables Java Identifiers Primitive Types Assignment Statements Specialized Assignment Operators Simple Screen Output Simple Input Primitive Types and Expressions: Outline, cont. Number Constants Assignment Compatibilities Type Casting Arithmetic Operations Parentheses and Precedence Rules Increment and Decrement Operators (whew!) Variables and Values Variables store data such as numbers and letters.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Think of them as places to store data. They are implemented as memory locations. The data stored by a variable is called its value. The value is stored in the memory location. Its value can be changed. Variables and Values, cont. class EggBasket (page 50) Variables and Values, cont. variables numberOfBaskets eggsPerBasket totalEggs assigning values eggsPerBasket = 6; eggsPerBasket = eggsPerBasket - 2; Naming and Declaring Variables Choose names that are helpful such as count or speed , but not c or s . When you declare a variable, you provide its name and type. int numberOfBaskets,eggsPerBasket; A variable’s type determines what kinds of values it can hold ( int , double , char , etc . ). A variable must be declared before it is used. Syntax and Examples syntax type variable_1, variable_2, …; ( variable_1 is a generic variable called a syntactic variable) examples int styleChoice, numberOfChecks; double balance, interestRate; char jointOrIndividual; Types in Java A class type is used for a class of objects and has both data and methods. “Think Whirled Peas” is a value of class type String A primitive type is used for simple, nondecomposable values such as an individual number or individual character. int, double, and char are primitive types. Naming Conventions Class types begin with an uppercase letter (e.g. String ). Primitive types begin with a lowercase letter (e.g. int ). Variables of both class and primitive types begin with a lowercase letters (e.g. myName, myBalance ).
Background image of page 2
Multiword names are “punctuated” using uppercase letters. Where to Declare Variables
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

CH2 Notes - Primitive Types, Strings, and Console I/O...

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

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