The different types of variables in a Java program.

Slides:



Advertisements
Similar presentations
1 Storage Duration and Scope –Local and global variables Storage classes –automatic, static, external, register Todays Material.
Advertisements

Java Card Technology Ch04: Java Card Object
Written by: Dr. JJ Shepherd
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Road Map Introduction to object oriented programming. Classes
Tutorial 6 & 7 Symbol Table
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
LESSON 4 - Variables JAVA PROGRAMMING. Variables Variable is a named storage location that stores data and the value of the data may change while the.
©2004 Brooks/Cole Chapter 10 More on Classes. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object assignment With primitive types, setting.
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
Introduction to Java Programming, 4E Y. Daniel Liang.
The different kinds of variables in a Java program.
Storage Classes.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Memory organization - storing variables efficiently in the RAM memory.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
1. 2 Reference... Student stu; Reference of Student stu When the reference is created it points to a null value. Before access the reference, objects.
18. DECLARATIONS.
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Week 6: Functions - Part 2 BJ Furman 01OCT2012. The Plan for Today Comments on midterm exam (next week in lab!) Review of functions Scope of identifiers.
3/25: Scope Rules, More Methods about RollDie.java & modifications Scope rules More methods Program of the day.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Copyright Curt Hill Variables What are they? Why do we need them?
Objects and Classes Mostafa Abdallah
The life time of local variables (in a method). Local variables Local variable: A local variable is used to store information that is relevant for the.
 Constructor  Finalize() method  this keyword  Method Overloading  Constructor Overloading  Object As an Argument  Returning Objects.
Classes: user-defined types. Organizing method with a class A class is used to organize methods * Methods that compute Mathematical functions * The Scanner.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MTech[IT],MPhil (Comp.Sci), MCA, MSc[IT], PGDCA, ADCA, Dc. Sc. & Engg.
A little hardware; a little software CS 139 – 08/29/07.
Chapter 3: Developing Class Methods Object-Oriented Program Development Using Java: A Class-Centered Approach.
ROM AND RAM By Georgia Harris. WHAT DOES IT MEAN?  RAM: random access memory  ROM: read only memory.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
Chapter 2. Variable and Data type
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
Week 13 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
JAVA CLASSES, METHODS AND VARIABLES.  Defined Noun: A set or category of things having some property or attribute in common and differentiated from others.
What is an object?. What Makes an Object? An object has identity (it acts as a single whole). Every object has a name that identifies what it is. Ex.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
C Part 2 Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens The Three Attributes of an Identifier Identifiers have three essential.
IB Computer Science Content developed by Dartford Grammar School Computer Science Department Objects as a programming concept.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
The Object-Oriented Thought Process Chapter 03
Classes (Part 1) Lecture 3
C Functions -Continue…-.
More About Objects and Methods
Road Map Introduction to object oriented programming. Classes
Working with Forms in Visual Basic
Haidong Xue Summer 2011, at GSU
Using local variable without initialization is an error.
Advanced Programming Basics
Introduction to Computer Science and Object-Oriented Programming
Arrays .
Cs212: Data Structures Computer Science Department Lecture 2: Arrays.
Instance methods.
Function “Inputs and Outputs”
String.
Chapter 6 Objects and Classes
Understanding Variables
Local variables and how to recognize them
(C) 2010 Pearson Education, Inc. All rights reserved.
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
C Programming Lecture-17 Storage Classes
Presentation transcript:

The different types of variables in a Java program

Different types of information Computer program needs information to operate correctly The information used by computer programs are stored inside variables We can divide the information broadly into: As a result, computer programs use different kinds of variables specialized to store short term and long term information Short term information Long(er) term information

Different types of information (cont.) Furthermore, because variables can take up a lot of RAM memory, we organize the storage of the different kinds of variable in the RAM memory.

The different types of variables in the Java program Java has 4 different kinds of variables (See: ts/variables.html) Class variables Instance variables Local variables Parameter variables

The different types of variables in the Java program (cont.) General information on variables: Each type of variable has it's own characteristics (properties) The type of variable is determined by: Where the variable is defined Whether the keyword static was used in the variable definition.

Properties of variables Every variable has 2 properties: life time = the duration that a variable exists scope = the region in the program where the variable is accessible (can be used)

Properties of variables (cont.) Note: The different kinds of variables (class, instance, local and parameter variables) have different life time durations and different scopes

Why do programs have different kinds of variables The reason is to accommodate different needs: Short term information: Long term information: Some information need only be retained within a (one) method (We call this kind of information local information) Some information must be retained across several methods

Why do programs have different kinds of variables (cont.) Local variables and parameter variables are used to store local (or short term) information Class variables and instance variables are used to store longer term information