Class Notes (807,845)
Canada (492,872)
CMPUT101 (15)
Lecture 4

CMPUT 114 - Lecture 4 - References: Literals, Variables and Assignment(1)

2 Pages
Unlock Document

University of Alberta
Computing Science
Duane Szafron

CMPUT 114 – Lecture 4 – References: Literals, Variables and Assignment Referring to objects & values – In a written program, we can’t draw shapes so we need to have some notation for referring to objects and values called a reference Literals – There are different ways to reference objects & values in a program: ○ Literals ○ Variables – The simplest way is to use a literal in our code. – A literal refers to the same object or value at all times. – You can think of a literal as a nameplate that is automatically pre-bound to an object or value – Literals and values cannot be re-bound Literal Tokens – In general, a literal is recognized by the compiler and is immediately translated into a language value or object – Common literals in programming languages include characters, numbers, and strings Variables – Literals are somewhat restrictive because: ○ Some objects cannot be referred to using literals ○ Sometimes we may want to rebind our nameplates. – A variable is like a soft nameplate that may be attached to an object or value and may be re-attached to a different object or value in the future. – More than one variable can be attached to the same object or value at the same time Java: 4 Kinds or Variables – local variables (Inside a method) – static variables (sometimes called “class” variables) – message parameters (specified in the method params) – instance variables (specified outside in the class.) Variable Declarations – Every variable must be declared – The declarations syntax for each kind of variable is different – A declaration specifies: ○ The amount of memory to be allocated ○ How the data should be internally represented ○ How the data can be l
More Less

Related notes for CMPUT101

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.