Introduction to Objects

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

IT151: Introduction to Programming
10-Jun-15 Using Objects. 2 Overview In this presentation we will discuss: Classes and objects Methods for objects Printing results.
Road Map Introduction to object oriented programming. Classes
1 Basic Object Oriented Concepts Overview l What is Object-Orientation about? l What is an Object? l What is a Class? l Constructing Objects from Classes.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
28-Jun-15 Using Objects. 2 Overview In this presentation we will discuss: Classes and objects Methods for objects Printing results.
29-Jun-15 Using Objects. 2 Classes and objects The type of an object is the class that describes that object If we say int count, the type of count is.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
2.2 Information on Program Appearance and Printing.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Chapter 2: Objects and Primitive Data Classes and Objects String, Random, Math, NumberFormat, DecimalFormat and Wrapper Classes.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Unit 3: Java Data Types Math class and String class.
Program Statements Primitive Data Types and Strings.
Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
Java Software Solutions Lewis and Loftus Chapter 4 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects and Classes -- Introduction.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Introducing Objects and stuff GABY and MATT Definition: Object: “a class that is the root of the hierarchy tree for all classes in JAVA.” –An object.
Introduction to Java Java Translation Program Structure
Programs and Classes A program is made up from classes Classes may be grouped into packages A class has two parts static parts exist independently Non-static.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Chapter 4 Introduction to Classes, Objects, Methods and strings
CSE 501N Fall ‘09 04: Introduction to Objects 08 September 2009 Nick Leidenfrost.
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
CSCI 1100/1202 January 14, Abstraction An abstraction hides (or ignores) the right details at the right time An object is abstract in that we don't.
Unit 3 Lesson 5 Strings and the String Class Mr. Dave Clausen (modifications from the textbook)
CSC 110 – Intro to Computing - Programming
Object and Classes อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 3.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
© 2006 Pearson Education Chapter 2: Objects and Primitive Data Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by.
Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes : Review Java Software Solutions Foundations of Program Design Seventh Edition John.
Object Oriented Programming Idea Computer program may be seen as comprising a collection of objects Object Fundamental entity in a JAVA program Used to.
Content Programming Overview The JVM A brief look at Structure
Introduction to Java part 2
Classes and OOP.
Console Output, Variables, Literals, and Introduction to Type
Java Primer 1: Types, Classes and Operators
Variables, Expressions, and IO
Road Map Introduction to object oriented programming. Classes
Introduction to Objects
Chapter 4: Writing classes
Using Objects 21-Nov-18.
Introduction to Java part 2
Chapter 4 Writing Classes.
Introduction to Primitive Data types
Programs and Classes A program is made up from classes
Introduction to Java Programming
Packages & Random and Math Classes
Object Oriented Programming in java
Introduction to Java part 2
Primitive Types and Expressions
CSC 1051 – Data Structures and Algorithms I
Instructor: Alexander Stoytchev
Introduction to Primitive Data types
String Objects & its Methods
Presentation transcript:

Introduction to Objects We are gong to start with an overview of objected-oriented principles in order to show you the big picture. The information we manage in a Java program is either represented as primitive data or as objects. We’ll start with objects since objects are the building blocks of object oriented programing and get to primitive data a little later.

Introduction to Objects An object is a basic part of a Java program An object represents something with which we can interact in a program An object provides a collection of services that we can tell it to perform for us A software object often represents a real object such as a bank account Every object has: a “state” a set of “behaviors” An object is defined by a class, which is like the data type of the object. A class is the model or blueprint from which an object is created. It establishes the kind of data an object of that type will hold and defines the methods that represented the behavior of such objects or the operations that can be performed on them. By “state” we mean state of being which are basic characteristics that currently define the object. For example, part of a bank account’s state is its current balance. The behaviors of an object are the activities associated with the object. Behaviors associated with a bank account probably include the ability to make deposits and withdrawals.

Using Objects The services are defined by methods in a class that defines the object A class represents a concept, and an object represents the embodiment of a class A class can be used to create multiple objects

Class  Object Here is a visual representation of a class and objects. The car class is simply a blueprint or an idea from which objects can be created. A class is not an object no more that a blueprint is a house. A class contains no space to store data. Each object has space for its own data, which is why each object can have its own state. From that class blueprint, multiple objects can be created. From the car class, we were able to create a Mercedes object, a BMW object, and an Audi object.

Example of Using the System.out Object The System.out object represents a destination to which we can send output In the Lincoln program below, we invoked the println method of the System.out object: System is a class in the java.lang package. out is a static member of the System class, and is an instance of java.io.PrintStream. println is a method of java.io.PrintStream. This method is overloaded to print message to output destination, which is typically a console or file. The println method will print either a string literal such as “Whatever you are, be a good one.” as shown in the example above or a variable in the parameter and then advances the program to the next line. Advancing the program to the next line is what the “ln” in print line does.

The print Method The System.out object provides another service as well The print method is similar to the println method, except that it does not advance to the next line Therefore anything printed after a print statement will appear on the same line

Character Strings Every character string is an object in Java, defined by the String class Every string literal, delimited by double quotation marks, represents a String object A character string is an object in Java, defined by the class String. Because strings are such an important part of computer programming, Java provides something called a String Literal, which appears inside double quotation marks, as we’ve seen in previous examples. We’ll explore string literals in more depth a little later.

String Concatenation The string concatenation operator (+) is used to append one string to the end of another It can also be used to append a number to a string A string literal cannot be broken across two lines in a program

A character string within in double quotation marks cannot be split between two lines of code. One way to get around this problem is to use the string concatenation operator, the plus sign . String concatenation adds one string to another.

We can also use the string concatenation operator to combine text and numbers. Note that the numbers in the last couple of lines are not enclosed in double quotes and are therefore not character strings. In these cases, the number is automatically converted to a string, and then the two strings are concatenated. Digits are characters and can be included in strings as needed.