Week 3 Recap CSE 115 – Fall 2006. Java Source Code File Made up of: Package declaration Class definition.

Slides:



Advertisements
Similar presentations
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Advertisements

Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
IT151: Introduction to Programming
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Chapter 1: Introduction
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Summary of the lecture We discussed –variable scope –instance variable declarations –variable lifetime.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Lecture #5 Agenda Cell phones off & name signs out Review Questions? UML class diagram introduction Our first class definition!
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
1 Composition A whole-part relationship (e.g. Dog-Tail) Whole and part objects have same lifetime –Whole creates instance of part in its constructor In.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
Java Keywords CSE 115 Spring Purpose This set of slides contains a running list of the keywords that we have talked about so far this semester and.
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
Where do objects come from? Objects are instances of classes We instantiate classes: –e.g.new chapter1.Terrarium() –There are three parts to this expression:
Week 2 Recap CSE 115 – Spring Object Oriented Program System of objects that communicate with one another to solve some problem.
Week 6 Recap CSE 115 Spring Review We have built a program that uses Association, Composition, Instantiation Dependency, Local Instance Dependency,
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Week 4 Recap CSE 115 Fall 2006 Section C. Decoupling Separation of concerns Defining what an object can do, not how it does it.
Java Syntax, Java Conventions, CSE 115 Conventions (Part 2) CSE 115 Spring 2006 January 30, February 1 & 3, 2006.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Week 5 Recap CSE 115 Spring Composition Informally called “has a” Represented in UML with a diamond- headed arc In code: Declare an instance variable.
CSE 115 Week 3 January 28 – February 1, Monday Announcements Software Installation Fest: 2/5 and 2/6 4pm – 7pm in Baldy 21 Software Installation.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
Week 3 Recap CSE 115 – Spring Constructor Special capability of a class that sets up the initial state of the object. Constructor definitions are.
UML class diagrams (1) UML = Unified Modeling Language We use only class diagrams, not other UML diagrams Purpose: –keep OO concepts separate from implementation.
© 2006 Pearson Education Making Objects 1 of 19 MAKING OBJECTS Views of a Class Defining Your Own Class Declaring Instance Variables Declaring Methods.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Composition details Recall, composition involves 3 things: –Declaration of instance variable of.
CSE 115 Week 2 January , Wednesday Announcements Pick up Syllabus if you need one Pick up Syllabus if you need one Recitation Change Form.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
ITEC 320 Lecture 16 Packages (1). Review Questions? –HW –Exam Nested records –Benefits –Downsides.
Comments are for people Header comments supply basic information about the artifact.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
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.
The Java Programming Language
CET203 SOFTWARE DEVELOPMENT Session 1A Revision of Classes.
Introduction to programming in the Java programming language.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
February 2 - 6,  2/4: Go over review sheet for Exam 1  2/6: Exam 1 & Lab 1 due  2/9: Go over Exam 1  2/11: Makeup exam for Exam 1.
ITEC 320 Lecture 9 Nested records / Packages. Review Project ?’s Records Exam 1 next Friday.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Class Fundamentals BCIS 3680 Enterprise Programming.
TK1924 Program Design & Problem Solving Session 2011/2012
3 Introduction to Classes and Objects.
Yanal Alahmad Java Workshop Yanal Alahmad
University of Central Florida COP 3330 Object Oriented Programming
Chapter 4 Procedural Methods.
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 7 Procedural Methods.
Put the dots on the shift keys.
Notes from Week 5 CSE 115 Spring 2006 February 13, 15 & 17, 2006.
Object Oriented Programming in java
Java objects: a first view
February , 2009 CSE 113 B.
February 2 - 6, 2009 CSE 113 B.
Presentation transcript:

Week 3 Recap CSE 115 – Fall 2006

Java Source Code File Made up of: Package declaration Class definition

Class Definition Made up of: Class Header Class Body Class Body is made up of: Definitions of properties Definitions of capabilities

Package Declaration package identifier ; package is a keyword in Java – a word that has a special meaning identifier represents a name. Here we are identifying a package by name.

Identifiers Programmers can pick out identifiers if we follow these rules. Identifiers must begin with a letter or underscore Followed by zero or more letters, digits, or underscores No special characters allowed in an identifier Keywords are not allowed to be identifiers

Identifiers (Style) Rules are enforced by compiler. Style enforced by community (i.e. your grade) Style for identifiers for packages is that the first letter of a package name is lower-case, all other letters are lower-case, and we do not see underscores in package names.

Packages Way to organize our classes so that like classes are grouped together. Putting a class in a package forces you to put those classes in the same directory on the system.

Nested Packages You can put a package inside of another package. This is indicated by using the dot (period) in between package names. On the system, nested packages are directories inside other directories. If you are using something outside of your current package, you must give the fully-qualified package name.

Class Header public class identifier public is a keyword that is an access control modifier. It tells who has access to something. If public, everyone has access. class is another keyword that indicates we are about to start the definition of a class. The identifier here represents the name of the class.

Names of Classes Must follow rules of identifiers. Style: First letter upper-case, rest lower-case. If more than one word, capitalize each new word. No underscores in class names. Whatever you name the class is whatever you will name the file the class is defined in.

Class Body Starts with a { Ends with a }

Constructor Special capability of a class that sets up the initial state of the object. Constructor definitions are made up of: Constructor Header Constructor Body Starts with { and ends with }

Constructor Header Public identifier () public means as it did before. The identifier here is the name of the constructor. Java imposes that the name of a constructor is the same as the name of the class. () are called parameter list

Creating an object The syntax to create an object is: new ConstructorName(); new is a keyword that indicates that you will create a new instance of the class whose constructor is named after the keyword.

Instantiation Dependency Relationship Informally called “uses a” Represented in UML diagrams as a dotted arrow In code, if ClassA “uses a” ClassB: public class ClassA { public ClassA() { new ClassB(); }

Relationships Between Classes You should recognize the formal name, the informal name, the UML relationship arc, and the way the relationship looks in code.