CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 12.

Slides:



Advertisements
Similar presentations
Classes And Objects II. Recall the LightSwitch Class class LightSwitch { boolean on = true; boolean isOn() { return on; } void switch() { on = !on; }
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Building Java Programs Interactive Programs w/ Scanner What is a class? What is an object? What is the difference between primitive and object variables?
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Written by: Dr. JJ Shepherd
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 17.
Lab#1 (14/3/1431h) Introduction To java programming cs425
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner Class Design Lecture 6, Tue Jan
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
CS 106 Introduction to Computer Science I 02 / 20 / 2008 Instructor: Michael Eckmann.
2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
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.
Java Language and SW Dev’t
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
CSC 212 Object-Oriented Programming and Java Part 1.
The Java Programming Language
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Chapter 1 Object Orientation: Objects and Classes.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Applications Development
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 11.
Types in programming languages1 What are types, and why do we need them?
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CSE 1341 Honors Note Set 05 Professor Mark Fontenot Southern Methodist University.
Working With Objects Tonga Institute of Higher Education.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Written by: Dr. JJ Shepherd
Exam Review 10/01/2014 Happy October. The Exam  Will be in Canvas  Two parts  Part A is recall – closed book, closed notes ◦Quizzes, in class activity.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
OOP Basics Classes & Methods (c) IDMS/SQL News
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Chapter 1 Object Orientation: Objects and Classes.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Intro to ETEC Java.
3 Introduction to Classes and Objects.
Yanal Alahmad Java Workshop Yanal Alahmad
CSE 413, Autumn 2002 Programming Languages
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Principles of Computer Programming (using Java) Chapter 2, Part 1
null, true, and false are also reserved.
Computers & Programming Languages
A+ Computer Science INPUT.
IFS410 Advanced Analysis and Design
Sridhar Narayan Java Basics Sridhar Narayan
Programs and Classes A program is made up from classes
A+ Computer Science INPUT.
Session 2: Introduction to Object Oriented Programming
Object Oriented Programming in java
Defining Classes and Methods
Chap 2. Identifiers, Keywords, and Types
Happy October Exam Review 10/01/2014.
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 12

Classes and Objects - 1 Object-Oriented Programming – software development methodology – development is based on looking at the problem from the perspective of what objects are interacting in the system. – i.e. University Registration System Students Professors Classrooms Courses with multiple class sections

What have we been doing so far? Procedural programming – Thinking about the different sub-procedures of how to solve a problem. – Data and procedures are separate and unrelated except for the fact that procedures operate on the data – e.g. Average grades for students: Procedural: getGrades, averageGrades, dispalyAverage

Classes and Objects - 2 An Object is a programming construct that has state (contains data) – i.e. every student has an id and name, but values may be different for each student and has behavior (contains methods) – interface allows us to access and manipulate the data in a controlled environment. – i.e. Functionality to retrieve the students name from the object or update the students GPA.

Some Object Semantics We communicate with an object by sending messages to the object. In Java, we send messages by calling methods on the object. Scanner s = new Scanner (System.in); s.nextInt(); s.nextDouble(); Creating a scanner object Sending message to scanner obj to tell it to read the next integer from the keyboard. Sending message to scanner obj to tell it to read the next double from the keyboard.

Primitive vs. Reference Variables Primitive Variable – a variable with a primitive data type – primitive data types are part of the core Java language – short, int, long, char, byte, boolean, double, float. Reference Variable – a variable with a non- primitive data type – EVERYTHING ELSE! – String, Scanner, TouchSensor

Primitive Variables Can be declare with out “creating” using the keyword new. We access the variable directly – Doesn’t have an interface of methods through which to access functionality and data. – Programmer can use the relational operators to compare int a = 10; int b = 20; if (a < b) { //… }

Reference Variables Used to refer to objects Must use the new operator to create an object of a particular type – new Scanner(System.in); – new returns a reference (memory location) that is stored in the reference variable – Scanner s = new Scanner (System.in); returns a memory location that is then stored in s

The Java API API = Application Programming Interface Contains about classes that are already implemented and tested You can use this so as to not re-invent the wheel. – Scanner is a perfect example – Scanner class contains the code to create a scanner object that can allow you to read from a data source. – String is another example We’ll explore this in much more depth throughout the semester.

Classes vs. Objects A class is a blueprint for an object. – It tells the JVM how to construct an object when the programmer asks for one Student Name:String id:String gpa:float void getName() void PrintGPA Student Name:String id:String gpa:float void getName() void PrintGPA Class Student Mark Mark Sam Sam Joe Joe Objects of Type Student

The String Class You can have multiple Strings in your program Can call any method from the String class on any of the String objects. String fName = “Mark”; String lName = “Fontenot; String school = “Southern Methodist University”; Each created based on same String blueprint int len = fName.length(); System.out.println(lName.charAt(2)); if (school.equals(“TCU”)) System.out.println(“Boo!”);

How do you know what methods are available?? Look at the API documentation… – – Lists all of the methods that you can call on a java String object – There is an API doc page for every class that is part of the Java API.

BREAKOUT 1

?