ICOM4015-lec02-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Classes and Objects Advanced Programming ICOM 4015 Lecture 2 Reading: Java Concepts Chapter 2 Fall 2006 Slides adapted fom Java Concepts companion slides 1 Lecture Goals To learn about variables To understand the concepts of classes and objects To be able to call methods To be able to browse the API documentation To realize the difference between objects and object references Fall 2006 Slides adapted fom Java Concepts companion slides 2 Types and Variables Every value has a type Variable declaration examples: String greeting = "Hello, World!"; PrintStream printer = System.out; int luckyNumber = 13; Variables Store values Can be used in place of the objects they store Fall 2006 Slides adapted fom Java Concepts companion slides 3 Syntax 2.1: Variable Definition typeName variableName = value; or typeName variableName; Example: String greeting = "Hello, Dave!"; Purpose: To define a new variable of a particular type and optionally supply an initial value Fall 2006 Sl ...
|
|
ICOM4015-lec05-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Decisions Advanced Programming ICOM 4015 Lecture 5 Reading: Java Concepts Chapter 6 Fall 2006 Slides adapted from Java Concepts companion slides 1 Lecture Goals To be able to implement decisions using if statements To understand how to group statements into blocks To learn how to compare integers, floatingpoint numbers, strings, and objects To recognize the correct ordering of decisions in multiple branches To program conditions using Boolean operators Slides adapted from Java Concepts companion slides and variables Fall 2006 2 The if Statement The if statement lets a program carry out different actions depending on a condition if (amount <= balance) balance = balance - amount; Fall 2006 Slides adapted from Java Concepts companion slides Continued. 3 The if Statement Figure 1: Fall 2006 Slides adapted from Flowchart for an if statement Java Concepts companion slides 4 The if/else Statement if (amount <= balance) balance = balance - amount; else balance = balance - OVERDRAFT_PENALTY; ...
|
|
ICOM4015-lec05-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Decisions Advanced Programming ICOM 4015 Lecture 5 Reading: Java Concepts Chapter 6 Fall 2006 Slides adapted from Java Concepts companion slides 1 Lecture Goals To be able to implement decisions using if statements To understand how to group statements into blocks To learn how to compare integers, floatingpoint numbers, strings, and objects To recognize the correct ordering of decisions in multiple branches To program conditions using Boolean operatorsSlides adapted from Java Concepts companion slides and variables Fall 2006 2 The if Statement The if statement lets a program carry out different actions depending on a condition if (amount <= balance) balance = balance - amount; Fall 2006 Slides adapted from Java Concepts companion slides Continued. 3 The if Statement Figure 1: Fall 2006 Slides adapted from Flowchart for an if statement Java Concepts companion slides 4 The if/else Statement if (amount <= balance) balance = balance - amount; else balance = balance - OVERDRAFT_PENALTY; ...
|
|
ICOM4015-lec11-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package access control To understand the common superclass Object and to override its toString and equals methods Fall 2006 Adapted from Java Concepts Companion Slides 2 An Introduction to Inheritance Inheritance: extend classes by adding methods and fields Example: Savings account = bank account with interest class SavingsAccount extends BankAccount { new methods new instance fields } Fall 2006 Adapted from Java Concepts Companion Slides Continued 3 An Introduction to Inheritance SavingsAccount automatically inherits all methods and instance fields of BankAccount SavingsAccount collegeFund = new SavingsAccount(10); / Savings account with 10% inte ...
|
|
ICOM4015-lec11-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Inheritance Advanced Programming ICOM 4015 Lecture 11 Reading: Java Concepts Chapter 13 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package access control To understand the common superclass Object and to override its toString and equals methods Fall 2006 Adapted from Java Concepts Companion Slides 2 An Introduction to Inheritance Inheritance: extend classes by adding methods and fields Example: Savings account = bank account with interest class SavingsAccount extends BankAccount { new methods new instance fields } Fall 2006 Adapted from Java Concepts Companion Slides Continued. 3 An Introduction to Inheritance SavingsAccount automatically inherits all methods and instance fields of BankAccount SavingsAccount collegeFund = new SavingsAccount(10); / Savings account with 10% interest collegeFund ...
|
|
ICOM4015-lec07-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Arrays and Array Lists Advanced Programming ICOM 4015 Lecture 7 Reading: Java Concepts Chapter 8 Fall 2006 Slides adapted from Java Concepts companion slides 1 Lecture Goals To become familiar with using arrays and array lists To learn about wrapper classes, auto-boxing and the generalized for loop To study common array algorithms To learn how to use two-dimensional arrays To understand when to choose array lists and arrays in your programs To implement partially filled arrays Fall 2006 Slides adapted from Java Concepts companion slides 2 Arrays Array: Sequence of values of the same type Construct array: new double[10] Store in variable of type double[ ] double[] data = new double[10]; Continued Fall 2006 Slides adapted from Java Concepts companion slides 3 Arrays When array is created, all values are initialized depending on array type: Numbers: 0 Boolean: false Object References: null Fall 2006 Slides adapted from Java Concepts companion slides 4 Ar ...
|
|
ICOM4015-lec10-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Interfaces and Polymorphism Advanced Programming ICOM 4015 Lecture 10 Reading: Java Concepts Chapter 11 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn about interfaces To be able to convert between class and interface references To understand the concept of polymorphism To appreciate how interfaces can be used to decouple classes Continued Fall 2006 Adapted from Java Concepts Companion Slides 2 Chapter Goals To learn how to implement helper classes as inner classes To understand how inner classes access variables from the surrounding scope To implement event listeners for timer events Fall 2006 Adapted from Java Concepts Companion Slides 3 Using Interfaces for Code Reuse Use interface types to make code more reusable In Chap. 7, we created a DataSet to find the average and maximum of a set of values (numbers) What if we want to find the average and maximum of a set of BankAccount values? Continued Fall 2006 Adapted from ...
|
|
ICOM4015-lec01-f08
UPR Mayagüez, ICOM 4015
Excerpt: ... Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1 Fall 2008 Slides adapted from Java Concepts companion slides 1 Lecture Goals To understand the activity of programming To learn about machine code and high level programming languages To become familiar with your computing environment and your compiler To compile and run your first Java program To recognize syntax and logic errors Fall 2008 Slides adapted from Java Concepts companion slides 2 What Is Programming? Computers are programmed to perform tasks Different tasks = different programs Program Sequence of basic operations executed in succession Contains instruction sequences for all tasks it can execute Sophisticated programs require teams of highly skilled programmers and other professionals Fall 2008 Slides adapted from Java Concepts companion slides 3 What are Computers Good for? Can store large amount of data Instructions to be executed (programs) ...
|
|
ICOM4015-lec01-f08
UPR Mayagüez, ICOM 4015
Excerpt: ... Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1 Fall 2008 Slides adapted from Java Concepts companion slides 1 Lecture Goals To understand the activity of programming To learn about machine code and high level programming languages To become familiar with your computing environment and your compiler To compile and run your first Java program To recognize syntax and logic errors Fall 2008 Slides adapted from Java Concepts companion slides 2 What Is Programming? Computers are programmed to perform tasks Different tasks = different programs Program Sequence of basic operations executed in succession Contains instruction sequences for all tasks it can execute Sophisticated programs require teams of highly skilled programmers and other professionals Fall 2008 Slides adapted from Java Concepts companion slides 3 What are Computers Good for? Can store large amount of data Instructions to be executed (programs) Data to operate with Can execu ...
|
|
ICOM4015-lec01-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1 Fall 2006 Slides adapted from Java Concepts companion slides 1 Lecture Goals To understand the activity of programming To learn about machine code and high level programming languages To become familiar with your computing environment and your compiler To compile and run your first Java program To recognize syntax and logic errors Fall 2006 Slides adapted from Java Concepts companion slides 2 What Is Programming? Computers are programmed to perform tasks Different tasks = different programs Program Sequence of basic operations executed in succession Contains instruction sequences for all tasks it can execute Sophisticated programs require teams of highly skilled programmers and other Fall 2006 Slides adapted from Java Concepts companion slides professionals 3 Important Characteristics of a Computer Can store large amount of data Instructions to be executed (programs) Data to ...
|
|
ICOM4015-lec04-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Fundamental Data Types Advanced Programming ICOM 4015 Lecture 4 Reading: Java Concepts Chapter 4 Fall 2006 Slides adapted from Java Concepts companion slides 1 Lecture Goals To understand integer and floating-point numbers To recognize the limitations of the numeric types To become aware of causes for overflow and roundoff errors To understand the proper use of constants Continued Fall 2006 Slides adapted from Java Concepts companion slides 2 Lecture Goals To write arithmetic expressions in Java To use the String type to define and manipulate character strings To learn how to read program input and produce formatted output Fall 2006 Slides adapted from Java Concepts companion slides 3 Number Types int: integers, no fractional part 1, -4, 0 double: floating-point numbers (double precision) 0.5, -3.11111, 4.3E24, 1E-14 Fall 2006 Slides adapted from Java Concepts companion slides 4 Number Types A numeric computation overflows if the result falls outsid ...
|
|
ICOM4015-lec04-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Fundamental Data Types Advanced Programming ICOM 4015 Lecture 4 Reading: Java Concepts Chapter 4 Fall 2006 Slides adapted from Java Concepts companion slides 1 Lecture Goals To understand integer and floating-point numbers To recognize the limitations of the numeric types To become aware of causes for overflow and roundoff errors To understand the proper use of constants Continued. Fall 2006 Slides adapted from Java Concepts companion slides 2 Lecture Goals To write arithmetic expressions in Java To use the String type to define and manipulate character strings To learn how to read program input and produce formatted output Fall 2006 Slides adapted from Java Concepts companion slides 3 Number Types int: integers, no fractional part 1, -4, 0 double: floating-point numbers (double precision) 0.5, -3.11111, 4.3E24, 1E-14 Fall 2006 Slides adapted from Java Concepts companion slides 4 Number Types A numeric computation overflows if the result falls outside the range for the ...
|
|
ICOM4015-lec08-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Designing Classes Advanced Programming ICOM 4015 Lecture 8 Reading: Java Concepts Chapter 8 Fall 2006 Adapded from Java Concepts Slides 1 Chapter Goals To learn how to choose appropriate classes to implement To understand the concepts of cohesion and coupling To minimize the use of side effects To document the responsibilities of methods and their callers with preconditions and postconditions Fall 2006 Adapded from Java Concepts Slides Continued. 2 Chapter Goals To understand the difference between instance methods and static methods To introduce the concept of static fields To understand the scope rules for local variables and instance fields To learn about packages Fall 2006 Adapded from Java Concepts Slides 3 Choosing Classes A class represents a single concept from the problem domain Name for a class should be a noun that describes concept Concepts from mathematics: Point Rectangle Ellipse Concepts from real life Fall 2006 Adapded BankAccount from Java Concepts Slid ...
|
|
ICOM4015-lec08-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Designing Classes Advanced Programming ICOM 4015 Lecture 8 Reading: Java Concepts Chapter 8 Fall 2006 Adapded from Java Concepts Slides 1 Chapter Goals To learn how to choose appropriate classes to implement To understand the concepts of cohesion and coupling To minimize the use of side effects To document the responsibilities of methods and their callers with preconditions and postconditions Fall 2006 Adapded from Java Concepts Slides Continued 2 Chapter Goals To understand the difference between instance methods and static methods To introduce the concept of static fields To understand the scope rules for local variables and instance fields To learn about packages Fall 2006 Adapded from Java Concepts Slides 3 Choosing Classes A class represents a single concept from the problem domain Name for a class should be a noun that describes concept Concepts from mathematics: Point Rectangle Ellipse Concepts from real life Fall 2006 BankAccountAdapde ...
|
|
ICOM4015-lec03-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Implementing Classes Advanced Programming ICOM 4015 Lecture 3 Reading: Java Concepts Chapter 3 Fall 2006 Slides adapted from Java Concepts companion slides 1 Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand the purpose and use of constructors To understand how to access instance fields and local variables To appreciate the importance of documentation comments Fall 2006 Slides adapted from Java Concepts companion slides 2 Black Boxes A black box magically does its thing Hides its inner workings Encapsulation: the hiding of unimportant details What is the right concept for each particular black box? Continued Fall 2006 Slides adapted from Java Concepts companion slides 3 Black Boxes Concepts are discovered through abstraction Abstraction: taking away inessential features, until only the essence of the concept remains In object-oriented programming the black boxes from which a p ...
|
|
ICOM4015-lec03-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Implementing Classes Advanced Programming ICOM 4015 Lecture 3 Reading: Java Concepts Chapter 3 Fall 2006 Slides adapted from Java Concepts companion slides 1 Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand the purpose and use of constructors To understand how to access instance fields and local variables To appreciate the importance of documentation comments Fall 2006 Slides adapted from Java Concepts companion slides 2 Black Boxes A black box magically does its thing Hides its inner workings Encapsulation: the hiding of unimportant details What is the right concept for each particular black box? Continued. Fall 2006 Slides adapted from Java Concepts companion slides 3 Black Boxes Concepts are discovered through abstraction Abstraction: taking away inessential features, until only the essence of the concept remains In object-oriented programming the black boxes from which a program is manufactured a ...
|
|
ICOM4015-lec17-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... An Introduction to Data Structures Advanced Programming ICOM 4015 Lecture 17 Reading: Java Concepts Chapter 20 Fall 2006 Adapded from Java Concepts Companion Slides 1 Chapter Goals To learn how to use the linked lists provided in the standard library To be able to use iterators to traverse linked lists To understand the implementation of linked lists To distinguish between abstract and concrete data types Fall 2006 Adapded from Java Concepts Companion Slides Continued 2 Chapter Goals To know the efficiency of fundamental operations of lists and arrays To become familiar with the stack and queue types Fall 2006 Adapded from Java Concepts Companion Slides 3 Using Linked Lists A linked list consists of a number of nodes, each of which has a reference to the next node Adding and removing elements in the middle of a linked list is efficient Visiting the elements of a linked list in sequential order is efficient Random access is not efficient Fall 2006 Adapded fr ...
|
|
ICOM4015-lec17-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... An Introduction to Data Structures Advanced Programming ICOM 4015 Lecture 17 Reading: Java Concepts Chapter 20 Fall 2006 Adapded from Java Concepts Companion Slides 1 Chapter Goals To learn how to use the linked lists provided in the standard library To be able to use iterators to traverse linked lists To understand the implementation of linked lists To distinguish between abstract and concrete data types Fall 2006 Adapded from Java Concepts Companion Slides Continued 2 Chapter Goals To know the efficiency of fundamental operations of lists and arrays To become familiar with the stack and queue types Fall 2006 Adapded from Java Concepts Companion Slides 3 Using Linked Lists A linked list consists of a number of nodes, each of which has a reference to the next node Adding and removing elements in the middle of a linked list is efficient Visiting the elements of a linked list in sequential order is efficient Random access is not efficient Fall 2006 Adapded from Java Concepts Compan ...
|
|
ICOM4015-lec09-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Testing and Debugging Advanced Programming ICOM 4015 Lecture 9 Reading: Java Concepts Chapter 10 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn how to carry out unit tests To understand the principles of test case selection and evaluation To learn how to use logging To become familiar with using a debugger To learn strategies for effective debugging Fall 2006 Adapted from Java Concepts Companion Slides 2 Unit Tests The single most important testing tool Checks a single method or a set of cooperating methods You don't test the complete program that you are developing; you test the classes in isolation For each test, you provide a simple class called a test harness Test harness feeds parameters to the Fall 2006 Adapted from Java Concepts methods being tested Companion Slides 3 Example: Setting Up Test Harnesses To compute the square root of a use a common algorithm: 1. Guess a value x that might be somewhat close to the desi ...
|
|
ICOM4015-lec15-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Exception Handling Advanced Programming ICOM 4015 Lecture 15 Reading: Java Concepts Chapter 15 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn how to throw exceptions To be able to design your own exception classes To understand the difference between checked and unchecked exceptions To learn how to catch exceptions To know when and where to catch an exception Fall 2006 Adapted from Java Concepts Companion Slides 2 Error Handling Traditional approach: Method returns error code Problem: Forget to check for error code Failure notification may go undetected Problem: Calling method may not be able to do anything about failure Program must fail too and let its caller worry about it Many method calls would need to be checked Continued Fall 2006 Adapted from Java Concepts Companion Slides 3 Error Handling Instead of programming for success x.doSomething() you would always be programming for failure: if (!x.doSomething() return false; Fal ...
|
|
ICOM4015-lec15-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Exception Handling Advanced Programming ICOM 4015 Lecture 15 Reading: Java Concepts Chapter 15 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To learn how to throw exceptions To be able to design your own exception classes To understand the difference between checked and unchecked exceptions To learn how to catch exceptions To know when and where to catch an exception Fall 2006 Adapted from Java Concepts Companion Slides 2 Error Handling Traditional approach: Method returns error code Problem: Forget to check for error code Failure notification may go undetected Problem: Calling method may not be able to do anything about failure Program must fail too and let its caller worry about it Many method calls would need to be checked Continued. Fall 2006 Adapted from Java Concepts Companion Slides 3 Error Handling Instead of programming for success x.doSomething() you would always be programming for failure: if (!x.doSomething() return false; Fall 2006 Adapte ...
|
|
comments
Washington, TCSS 143
Excerpt: ... <h3>Homework 0: Sieve of Eratosthenes (Review of Java Concepts )</h3> ...
|
|
ICOM4015-lec13-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Event Handling Advanced Programming ICOM 4015 Lecture 13 Reading: Java Concepts Chapter 12 Fall 2006 Adapded from Java Concepts Companion Slides 1 Chapter Goals To understand the Java event model To install action and mouse event listeners To accept input from buttons, text fields, and the mouse Fall 2006 Adapded from Java Concepts Companion Slides 2 Events, Event Sources, and Event Listeners User interface events include key presses, mouse moves, button clicks, and so on Most programs don't want to be flooded by boring events A program can indicate that it only cares about certain specific events Fall 2006 Adapded from Java Concepts Companion Slides Continued. 3 Events, Event Sources, and Event Listeners Event listener: Notified when event happens Belongs to a class that is provided by the application programmer Its methods describe the actions to be taken when an event occurs A program indicates which events it needs to receive by installing event listener objects Event sou ...
|
|
ICOM4015-lec14-f06
UPR Mayagüez, ICOM 4015
Excerpt: ... Programming Graphics Advanced Programming ICOM 4015 Lecture 14 Reading: Java Concepts Chapter 5 Fall 2006 Adapted from Java Concepts Companion Slides 1 Chapter Goals To be able to write simple applications To display graphical shapes such as lines and ellipses To use colors To display drawings consisting of many shapes To read input from a dialog box To develop test cases that validate the Fall 2006 Adapted from Java Concepts Companion Slides correctness of your programs 2 Frame Windows The JFrame class JFrame frame = new JFrame(); frame.setSize(300, 400); frame.setTitle("An Empty Frame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); import javax.swing.*; Fall 2006 Adapted from Java Concepts Companion Slides 3 A Frame Window Figure 1: A Frame Window Fall 2006 Adapted from Java Concepts Companion Slides 4 File EmptyFrameViewer.java 01: import javax.swing.*; 02: 03: public class EmptyFrameViewer 04: { 05: public static void main ...
|