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.

Slides:



Advertisements
Similar presentations
M The University Of Michigan Andrew M. Morgan EECS Lecture 01 Savitch Ch. 2 C++ Basics Flow Of Control.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Data Types and Expressions
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
Variables Chapter 9 - Student Naming, data types, instance variables, math and conversions.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Primitive Variables.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
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.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Primitive Data Types. Identifiers What word does it sound like?
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Introduction to Programming
Primitive Variables.
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.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
Variables and Methods Chapter 3 – Lecture Slides 1(c) 2008 by E.S.Boese. All Rights Reserved. Variables vary... After all, change is the status quo.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
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.
1 2. Program Construction in Java. 01 Java basics.
1 Identifiers: Names of variables, functions, classes (all user defined objects), Examples: a b gcd GCD A COSC1373 TAX Tax_Rate Tax Rate if else while.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
COM S 207 Type and Variable Instructor: Ying Cai Department of Computer Science Iowa State University
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
© 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.
Asst.Prof.Dr. Tayfun ÖZGÜR
Chapter # 2 Part 2 Programs And data
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Working with Java.
Variables Mr. Crone.
Lecture 2: Data Types, Variables, Operators, and Expressions
Multiple variables can be created in one declaration
Variables and Arithmetic Operators in JavaScript
CMSC 104, Section 4 Richard Chang
Unit-2 Objects and Classes
null, true, and false are also reserved.
Computers & Programming Languages
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 2 Variables.
C++ Data Types Data Type
Chapter 2: Java Fundamentals
Variables in C Declaring , Naming, and Using Variables.
Recap Week 2 and 3.
Chapter 2: Java Fundamentals
Programming Language C Language.
© A+ Computer Science - Variables & Data Types © A+ Computer Science - ©A+ Computer Science
Chap 2. Identifiers, Keywords, and Types
Variables and Constants
Presentation transcript:

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 = true;

What is a data type?

A data type describes what type of data the variable will hold. There are 8 basic primitive data types What is a data type?

byte short int long float double char boolean int num = 9; double total = 3.4;

TYPEHoldsRANGE intintegers (32 bit) -2 billion to 2 billion int num = 3; doubledecimals/ floating number (64 bits) -1.7E+308 to 1.7E+308 double num1 = 7.4; boolean {true, false}Holds two values: {true, false} boolean done = false; char One character ‘A’

Declarations A declaration is the introduction of a new name in a program. All variables must declared in advance General forms to declare variable. Data type and variable name  int num;  double digit;  boolean done;

How do you name variables when defining them?

When naming a variable follow these rules and conventions: 1.The variable name must contain NO spaces. 2.The variable name must begin with a lower case letter. 3.If you run two words together, then the first letter of the second word should begin with a capital letter. 4.The remainder of the variable name contains only letters and digits. Can use _ $ as symbols and can start with _ but not recommended. IDENTIFIER variables are identifers

Below are some examples of valid variable names: number sum32 testAverage areaOfTrapezoid and below are some examples of invalid variable names: 2ndValue test Average question#2

Java is case sensitive. Brandon does not equal brandon. Brandon != brandon Java is case sensitive. (Yes, it’s so important that I said it twice!)

Keywords are reserved words that the language uses for a specific purpose. You cannot use keywordsas identifier names. abstractcontinuefornewswitch assert *** default goto * packagesynchronized booleandoifprivatethis breakdoubleimplementsprotectedthrow byteelseimportpublicthrows case enum **** instanceofreturntransient catchextendsintshorttry charfinalinterfacestaticvoid classfinallylong strictfp ** volatile const * floatnativesuperwhile

assignment operator (=). Called initializing the variable. int num = 1000; // This line declares num as an int variable which holds value "1000". boolean bol = true; // This line declares bol as boolean variable which is set to the value "true". boolean result = true; char capitalC = 'C'; byte b = 100; short s = 10000; int i = ; Statements: Statements in Java end with a semicolon ;

OOP: Basic Parts of Java Primitive Data Types, Example // create some integers int x, int y; // declared but not initialized x = 1234; y = 3; //initialized and ready to use double v = 3.14, w = 5.5; //declare and Initialize at same time