TCU CoSc 10403 Introduction to Programming (with Java) Getting to Know Java.

Slides:



Advertisements
Similar presentations
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Advertisements

OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
Inheritance Inheritance Reserved word protected Reserved word super
ECE122 L4: Creating Objects February 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 4 Creating and Using Objects.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Object-Oriented Programming Chapter Two. Java Buzz Words Simple Architecture neutral Object oriented Portable Distributed High performance Interpreted.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Chapter Chapter 1 Introduction to Object-Oriented Programming and Software Development.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Object Oriented Software Development
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Introduction to Object-oriented programming and software development Lecture 1.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Chapter 8 More Object Concepts
An Object-Oriented Approach to Programming Logic and Design
Chapter 2: Objects and Primitive Data Classes and Objects String, Random, Math, NumberFormat, DecimalFormat and Wrapper Classes.
Java Language and SW Dev’t
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
The Java Programming Language
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Java Software Solutions Lewis and Loftus Chapter 4 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects and Classes -- Introduction.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
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.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Working With Objects Tonga Institute of Higher Education.
M1G Introduction to Programming 2 5. Completing the program.
Java Software Solutions Lewis and Loftus Chapter 9 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Enhanced Class Design -- Introduction.
Introduction to Object-Oriented Programming Lesson 2.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
© 2004 Pearson Addison-Wesley. All rights reserved January 23, 2006 Creating Objects & String Class ComS 207: Programming I (in Java) Iowa State University,
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
1 n Object Oriented Programming. 2 Introduction n procedure-oriented programming consists of writing a list of instructions and organizing these instructions.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
© 2004 Pearson Addison-Wesley. All rights reserved3-1 Objects Declaration: String title;  title (object variable) of type String( Class )  title is just.
Lecture 1 Introduction Richard Gesick.
Introduction to.
Java Primer 1: Types, Classes and Operators
About the Presentations
Creating Objects & String Class
Fundamentals of Programming
Packages & Random and Math Classes
Abstract Classes and Interfaces
CPS120: Introduction to Computer Science
Presentation transcript:

TCU CoSc Introduction to Programming (with Java) Getting to Know Java

Problem Solving The purpose of writing a program is to solve a problem. Problem solving consists of multiple steps:  Understanding the problem.  Breaking the problem into manageable pieces.  Designing a solution.  Implementing the solution.  Testing the solution and fixing any problems that exist.

The Java Programming Language A programming language defines a set of rules: –That determine exactly how a programmer can combine words and symbols of the language into programming statements. Programming statements are the instructions that are carried out when the program is executed. –Java is an object-oriented programming language (more about that later). Java is one of the fastest growing programming technologies of all time.

Reasons Why Java is Popular Java is the first programming language to deliberately embrace the concept of writing programs that can be executed on the Web. Moreso, Java is a useful general purpose programming language. The Java language is accompanied by a library of extra software that we can use when developing programs. –The library provides the ability to create graphics, communicate over networks, and interact with databases. –The set of supporting libraries is huge and versatile.

I’ve been telling you that Java is an Object Oriented Programming Language - what exactly does that mean? To understand - we need to discuss and understand what an Object is and how it relates to a Class!!

Anatomy of a Java class A class is a description of a template (or pattern) that specifies the types of data values that an instance of the class can hold and the operations that it can perform. In OOP, rather than describe each and every object, the programmer describes the general type of an object (a class) and then uses the class to create (or instantiate) as many of the objects as are needed. Example: a class describing”generic” students at TCU. Instance variables - the data that is maintained for students (ex., name, address, age, …) Constructors - methods that are involved in the construction of an instance of a class. Methods - subprograms that permit instance variables to be accessed and modified (ex., setName(), setMajor(), getAge(), setAge(), … )

Example: consider a banking problem Bank Account A class (the concept) John’s Bank Account Balance: $5,257 An object (the realization) Bill’s Bank Account Balance: $1,245,069 Mary’s Bank Account Balance: $16,833 Multiple objects from the same class

Let’s discuss these concepts further!! A class -- the basic building block of an object-oriented language. It is a template/pattern that describes the data and behavior associated with instances of that class. When you instantiate a class you create an object that looks and feels like other instances of the same class. –The data associated with a class or object is stored in instance variables; –the behavior associated with a class or object is implemented with methods. Methods are similar to the functions or procedures in other procedural languages. **Some author wrote: Julia Child's recipe for rack of lamb is a real-world example of a class. Her rendition of the rack of lamb is one instance of the recipe, and mine is quite another. (While both racks of lamb may "look and feel" the same, I imagine that they "smell and taste" different.)

Constructors A constructor: – is a special method that is used to set up a newly created object – often sets the initial values of variables (i.e., it can be passed information that can be used to initialize some variables in the object) – has the same name as the class –does not return a value – has no return type, not even void The programmer does not have to define a constructor for a class (there is a default constructor for every class – its syntax is: theNameOfTheclass() For example, a class named Student could have a constructor that receives a parameter specifying the Student’s name: Student tommy = new Student(“Tom Jones”);

Inheritance Classes are defined in a hierarchy A class can extend (inherit from) some other class Object => Component => Container => Panel => Applet Thus, an Applet can do everything that Panel does and some other things. A Panel can do everything a Container can do, etc… Advantage –Easy to extend or specialize something that already exists. Note: we take advantage of this when we write: public class HelloWorld extends Applet { … } Disadvantage –Sometimes difficult to find everything that a class does; you may have to look up the tree.

Inheritance One class can be used to derive another via inheritance. A class can extend (inherit from) some other class Administrator class(extends Person) Faculty class(extends Person)Student class (extends Person) Person class (called a superclass) Subclasses or “derived” classes - may have more than just 2 levels.

Java Components Package (what the import statement brings in!!) –collection of related classes Class –description of an object (template) –variables + methods Variable – name for memory location for a data item Method – specifies an action on an object –retrieve/return info or change info Object –instance of a class –created by the “new” operator Java program = collection of cooperating objects

Creating Objects The new operator creates a new object from a class: Example: Person jackSmith = new Person (); Person sallyJones = new Person(); This declaration asserts that jackSmith and sallyJones are variables that refer to objects created from the Person class. They are initialized (set to point) to the objects created by the new operator The newly created object is actually created and allocated to memory by a call to a very special method contained within the class - a constructor of the class. Instance of the Person class containing a copy of all instance variables and all methods jackSmith Instance of the Person class containing a copy of all instance variables and all methods sallyJones

Choosing Identifier Names Identifier names should be descriptive. Avoid meaningless names such as a or x. Unless the name is actually descriptive, such as using x and y to represent (x, y) coordinates. –Avoid using unnecessarily long names (unless they promote better readability - example: yearToDateSalary). A “name” in Java is a series of identifiers separate by the dot (period) character. –The name System.out is the ‘name’ of an object through which we invoke the println method. (println is a method inside the object.)