Business Programming Concepts II

Slides:



Advertisements
Similar presentations
Written by: Dr. JJ Shepherd
Advertisements

Week 10: Objects and Classes 1.  There are two classifications of types in Java  Primitive types:  int  double  boolean  char  Object types: 
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
Java Classes Introduction and Chapter 1 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Java Programming Constructs 1 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
More Object Concepts Chapter 4.  Our class is made up of several students and each student has a name and test grades  How do we assign the variables.
Java Classes Appendix C © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Classes CS 21a: Introduction to Computing I First Semester,
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
CH 8 : Enhancing Classes - Review QUICK REVIEW : A Class defines an entity’s (Object’s) data and the actions or behaviors (Methods) associated with that.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Java Arrays and Methods MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Java Expressions MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
CreatingClasses-SlideShow-part31 Creating Classes part 3 Barb Ericson Georgia Institute of Technology Dec 2009.
Written by: Dr. JJ Shepherd
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Object Oriented Programming. Constructors  Constructors are like special methods that are called implicitly as soon as an object is instantiated (i.e.
Java Fundamentals MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Defining Your Own Classes II
Topic: Classes and Objects
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Creating and Using Objects, Exceptions, Strings
Objects as a programming concept
Intro To Classes Review
More About Objects and Methods
Lecture 15: More Inheritance
Object-Oriented Programming & Design Lecture 18 Martin van Bommel
Review: Two Programming Paradigms
Chapter 3: Using Methods, Classes, and Objects
Anatomy of a class Part I
Object-Oriented Programming Using C++
This pointer, Dynamic memory allocation, Constructors and Destructor
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
CSC 253 Lecture 8.
Building Java Programs
Introduction to Classes
CSC 253 Lecture 8.
Inheritance Basics Programming with Inheritance
Corresponds with Chapter 7
Chapter 6 Methods: A Deeper Look
Variables and Their scope
Outline Writing Classes Copyright © 2012 Pearson Education, Inc.
Interfaces.
More on Classes and Objects
Private.
Computer Programming with JAVA
Classes, Constructors, etc., in C++
Simple Classes in Java CSCI 392 Classes – Part 1.
Core Concepts.
Outline Anatomy of a Class Encapsulation Anatomy of a Method
Lecture 15: Inheritance II
Object-Oriented Programming Using C++
Suggested self-checks: Section 7.11 #1-11
Java Programming Language
Classes CS 21a: Introduction to Computing I
Java Basics Data Types in Java.
Classes, Objects and Methods
Dr. R Z Khan Handout-3 Classes
Barb Ericson Georgia Institute of Technology Oct 2005
Chapter 4 Constructors Section 4.4
(C) 2010 Pearson Education, Inc. All rights reserved.
Classes and Objects Object Creation
Anatomy of a class Part I
Creating and Using Classes
CMSC 202 Constructors Version 9/10.
Presentation transcript:

Business Programming Concepts II Java Objects MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh Bajaj, 2006. All rights reserved

Objectives Get started on Object Oriented Programming Learn how to use non-static methods in classes Let’s get started!

Objects Functional decomposition or Divide & Conquer: Take a large task, and break it up into methods (static methods) -Write a main method that calls on these other methods, which in turn may call on other methods. We can also divide our methods into multiple classes, and call them. Think about the TEXTIO class. We used the methods in that (written by someone else) within our own class. Think of our MyCustomerData class in Assignemnt 3. It was used by the TestMyCustomerData class. We can create & use many such classes. Commonly used classes are also called APIs (Application Programming Interface)

Objects Static Methods: Called (invoked) using <classname>.<methodname> E.g., TextIO.getln(); Non-Static Methods: -Cannot be called using <classname>.<methodname> -Instead we need to use <objectname>.<methodname> E.g., MyWord.length() where MyWord is a String object. -An object is created by allocating memory. We can create multiple objects of the same class when running one program Each object will occupy a different portion of main memory, and will have a different name.

Objects Non-Static Methods: A class can have non-static methods as well as static methods. The static methods will be invoked using <classname>.<methodname> The non-static methods can only be invoked by declaring objects of that class. Objects: Objects have methods (non-static) as well as fields (variables). Every time an object is created of a class, memory is allocated for all the non-static class variables (aka member variables) in the class. The non-static methods can access static & non-static variables in their code. The static methods can access only static variables in their code. Why? The object is an instance of its class The non-static class variables are also called instance variables. Static methods and variables are sometimes called class methods or class variables, since they belong to the class, and not to any object (don’t need to create an object to call them). Example: Classes c1 and Testc1

Objects

Fun In Class Assignment -Create a class called Students.java that has four instance variables: name,test1, test2 and test3. Default values are “ZZZZZ” for name and -1.0 for the 3 test scores. -Create methods: void setName(String namePar) void setTest1(double test1Par) String getName() double getTest1() And similarly for test2 and test3. That allow us to set & get values for these variables. The set methods are also called mutator methods The get methods are also called accessor methods.

Objects http://nfp.cba.utulsa.edu/bajaja/mis3023/Text/javanotes4.1/c5/s1.html Note: This is very similar to arrays. An array name is a reference to the array.

Objects When the object variable is created, before new is used, it points to no memory. This is called pointing to null. We can explicitly set an object name to null std = null;//std point to no memory and can test if(std==null){ } If an object points to null, we cannot reference its instance methods or variables. -Doing so would result in a null pointer exception. http://nfp.cba.utulsa.edu/bajaja/mis3023/Text/javanotes4.1/c5/s1.html

Objects http://nfp.cba.utulsa.edu/bajaja/mis3023/Text/javanotes4.1/c5/s1.html What if we set std1 = null; ?

Objects http://nfp.cba.utulsa.edu/bajaja/mis3023/Text/javanotes4.1/c5/s1.html

Objects For more detailed reading: http://nfp.cba.utulsa.edu/bajaja/mis3023/Text/javanotes4.1/c5/s1.html