Unit 6 - Variables - Fundamental Data Types

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
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.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Local Variables and Scope Benjamin Fein. Variable Scope A variable’s scope consists of all code blocks in which it is visible. A variable is considered.
1 CS1001 Lecture Overview Java Programming Java Programming.
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.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
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.
Java Programming Constructs 1 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Chapter 8: Arrays.
Primitive Variables.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
 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.
Data Types, Variables, and Arithmetic JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
August 6, 2009 Data Types, Variables, and Arrays.
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
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.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
Data Types, Variables, and Arithmetic Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by.
A: A: double “4” A: “34” 4.
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. 
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
1 2. Program Construction in Java. 01 Java basics.
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
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.
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.
Welcome to Computer Programming II! Computer Programming II Summer 2015.
Fundamentals 2.
Chapter 2 Variables.
JAVA MULTIPLE CHOICE QUESTION.
Variable Declarations
Chapter 4 – Fundamental Data Types
Object Oriented Programming
Selenium WebDriver Web Test Tool Training
Review Operation Bingo
Building Java Programs Chapter 2
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Chapter 2 Variables.
Chapter 2: Java Fundamentals
Sridhar Narayan Java Basics Sridhar Narayan
Statements and expressions - java
Building Java Programs
Recap Week 2 and 3.
Data Types Imran Rashid CTO at ManiWeber Technologies.
Java Programming Review 1
Unit 3: Variables in Java
Chapter 2 Variables.
Comparing Python and Java
Just Enough Java 17-May-19.
Variables and Constants
Presentation transcript:

Unit 6 - Variables - Fundamental Data Types

Variables A variable is a “named container” that holds a value. Example: q = 100 - q; means: 1. Read the current value of q 2. Subtract it from 100 3. Move the result back into q mov ax,q mov bx,100 sub bx,ax mov q,bx

Fundamental Data Types in Java Type Name Kind of data Memory used Size range int integers 4 bytes -2,147,483,648 to 2,147,483,647 double decimal #s 8 bytes ±1.76769 x 10^308 to ± 4.94 x 10^-324 char single 2 bytes all characters character boolean true or false 1 bit true or false ALL OTHER TYPES ARE CLASSES!!!

Your first Java class Class Name Kind of data Memory used Size range String words or varies any word phrases or phrase

Variables (cont’d) A variable must be declared before it can be used: int count; double x, y; JButton go; Walker amy; String firstName; Name(s) Type The name should be descriptive!!

Variables (cont’d) The assignment operator = sets the variable’s value: Examples int numberOfStudents; double myGPA = 4.15; boolean studentAbsent = false; String firstName; String phoneNumber = “707-433-5777”;

Variables: Scope Each variable has a scope — the area in the source code where it is “visible.” If you use a variable outside its scope, the compiler reports a syntax error. Variables can have the same name when their scopes do not overlap. { int k = ...; ... } for (int k = ...)

Variables: Fields Or: public class SomeClass { Scope Fields } Constructors and methods Or: public class SomeClass { } Constructors and methods Scope Fields

Variables: Local Variables Local variables are declared inside a constructor or a method. Local variables lose their values and are destroyed once the constructor or the method is exited. The scope of a local variable is from its declaration down to the closing brace of the block in which it is declared.

Variables: Local Variables public class SomeClass { ... public SomeType SomeMethod (...) } Scope Local variable declared Local variable declared