In Java.... Variables contain the values of primitive data types Value Types.

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

Discussion1 Quiz. Q1 Which of the following are invalid Java identifiers (variable names)? a) if b) n4m3 c) Java d) e) DEFAULT_VALUE f) bad-choice.
Lecture 9: More on objects, classes, strings discuss hw3 assign hw4 default values for variables scope of variables and shadowing null reference and NullPointerException.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
J AVA AND V ARIABLES. O VERVIEW Declaring a Variable Primitive Types Java Keywords Reference Variables Object Declaration and Assignment Objects and Garbage.
Road Map Introduction to object oriented programming. Classes
Lecture 12: Using Classes Yoni Fridman 7/19/01 7/19/01.
CS102 Data Types in Java CS 102 Java’s Central Casting.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
CS 106 Introduction to Computer Science I 02 / 20 / 2008 Instructor: Michael Eckmann.
Objects vs. Primitives Primitive Primitive byte, short, int, long byte, short, int, long float, double float, double char char boolean boolean Object (instance.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
C pointers (Reek, Ch. 6) 1CS 3090: Safety Critical Programming in C.
Java Unit 9: Arrays Declaring and Processing Arrays.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Lec 19 Array Intro. Agenda Arrays—what are they Declaring Arrays Constructing Arrays Accessing Array cells.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
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 Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
More arrays Primitive vs. reference parameters. Arrays as parameters to functions.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
Variables, Primitives, and Objects A Visual Learner’s Guide.
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.
Parameter Passing with Java See also the examples: Parameters1.java, Parameters2.java, Parameters3.java and Parameters4.java © Juhani Välimäki 2003.
Objects and Classes Chapter Nine. Definition “an object is a combination of some data (variables) and some actions (methods)”. Hopefully the data and.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
More than just a song and dance.. They are objects that store primitive variable values: Integer – stores an int Double – stores a double Character –
CSC 142 Computer Science II Zhen Jiang West Chester University
Templates Where the TYPE is generic. Templates for functions Used when the you want to perform the same operation on different data types. The definition.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Today’s lecture Review chapter 5 go over exercises.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Reference Types CSCI-1302 Lakshmish Ramaswamy. Reference Variables Java supports 8 primitive types All other types are reference types Reference variable.
Sections Basic Data Structures. 1.5 Data Structures The way you view and structure the data that your programs manipulate greatly influences your.
Memory Management in Java Mr. Gerb Computer Science 4.
Strings A String is a sequence of letters
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Road Map Introduction to object oriented programming. Classes
Unit-2 Objects and Classes
null, true, and false are also reserved.
Computers & Programming Languages
Arrays and Collections
Value Types and Reference Types
Local Variables, Global Variables and Variable Scope
Sridhar Narayan Java Basics Sridhar Narayan
Simple Classes in Java CSCI 392 Classes – Part 1.
Programs and Classes A program is made up from classes
Core Concepts.
Java Programming Review 1
Java Programming Language
Java’s Central Casting
Chapter 3 Introduction to Classes, Objects Methods and Strings
Subtype Substitution Principle
Lec 17 Using Nested Loops and Objects in an Applet Class
Presentation transcript:

In Java...

Variables contain the values of primitive data types Value Types

 In Java, primitive data types such as int, float, double, char, and boolean are called value types  A variable of one of these types is a container for one value of its appropriate type counterpricefoundIt 75.99false Value types of variables contain their values

Value Types  Because a variable of a value type is a container for ONE value of the corresponding type, giving it a second value replaces the first value entirely with the second dependents 2 2 3

Objects of Classes Reference Types in Java

Reference Types  A variable declared as a reference to an object of some class (either a built-in class or a user-defined class) is a reference type  A reference variable DOES NOT contain the the object to which it refers – instead, it refers to that object (i.e., it points to that object)  A reference variable is null (refers to nothing) until it is given an object for it to reference Reference Actual Object

Reference Types personA personB null null personA personB Rachel Walling new creates an actual object of type Person initialized to Rachel Walling Two different references now refer to a single actual object

Reference types  Just as value types may only have one value at a time, reference types may only refer to one actual instance at a time bob Bob Smith After line 5

Reference types  As value types may only have one value at a time, reference types may only refer to one actual instance at a time bob Bob Smith Bob Jones Since nothing refers to this object now, it is destroyed (“garbage collected”) by Java After line 7