Introduction to Java, OO and IDEs ICW Lecture 2 Errol Thompson Room 134.

Slides:



Advertisements
Similar presentations
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Objects, Classes, and Packages “Static” Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 6: 1 Progress By now you should have: Worked through units 1 to 5 of the learning.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
Objects & Object-Oriented Programming (OOP) CSC 1401: Introduction to Programming with Java Week 15 – Lecture 1 Wanda M. Kunkle.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Introduction to a Programming Environment
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Object Oriented Software Development
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
Introduction to Object-Oriented Programming
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Parameters. Overview A Reminder Why Parameters are Needed How Parameters Work Value Parameters Reference Parameters Out Parameters.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Applications Development
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 Programming Week 2 2 Inheritance Basic Java Language Section.
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.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Working With Objects Tonga Institute of Higher Education.
Designing Classes CS239 – Jan 26, Key points from yesterday’s lab  Enumerated types are abstract data types that define a set of values.  They.
3. Methods. Programming Paradigms Procedural Programming ‘Imperative’ assignment used to create state, and procedures manipulate state. E.g., C, Assembly,
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
Object Oriented Software Development 4. C# data types, objects and references.
CS2 Module 26 Category: OO Concepts Topic: Interfaces Objectives –Interfaces.
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
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the.
Fundamental Programming Fundamental Programming Introduction to Functions.
Chapter 1: Introduction to Computers and Programming.
Topic: Classes and Objects
Objects as a programming concept
3 Introduction to Classes and Objects.
Programming Language Concepts (CIS 635)
Lecture 11 C Parameters Richard Gesick.
Programs and Classes A program is made up from classes
Session 2: Introduction to Object Oriented Programming
Introduction to Data Structure
Java Programming Language
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

Introduction to Java, OO and IDEs ICW Lecture 2 Errol Thompson Room 134

Write down answers to the following questions What is a computer program? What is an object-oriented program?

What is a computer program? Any program  Instructions to a computer  Data plus algorithm  Takes in input carries out a process and generates output  May be divided into smaller chunks (i.e. functions and modules) An object-oriented program  Made up of entities called objects  An object has  state (data or attributes or fields, relationships) and  behaviour (functions, methods)  An OO program achieves things through interactions between objects  One object calls another (passes a message)  Java supports object-oriented programming

How do we define the characteristics of an object? In your program, you define “Classes”. You use “Classes” to create “Objects”. You retain references to “Objects” You call “Methods” to perform computation. You use “Methods” to manipulate data held in “Fields” within an Object.

What does this class do? class Something { public Something() { value = 0} private int value; public void inc () { value = value +1; } public int getValue () { return Value; } What would be a brief description for the behaviour of this class What is a better name for this class What fields and values are accessible to users of objects created from this class? What is the initial value of the field?

Object use public void testInc() { System.out.println("inc"); Counter instance = new Counter(); instance.inc(); int expResult = ?; int result = instance.getValue(); assertEquals(expResult, result); instance = null; } Write a short piece of Java code that uses the Counter class from the previous slide. Your code should use the object so that the resulting value retrieved from the object is equal to 1.

Objects and Methods Always think about running methods on objects. e.g. given Number objects “x” and “y” x.add(y) is more OO than x = add(x, y) Why write methods against objects? How do you decide which class should contain a method?

Object Interaction You Person 1 Directory Service Person 2 Person 3 Which objects can interact? For an object to call a method on another it must have knowledge of that object (i.e. a reference)

Static Methods. But not all methods in Java are called on objects,... what’s going on here? Some times methods are required that don’t run against a specific object. Initial program method (“main”) Factory methods Methods that are not object specific Any methods or fields that are not related to a specific object are declared as “Static”. They are class methods or fields

Static A static field is one that is the same for all objects. E.g. static pi. A static method is one that is the same for all objects. Static methods can’t refer to none static fields. Why? Static methods don’t need to be called on a particular objects. (Classname.method())

The main method If we just have objects and methods that run on objects how do we start our program? A class may have a special static “main” method. This method is run when the program is started.

Types Java is a statically typed language – this means All fields are declared with a type All methods have a return type (void means a method returns nothing) The type determines the values that can be assigned to a field or returned by a method, and the operations that can be performed on it. Where the type is a class name then the field will hold a reference to objects created from that class or one of its subclasses.

Primative Types Provided as part of the language byte, short, int, long, float, double, boolean, char Can not be used where a class is required. 13Interenet Computing Workship

Programming Problem The user has entered a set of data. It is to be held in a collection that 1.Enables the user to retrieve the items as a sorted collection 2.Enables the user to retrieve all unique items What classes in Java could we use as the base for this exercise and how can we develop our own class so that it reuses the existing Java class?

Conclusion Hand out photo copy of exerises. Make sure you can do these. If you can’t then come and talk to me about switching to the conversion M.Sc.

Next Time: Crypto Next week we will look at the Java Crypto API. This libarary lets you encrypt, decrypt, hash, handle keys,... And you will be given the first exerice worth 20% of your total mark.