© A+ Computer Science - www.apluscompsci.com. A reference variable stores the memory address of an object. Monster fred = new Monster(); Monster sally.

Slides:



Advertisements
Similar presentations
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Advertisements

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
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.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
Data types and variables
How Create a C++ Program. #include using namespace std; void main() { cout
Chapter 2 Data Types, Declarations, and Displays
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Hello, world! Dissect HelloWorld.java Compile it Run it.
String Escape Sequences
Objectives You should be able to describe: Data Types
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.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
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.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
Introduction to Programming
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
© A+ Computer Science - Variables Data Types © A+ Computer Science - Lab 0B.
Copyright Curt Hill Variables What are they? Why do we need them?
Copyright © – Curt Hill Types What they do.
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.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Variables and Types Java Part 3. Class Fields  Aka member variable, field variable, instance variable, class variable.  These are the descriptors of.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
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.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
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.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 2 Basic Computation
BASIC ELEMENTS OF A COMPUTER PROGRAM
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Object Oriented Programming
EPSII 59:006 Spring 2004.
Multiple variables can be created in one declaration
Data Types The type states how much and what kind of data the variable can store. integers- whole numbers no fractional parts int, short, long floating.
Type Conversion, Constants, and the String Object
Chapter 2 Basic Computation
Chapter 2.
© A+ Computer Science - VARIABLES © A+ Computer Science -
Chapter 2 Variables.
C++ Data Types Data Type
Chapter 2: Java Fundamentals
Variables Data Types Lab 0B
Chapter # 2 Part 2 Programs And data
Introduction to Primitives
Primitive Types and Expressions
© A+ Computer Science - Variables & Data Types © A+ Computer Science - ©A+ Computer Science
Variables and Constants
Presentation transcript:

© A+ Computer Science -

A reference variable stores the memory address of an object. Monster fred = new Monster(); Monster sally = new Monster();

© A+ Computer Science - m Monster Object Monster m = new Monster(); 0xF5 m stores the address of a Monster

© A+ Computer Science -

A variable is a storage location for a specified type of value. numDays 365 hTownTax 8.25 int numDays = 365; double hTownTax = 8.25; char grade = ‘A’;

© A+ Computer Science - int numDays = 365; numDays 365 numDays stores an integer value

© A+ Computer Science -

An identifier is used to identify something. public class Triangle{ } int width = 7; Always start identifier names with letters.

© A+ Computer Science - Which of these would be legal identifiers? 1stYear jump Up feet2Inches BigTriangle SpaceInvaders

© A+ Computer Science - Always use names that mean something. double totalPay; class Triangle{ } double a; //very bad class B{} //very bad

© A+ Computer Science - Keywords are reserved words that the language uses for a specific purpose. int double return void static long break continue Keywords cannot be used as identifiers.

© A+ Computer Science - SAM does not equal sam. Sam does not equal sam. Same does not equal sam. Case is important as is spelling.

© A+ Computer Science -

byte short int long float double int whole double fraction The type states how much and what kind of data the variable can store.

© A+ Computer Science - data typememory usagemin.. max byte8 bits-128 to 127 short16 bits to int32 bits-2 billion to 2 billion long64 bits-big to +big float32 bits-big to +big double64 bits-big to +big char16 bit unsigned reference32 bitsn/a It is important to know all data types and what each one can store.

© A+ Computer Science -

int one = 120; int two = ; byte bite = 99; long longInt = ; System.out.println(one); System.out.println(two); System.out.println(bite); System.out.println(longInt); OUTPUT

© A+ Computer Science - int one = 120.0; System.out.println(one); OUTPUT LOP error Integer types can store integer values only. Integer types cannot store fractional / decimal values. Attempting to assign fractional / decimal values to an integer type results in a loss of precision compile error.

© A+ Computer Science -

double one = 99.57; double two = 3217; float three = 23.32f; System.out.println(one); System.out.println(two); System.out.println(three); OUTPUT

© A+ Computer Science - double one = 120.7; System.out.println(one); one = 125; System.out.println(one); OUTPUT Real types can store fractional/decimal values as well as integer values.

© A+ Computer Science -

char let = 'A'; char fun = 65; char test = 'a'; char go = 97; char what = 48; char variables are used to store a single letter. char variables are actually integers.

© A+ Computer Science - char is a 16-bit unsigned int data type. Here is a 16 bit pattern: char let = 65;

© A+ Computer Science - char alpha = 'A'; char ascii = 65; char sum = 'B' + 1; System.out.println(alpha); System.out.println(ascii); System.out.println(sum); System.out.println('B'+1); OUTPUT A C 67

© A+ Computer Science -

boolean go = true; System.out.println(go); boolean stop = false; System.out.println(stop); A boolean type can store true or false only. OUTPUT true false

© A+ Computer Science -

String dude = "hello world"; String buddy = "whoot - \\\\\\\\\\\\"; System.out.println(dude); System.out.println("buddy = " + buddy); OUTPUT hello world buddy = whoot - \\\\\\ A String type stores groups of characters.

© A+ Computer Science -

receiver = 57; receiver = ; In an assignment statement, the receiver is always on the left of the assignment operator ( = ).

© A+ Computer Science - int num; int num = 99; num = 56; definition and assignment assignment only definition only

© A+ Computer Science -

data typememory usagemin.. max byte8 bits-128 to 127 short16 bits to int32 bits-2 billion to 2 billion long64 bits-big to +big float32 bits-big to +big double64 bits-big to +big char16 bit unsigned reference32 bitsn/a It is important to know all data types and what each one can store.

Math Operators in Java You've seen the = used to assign values to variables There are other important operators in Java you can use on numerical variables (ints and doubles): –+ //addition –- //subtraction –* //multiplication –/ //division –() //to specify order of operations

Using Math Operators in Java Order of operations in Java is the same as it is in Algebra. What does each line of code result in? int x = 4; int y = 2; int answer = x * y; answer = x + x * y; answer = (x + x) * y; answer = ((x + x) * y)/4; System.out.println("answer = "+answer);