Java Review CIS 304 Intermediate Java Programming for Business.

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four Defining Your Own Classes.
Advertisements

Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Written by: Dr. JJ Shepherd
Lecture 3: Topics If-then-else Operator precedence While loops Static methods Recursion.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Declaring Variables You must first declare a variable before you can use it! Declaring involves: – Establishing the variable’s spot in memory – Specifying.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes Part 1.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
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.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
Understanding class definitions Looking inside classes.
11 Chapter 5 METHODS. 22 INTRODUCTION TO METHODS A method is a named block of statements that performs a specific task. Other languages use the terms.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
SE-1010 Dr. Mark L. Hornick 1 Defining Your Own Classes Part 3.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Copyright © 2003 Pearson Education, Inc. Slide 2-1 Problem Solving with Java™ Second Edition Elliot Koffman and Ursula Wolz Copyright © 2003 Pearson Education,
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
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.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Mathematical Calculations in Java Mrs. G. Chapman.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Copyright Curt Hill Variables What are they? Why do we need them?
CIS 234: Java Methods Dr. Ralph D. Westfall April, 2010.
More Object Concepts— Farrell, Chapter 4 Dr. Burns.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Methods main concepts – method call – object 's methods – actual parameters – method declaration – formal parameters – return value other concepts – method.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
JAVA Practical Unary operators 2. Using Reals 3. Conversions 4. Type Casting 5. Scope 6. Constants.
Class Fundamentals BCIS 3680 Enterprise Programming.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
OOP Tirgul 10. What We’ll Be Seeing Today  Generics – A Reminder  Type Safety  Bounded Type Parameters  Generic Methods  Generics and Inner Classes.
JavaScript Variables. Definition A variable is a "container" for information you want to store. A variable's value can change during the script.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Functions + Overloading + Scope
Classes (Part 1) Lecture 3
Java Programming: Guided Learning with Early Objects
Java Primer 1: Types, Classes and Operators
Computer Science 3 Hobart College
Object Oriented Systems Lecture 03 Method
Java Programming: From Problem Analysis to Program Design, 4e
Lecture Set 4 Data Types and Variables
Defining Classes and Methods
Defining Your Own Classes
Chapter 6 Methods: A Deeper Look
More About Objects and Methods
Programs and Classes A program is made up from classes
Tonga Institute of Higher Education
Chapter 2 Programming Basics.
Object Oriented Programming in java
Primitive Types and Expressions
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Java Review CIS 304 Intermediate Java Programming for Business

Naming Variables and Classes 4 All use letters, numbers and underscores –we'll just use letters and numbers 4 Variables –starts with lower case letter –all words after first are capitalized –all words are "run together" (e.g., myBankAcct)

What is a Variable? 4 named location in memory 4 data type -- points at location in memory where value is stored 4 object -- points at location in memory which references storage location where all the data contents of object are stored –where are instance variables stored? –where are object's methods stored? –where are class variables stored?

Objects and Primitive Data Types 4 What they are –8 Primitive data types –Declaring them –Using them 4 Objects –Declaring them –Constructing them (from a class definition) –Using them

Casting 4 Java is "strongly typed" 4 conversion of types during mathematical operations involving mixed types 4 int can be cast to double automatically with assignment statement 4 primitive data types can be cast –ex: int a = (int) 48.7; casts a double to an int –try this in scrapbook 4 objects can be cast down the hierarchy –ex: (Person) myDictionary.get(lookUpKey);

Operator Precedence Listed in order of decreasing precedence !, unary +, unary - *, /, % +, - =, > ==, != && || =

Operator Precedence (more complete) 4 Listed in order of decreasing precedence (), [ ],. ++, -- !, unary +, unary -, !, (type) right to left *, /, % +, - =, >, instance of ==, != && || =, +=, -=, *=, /=, %= right to left

Classes 4 Class is a template –Class is used to construct objects –Class includes instance variables (which are maintained separately for each object) instance methods class variables, called static variables class methods, called static methods

this 4 private int myVar; 4 public void methodA(int myVar) 4 { this.myVar = myVar; 4 … 4 }

Classes You Should Know 4 String 4 NumberFormat 4 DecimalFormat 4 JOptionPane 4 Wrapper classes for the primitive data types

Dot Notation 4 How this is used with data types 4 object.method() 4 class.method() 4 object.instanceVariable 4 class.instanceVariable

Visibility 4 Concept: from where can you see/access classes, methods and variables 4 Options public private protected package

Scope of Variables 4 Concept: where is a variable available for use 4 Variable is only available within the braces within which it is defined 4 Guidelines –Keep variables as local as possible –Calculate values in preference to storing them –Within reason, use as few variables as possible 4 If duplicate names are used, inner name hides the outer name –easy source of errors –Ex: if varName is both an instance variable and a formal parameter, need to distinguish this.varName from varName