COM S 207 Type and Variable Instructor: Ying Cai Department of Computer Science Iowa State University

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Data Types and Expressions
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
Lecture 2: Variables and Expressions Yoni Fridman 6/29/01 6/29/01.
Variables, Constants and Built-in Data Types Chapter 2: Java Fundamentals.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
COM S 207 While-Loop Statement Instructor: Ying Cai Department of Computer Science Iowa State University
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
CPS120: Introduction to Computer Science
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Variables.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Primitive Variables.
A variable is a storage location for some type of value. days 102 taxrate 7.75 int days = 102; double taxrate = 7.75; char grade = ‘A’; boolean done.
Copyright Curt Hill Variables What are they? Why do we need them?
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
COM S 207 Literal, Operator, and Expression Instructor: Ying Cai Department of Computer Science Iowa State University
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
COM S 207 ArrayList Instructor: Ying Cai Department of Computer Science Iowa State University
1.2 Primitive Data Types and Variables
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
ICS102 Lecture 1 : Expressions and Assignment King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer.
1 2. Program Construction in Java. 01 Java basics.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Fundamentals 2.
Chapter 2 Variables.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
User Interaction and Variables
Chapter 2 Basic Computation
Elementary Programming
Chapter 4 – Fundamental Data Types
Documentation Need to have documentation in all programs
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Variables and Primative Types
IDENTIFIERS CSC 111.
Building Java Programs Chapter 2
Unit-2 Objects and Classes
Computers & Programming Languages
Chapter 2 Edited by JJ Shepherd
Unit-1 Introduction to Java
Chapter 2 Variables.
C++ Data Types Data Type
Chapter 2: Java Fundamentals
Storing Information Each memory cell stores a set number of bits (usually 8 bits, or one byte) (byte addressable)
Chapter 2: Java Fundamentals
Java Programming Review 1
Primitive Types and Expressions
© A+ Computer Science - Variables & Data Types © A+ Computer Science - ©A+ Computer Science
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 2 Variables.
Use a variable to store a value that you want to use at a later time
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Presentation transcript:

COM S 207 Type and Variable Instructor: Ying Cai Department of Computer Science Iowa State University

8 Primitive Data Types Integer types byte (8 bits): [ -2^7, 2^7-1], i.e., [-128, 127] short (16 bits): [ -2^15, 2^15-1], i.e., [-32,768, 32,767] int (32 bits) : [ -2^31, 2^31-1] long (64 bits): : [ -2^63, 2^63-1] Float types float (32 bits) double (64 bits) Other types boolean (1 bit)  true / false char (16 bits)  ‘a’, ‘A’,..., ‘1’, ‘2’

Variable: A named space that stores values of one particular type Declare a variable (give a type and a name) Ask for a space and give it a name In Java, each variable must have a type Store a value (save) Get the stored data (recall) Examples int numberOfStudents; //declare a variable numberOfStudents = 10; //save the data in the space System.out.println(numberOfStudents); //recall

Declaring a variable When declaring a variable, you specify a name, a type, and often an initial value

Naming a variable Name should describe the purpose “canVolume” is better than cv Use five simple rules Use only letters, digits or the underscore (_)  Don’t start with a digit Separate words with “camelHump” notation Variable names are case-sensitive Don’t use reserved “java” words (See App.B) Variables start with lower case, class names with upper case (by convention, not a rule)

Legal and illegal variable names in Java

Assign value to a variable

Common Error Undeclared variables You must declare a variable before you use it double canVolume = 12 * literPerOunce; double literPerOunce = ; Uninitialized variables You must initialize a variable before you use it int bottles; int bottleVolume = bottles * 2;

Other Frequently Used Types String String courseName = “COMS 207”; String studentName = “John Scott”; System.out.println(courseName);

Announcements Read chapter 2 (2.1, 2.2., 2.3) Recitation this week Homework 1 Posted on blackboard Use blackboard to submit answers