The different kinds of variables in a Java program



Similar documents
Install Java Development Kit (JDK) 1.8

Lecture 9. Semantic Analysis Scoping and Symbol Table

Moving from CS 61A Scheme to CS 61B Java

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

UML for C# Modeling Basics

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

SQL 2012 Compatibility and Vista View Conversion. Presented By: Deepali Savkoor Ellucian June 12, 2014

Programming Languages CIS 443

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Poisson processes (and mixture distributions)

Java (12 Weeks) Introduction to Java Programming Language

Curriculum Map. Discipline: Computer Science Course: C++

Iteration CHAPTER 6. Topic Summary

7. Solving Linear Inequalities and Compound Inequalities

Mathematics sample unit Order of Operations Stage 3. Detail: 8 activities. Substrand: S3 NA Multiplication and Division 2 (part)

Clustering and scheduling maintenance tasks over time

SQL Server. 1. What is RDBMS?

Design Patterns in Parsing

Java SE 8 Programming

Sequence Diagrams. Massimo Felici. Massimo Felici Sequence Diagrams c

Explicit Flow Control: break label, goto case and explicit switch

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Order of Operations More Essential Practice

1 Basic commands. 2 Terminology. CS61B, Fall 2009 Simple UNIX Commands P. N. Hilfinger

A Case for Overlays in DCN Virtualization Katherine Barabash, Rami Cohen, David Hadas, Vinit Jain, Renato Recio and Benny Rochwerger IBM

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

This chapter describes how to set up and manage VPN service in Mac OS X Server.

The join operation allows you to combine related rows of data found in two tables into a single result set.

Applies to Version 6 Release 5 X12.6 Application Control Structure

Software Development (CS2500)

Chapter 1 Fundamentals of Java Programming

ECE 341 Coding Standard

JAVA - INNER CLASSES

CS 338 Join, Aggregate and Group SQL Queries

Concepts and terminology in the Simula Programming Language

Android Application Development Course Program

EXTENDING NETWORK KNOWLEDGE: MAKING OLSR A QUALITY OF SERVICE CONDUCIVE PROTOCOL

Web Browser Session Restore Forensics A valuable record of a user s internet activity for computer forensic examinations

Compound Inequalities. AND/OR Problems

Fundamentals of Java Programming

9. Text & Documents. Visualizing and Searching Documents. Dr. Thorsten Büring, 20. Dezember 2007, Vorlesung Wintersemester 2007/08

El Dorado Union High School District Educational Services

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

The Web Web page Links 16-3

Nested Blocks and Variable Scope. Copyright 2007, Oracle. All rights reserved.

LAB4 Making Classes and Objects

Basic Lisp Operations

Object Oriented Software Design

CASCADING IF-ELSE. Cascading if-else Semantics. What the computer executes: What is the truth value 1? 3. Execute path 1 What is the truth value 2?

SQL Server Database Coding Standards and Guidelines

Chapter 13 Storage classes

Understanding class definitions

Object Oriented Software Design

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

Japan Communication India Skill Development Center

DIPLOMA IN WEBDEVELOPMENT

GUI Event-Driven Programming

Oracle Fusion Middleware

Object Oriented Software Design II

Chapter 7 Probability. Example of a random circumstance. Random Circumstance. What does probability mean?? Goals in this chapter

i. Node Y Represented by a block or part. SysML::Block,

A Production Planning Problem

Java Interview Questions and Answers

Japan Communication India Skill Development Center

Java EE Web Development Course Program

Oil Fill, Breather, and PCV Information For PML Small Block Chevrolet Center Bolt Valve Covers

This loop prints out the numbers from 1 through 10 on separate lines. How does it work? Output:

Probability: Terminology and Examples Class 2, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

AppendixA1A1. Java Language Coding Guidelines. A1.1 Introduction

Modern PL/SQL Code Checking and Dependency Analysis

vcloud Director User's Guide

Japan Communication India Skill Development Center

Lumen Recruitment Systems

MySQL for Beginners Ed 3

Bonus ChapteR. Objective-C

Dangerous Goods Management (EHS-DGP)

Performance Tuning for the Teradata Database

<Project Name> Bill of Materials

Machine Learning and Data Mining. Regression Problem. (adapted from) Prof. Alexander Ihler

Structured Query Language (SQL)

Software Paradigms (Lesson 1) Introduction & Procedural Programming Paradigm

Embedded BI made easy

DJIGZO ENCRYPTION. Djigzo white paper

C++ INTERVIEW QUESTIONS

Certified PHP/MySQL Web Developer Course

Software Engineering. What is a system?

Assembly Instructions ShadeTree Canopy Systems. A wood support constructed with a ShadeTree Bracket System. Garden Getaway

Conditional Statements Summer 2010 Margaret Reid-Miller

COMMUNITY COLLEGE OF CITY UNIVERSITY CITY UNIVERSITY OF HONG KONG

Cable Routing Procedures for Dell PowerEdge R310 & R410 Systems

Transcription:

The different kinds of variables in a Java program

The different kinds of variables in a Java program Java has 4 different kinds of variables Class variables Instance variables Local variables Parameter variables The kind of variable is determined by: Where the variable is defined Whether the keyword static was used in the variable definition.

Properties of variables (1) 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 (2) To accommodate different needs: Short term information: Some information need only be retained within a (one) method(we call this kind of information local information) Long term information: Some information must be retained across several methods

Local variables (1) A local variable is used to store information that is relevant for the duration of the execution of one method A local variable will exists as long as the method in which they have been created is still running As soon as the method terminates (i.e., returns), all the local variables defined inside the method are destroyed.

Local variables (2) A local variable is defined inside the body of a method

Local variables (3)

Local variables (4) A local variable only exists between: The definition of the local variable The end of the method where the local variable is defined

Scope of a variable Scope of a variable = the region in the program where the variable is accessible Between the 2 location above, the scope of a variable is further limited by the block in which it is defined

The scope of local variables (1)

The scope of local variables (2) The access of the variable r was limited to the block in which it was defined!!!

The scope of local variables (3)

The scope of local variables (4) You cannot define different variables with the same name inside the same scope

Non-overlapping (or disjoint) scopes (1) Disjoint scopes = 2 or more scopes that do not overlap with each other

Non-overlapping (or disjoint) scopes (2)

Scoping rule for nested scope (1)

Scoping rule for nested scope (2)

Parameter Variables

Parameter variables (1) A parameter variable is used to store information that is being passed from the location of the method call into the method that is called

Parameter variables (2)

Parameter variables (3)

Defining parameter variables (1) A parameter variable is defined inside the brackets (... ) of the header of a method

Defining parameter variables (2)

The life time and scope of parameter variables (1) The life time of a parameter variable is the entire body of the method A parameter variable behaves like a local variable that is defined at the start of the method

The life time and scope of parameter variables (2) You cannot define different variables with the same name inside an outer scope and inside an inner scope In Java, you cannot define a local variable inside a method that has the same name as a parameter variable.

Class Variables

Class Variables (1) A class variable is used to store long term information that are used by many different methods in the program Can have the public access Must use the keyword static Inside the braces {... } of a class outside the braces {... } of every method

Class Variables (2)

Accessing a class variable (1) A class variable is accessed using its complete name: nameofclass.nameofclassvariable

Accessing a class variable (2) We can reference a class variable defined inside the same class without using the class name

The life time and scope of (public) class variables (1) Class variables exist for the entire execution of the Java program Class variables are accessible in every method of every class

The life time and scope of (public) class variables (2) When the method has a local variable or a parameter variable is equal to the name of the class variable, then: The class variable with the same name can no longer accessible with the short hand notation in that scope!!!

The life time and scope of (public) class variables (3)