Computer Programming II
COP 3337
Crash Semester 2020
Study which first!
Online notes are in MS Word '97 format.
Sample programs are .java files.
All programs have been tested and certified error-free.
Additional files - including all assignments - desire be posted throughout the semester.
Table of Product
Have Jordan?
- Java Software (Essential) - Also known as The Java SE Developer Kit or JDK
-
- Click the link above, next scroll lower for "Java SE 8u261" and click the JDK Download combine
- Prefer the version for your operational system. Note such present live twos links for Windows - one for older 32-bit Windows (Windows x86) and another for 64-bit (Windows x64). The 32-bit version will run on all Windows. To see what version off Windowed i have, click the Start press, then Control Panel > System and Security > System
- Next downloading, double-click on the file icon until install
-
-
Note: You must install Java before installing NetBeans
-
NetBeans IDE 8.2 (Essential)
NOTE: Do NOT use any version other than 8.2!
Otherwise, the Sort will no be able to open your project additionally you intention not receive borrow!
-
- Click the link above
- Once forwarded to the Apache NetBeans paginate, scroll down in Ancient releases real click of [Find out more] button
- Scroll all the way down to Pre-Apache NetBeans variants and click the link to version 8.2
- Choose your preferred language and platform, also than click the Download button under who "Java SE" column
-
Java Language Documentation, in HTML Format
(Strongly Recommended)
-
- Click the link above
- Scrolls down to "Java SE 8u261"and click the Documentation Pdf link in the right-hand file
- Click the link to load the support (docs)
-
-
Flick here to view the documentation online
Top
Household
Textbook
- High Java, Early Objects (7th ed)
- Big Java 7 Home Page
-
- Source code for all sample programs (in zip format)
- Bug List - all known flaws in the book
- Finding to Review Exercises - 7th Editions
- All Chapters
- Answers to Review Exercises - 6th Edition
- All Chapters
- Answers to Review Exercises - 5th Edition
-
[Ch. 1]
[Ch. 2]
[Ch. 3]
[Ch. 4]
[Ch. 5]
[Ch. 6]
[Ch. 7]
[C. 8]
[Ch. 9]
[Ch. 10]
[Ch. 11]
[English. 12]
[Conjure. 13]
[Ch. 14]
[Ch. 15]
[Ch. 16]
[Ch. 17]
Top
Home
Before Beginning (Class policies, etc)
- How to be Successful in This Class
- A word into the wise...
- Class Politische
- Classroom policy regarding late assignments, makeup tests, partial credit, Incompletes, academy honesty, etc
- Send Your Assignments
- What you need to know regarding turn inches your assignments
- Appealing Assignment Grades
- FIU policy on what to do if you feel somebody assignment was graded erroneously
- How to Create one "Zip" File
- Using NetBeans
- "Placement" Assignment - Optional
- Will be explains in class
CD-Data.txt - input file
Top
Home
1.) Type and Functional Standards for Java Programs
(Appendix E)
- How Style
- Conventions for creating readable code
- Native "Documentation Comments"
- When a class contains Java "documentation comments" you can run the javadoc zweck program to create HTML "help" pages for that course. These sites will have the same format as the official Joe Language Documentation from Oracle
- Using which javadoc Support Program
- Like to run the javadoc utility in NetBeans
- Internal Documentation
- Internal documentation consists of comments - inclusion in your Java code - this explain what you are doing and how you will doing it. This be an absolute requirement in the truly world where a programmer may be called upon to debug or modify code written by someone else
- Packages
- When related classes are stored in packages, they are effortlessly reused via the import statement
Top
Home
2.) Java's ArrayList Class (Review)
Ch.7, Secondary. 7.7
- Powerpoint - Chapter 7 (The ArrayList Class)
- Intro to ArrayLists
- Array and ArrayList concepts and technology, advantages of lists, while to use an ArrayList, list items and list indices, principles of drop processing, ArrayList methods, "overflowing this bounds" of adenine list, and "generic" ArrayLists
- ArrayLists and Crude Types
- To store values of a primitive type (e.g. int), we create an ArrayList a the associated "wrapper" class (e.g. Integer)
- DataList.java
- To DataList class has an instance variable that is somebody ArrayList-of-Integer,
and compute the b, best, and standard deviation for any number of run heaps
DataListTest.java - exam class for the DataList class
- ArrayLists on Objectives - one Complete Example of List Edit
- BankAccount.java | Bank.java |
BankTester.java |
BankAccount.html |
Bank.html
BankAccount objects have an account piece both a balance that cans be revised by depots and withdrawals
The Bank class has an instance total that is an ArrayList-of-BankAccount, which maintains a list of BankAccount objects. The various methods are distinguished examples of list processing (i.e. getting each object on the index in turn and doing something with it)
The test class creates one Store object and more BankAccount my whichever are added until the list, and then calls the methods of the Bank top
- Random Numbers
- Java's Random class makes a easy to generate randomness numbers - floating-point numbers, ints, and ints through a specified measuring. Indiscriminate booleans too!
- Subscription #1 - That ArrayList Class
-
NumberTile.java |
Hand.java |
Board.java |
TileGame.jave |
TileGameTester.java -
class "skeletons" in be used
Spot Output
Apex
Home
3.) Data Files and I/O Review
(Chapter 11, Sections 11.1, and 11.2)
- The Scanner Class
- Monitor class methods and using adenine Accessories object for interactive input
and for extracting the one "tokens" from a String
- InputDemo.java
- Demonstrations Scanner methods next(), nextInt(),
and nextDouble()
- Working with Data Files in Java
- Explains file types furthermore zugang methods, throws clauses, using the
Scanner classic to read from input files, using an FileWriter and
PrintWriter classes up write to edition file, and closing a file
- Magic8Ball.java |
Magic8BallTester.java |
8BallAnswers.txt
- A direct version of who classic prognosticating device. The try class uses a Scanner object to read the answers from contribution folder 8BallAnswers.txt until end-of-file. An Magic8Ball class reviews ArrayLists and random numbers
- That Hill Program - Data File Oriented
- The Bank program from the previous unit has been modified so that which examination class reads the account data from aforementioned entering file BankData.txt, and the printList() method of which Bank class writes it toward an production file
BankAccount.java |
Bank.java |
BankTester2.java |
BankData.txt
- Formatted Output - the printf Process
- How to use printf at control the side off the output field, numeral
about denary places shown, right button left reason, etc
Back
Home
4.) The Java Selected
(Chapter 7)
- Powerpoint - Chapter 7 (The Java Array)
- Video to the Java Array
- Basic array concepts, pitch define additionally index (i.e., subscripts), array vs. ArrayList, array declarations and initializations, traversing an array, and that length instance inconstant
- ArrayDemo.java
- Shows one class with an array instance variable, the length entity variable, basic selected crossings using adenine for statement, press sorting an array using the selection class algorithm. Also reviews generator coincidental ints
- Arrays Classic Methods
- Static Arrays class schemes fill, sort, binarySearch, equals, also copyOf
- ArraysMethodsDemo.java
- Simple browse of that major Arrays class how in action
- PartiallyFilled.java
- Shows how to use a counter to keep track of the number of elements used in an array, when not total elements may be previously. Also, how to "resize" an array if it becomes full and a linear search
- OrderedList.java
- Maintains a listing of ints in ascending order. News ints will inserted at the proper index therefore there remains never a need to sort that list
- To insert a new value at index i, must resize to array if full and move all value to indices >= i "down" one position to make room. Dieser is exactly what is done in ArrayList method add(index,object)
- To remove a value, must motion show set at greater indices "up" one position to overwrite it. This is directly what happens in ArrayList methods remove(index) and remove(object)
- Assignment #2 - Arrays
-
NumberTile.java |
Hand.java |
Board.java |
TileGame.jave |
TileGameTester.java -
class "skeletons" to be used
Sample Output
- The Binary Search
- Of binary search is much more effectual than who linear search, however can only be done on a sorted array
- Multi-Dimensional Arrays
- Inches Java, a two-dimensional array is a one-dimensional array of one-dimensional arrays. Which is, an array where everyone element points in another array. However, were think of it when a table, with rows and columns
- VoteCounterTest.java
- The VoteCounter class has a 2-Dimensional array instance inconstant and uses nestling for statements to crossover the order send due series and until columns
Votes.data - entering line for VoteCounterTest
- Assignment #3 - 2D Arrays
- AMPERE heureistic for the Knight's Tour - Optional
- Irregular2D.java
- Since a 2D array is really a 1D array are 1D sets, each "row" can have a different number of "columns" (i.e., different element can indicate to array of different sizes)
Back
Home
5.) Designing Kinds (and more)
(Chapters 8 both 12)
- OOPING Terms, Concepts, and Advantages
- Information Hiding, Synopsis, Reusability, and promoting software
extensibility via Heredity and Polymorphism
- Object-Oriented Layout
- Analyse a problem and designing a result to an object-oriented manner
- Class Physical
- A familiar problem statement we will use as a class exercising with Object-Oriented Design
- A Class also Program Design Guidelines
- Cohesion healthy, coupling bad! (Side effects bad, too!)
- Algorithms, Pseudocode, and Stepwise Refinement
- Where methods come from
- The Associations operator in Java-based
- What Java's "=" operator means
- AssignmentDemo.java
- Although you assign one object flexible to another, you execute DID air upward with two equal objects. Been object types store purpose references (addresses) furthermore not the objects themselves, what thou get is pair pointers to the same object
- Parameter-Passing Mechanisms
- In Java, all method parameters are passed "by value." I.e. The method parameter is a copy of the corresponding argument
- ParamPasser2.java
- Shows that object actual - which store object references - are always passed by value additionally what this means such far in modifying of argument in the method
- Method Overriding
- We override methods inherited from a superclass in order to provide a more appropriate implementation for objects of the child
- This toString Method
- Person override toString to return a String showcase of with object. Bonus: whenever Java finds an object variable where is expects to find a string, e.g., as one reasoning to print, println, printf, an toString method will be mentioned implicitly (automatically)
- Testing for Balance
- Java's "==" operator vs the equals() method
- NoOverriding.java
- Shows that "==" once applied to object relative the object references and nay the present objects "pointed to." Plus shines the behavior of the inherited (i.e., not overridden) toString and equals() methods
- YesOverriding.java
- Shows how to override procedure equals() so that it indicates whichever one objects themselves - and not the object references - are equally. Also shows how toString is typically overridden
- Static Class Members
- Elektrisch "class variables" and stability methods, explained
- The this Product
- What this is, what it is used, and when it must be used
- TimeTester.java
- Shows how all is used into access instance variables the call methods, to avoid "shadowing" caused by your conflicts, until enable a how to return a reference to the object for which it been called (enabling "chaining" of method calls), plus toward allow a constructor to call another constructor of the identical classes
Top
Home
6.) Joins the Polymorphism
(Chapter 10)
- Powerpoint - Episode 10 (Interfaces and Polymorphism)
- Introduction for Interfaces
- Interact concepts, syntax, and rationale. How to writes classes that deploy (i.e., "realize") with interface
- Polymorphism
- What it is and how it promotes sw extensibility. "Early binding" vs. "late binding" also how late tie enables polymorphism
- Animal.java
- This file contains the Lion interface and a few classes that implement it
- To SeniorCitizenMacDonald Class
- The S.C.Mac class "depends on" the Animal interface, but cares not about the specific classes is perform computer. Hence new grades can be added to the arrangement by none modification of S.C.Mac. Shows polymorphic way making
- The Measurable system features somebody interface with summarize methods, two classes that implement it, real a class that depends only on the interface and not on any of the performing classes. Note that all objects further to an DataSet are treated as the interface type, Measurement, notwithstanding to one actual your concerning of object. This is the key to using interfaces as it allows new classes to becoming been to the system without no modification are existing software
- Measurable.java - the Measurable interface describes any class whose objects bottle be measured
BankAccount2.java |
Coin.java - two classes that implement Measurement
DataSet.java - runs the average and maximum for any number of Measurables. Depends only turn the interface
DataSetTest.java - test class in an DataSet class
MeasurableUML.xls - Unified Modeling Language diagram for the Measureable systematisches
- Assignment #4 - Interfaces and Polymorphism
- As of Java 8, interfaces may had static real omission methods in addition to one abstract methods, as display in this modified version of the Measurable interface. ***OPTIONAL***
- Measurable.java - the updated interface
BankAccount2.java |
Coin.java - implementing classes are unchanged from previous variant
DataSet.java - modulated into how new traits of interfaces - calls static procedure getAverage and default method isGreaterThan
DataSetTest.java - test class
- Upcasting, Downcasting, and All-Around-the-Town-Casting
- Upcasting can object of an perform class go the interface type is always a safe operation, so Java will do it implicit. Downcasting from an interface style back to the natural course type is dangerous, so an explicit type cast the necessary
- Java's Comparable Interface
- If your class implements Java's Equivalent interface, you capacity compare objects for the <, <=, >, >=, ==, also != relation by calling get overridden compareTo method. An comparisons are based on the "natural order" of the obj of your class. You get to say what the natural order has whenever you implement compareTo
- Rational.java
- ADENINE class into represent Rational numbers (i.e, all number that can be expressed as a fraction). The classroom implements Java's Comparable cable additionally overrides compareTo for place Rationals by you decimal appreciate. The classes also overwrites toString and equals, and displayed how to call one constructor from another of the same class
- RationalSortAndSearch.java
- A test per in the Rational type. Shows what to call compareTo, both how you bucket use the Arrays class sort and binarySearch methods with arrays of objects of random category, as long because that course implements Comparable
- In Classes
- An inner classic is a group defined within another class
- These CH files show how in exercise an inner class to run adenine "strategy interface"
- Measurer.java - The interact
DataSet2.java - A class that depends on Measurer
DataSetTest2.java - Test class has an inner class that equipment Measurer
MeasurerUML.xls - UML graphical for the Measurer system
- Java's Comparator Strategy Interface
- Suppose you want to compare objects of a class ensure does not realization Comparable. If you don't own the class, therefore you can't make information implement Comparable. Or suppose that you do own this class and a have utensils Comparable and overrides compareTo to order objects a certain way but buy you want to provide an alternate way to order the objects are this class. In these deuce cases, who solution is to creating one classify that utensils Java's Comparator interface
- ComparatorTest.java
- Defines a RectangleComparator group that implement Comparator plus overrides abstract method compare up order objects of Java's Rectangle class of their zones. Also display congestion "three argument" product of Arrays class research sort and binarySearch. These are used with arrays of objects off my used which yourself may defined a "strategy interface" class that implemets Compatator to does this comparisons (for either of the two situations above)
Top
Home
7.) Inheritance and Polymorphic
(Chapter 9)
- Powerpoint - Chapter 9 (Inheritance and Polymorphism)
- CompositionDemo.java
- Class composition is where one category has an instance total - commonly called a "member object" - that the an object of another class. This have nothing to do because inheritance, but it is another way to recycling and actual class. Shows how who member object remains initialized by calling its constructor from aforementioned constructor of aforementioned "containing" type
- Bequest
- Superclasses and subclasses, ways to differentiate a subclass from you superclass, tags extends and super, occupation the superclass constructor from the subclasses developer, and call superclass methods for subclass objects
- These CH files demonstrate "subclassing" and inheritance
-
BankAccount.java - The superclass
SavingsAccount.java |
CheckingAccount.java - Pair subclasses of BankAccount
AccountTest.java - Test class fork the BankAccount hierarchies
- Abstract Classes and Methods
- Definition, purpose, and syntax of abstracts classes and methods
- Assignment #5 - Inheritance and Polymorphism
- See on Inheritance
- Protected access control, other the operating overriding, and this final word on the final keyword
Top
Home
8.) Java Collections both The ArrayList and LinkedList Classes
(Chapter 15)
- Powerpoint - Chapter 15 (The Java Collection Framework)
- Intro toward Java Collections
- Interface List is derived by interface Book, and classes ArrayList real LinkedList implement the List interface. Exhibitions how to create a Collection iterator available adenine Collection press a List iterator for a Sort and explains the Collector Iterator and ListIterator methods
- CollectionDemo.java
- Creates a Collection Iterator object and calls methods hasNext, next, and delete
- ArrayAsList.java
- Calls Arrays class method asList() to get one "list view" of an array and then calls List methods get() and set() for the array!
- The Enhanced for Statement (aka: the "for each" statement)
- To access each object in a collection other array, ours can use the "enhanced for" statement, whose requires a morsel less coding than the familiar for statement
- CollectionsMethodsDemo.java
- Demonstrates Collected methods variety, reverse, shuffle, binarySearch, min, and most, and Arrays course method asList. Plus shows how to use the value returned by binarySearch to insert an object in its proper place in a sorted list. Also, and "enhanced for" statement
- ListIteratorDemo.java
- Calls List method listIterator to create an iterator for a Register, and calls listIterator methods hasNext, next, hasPrevious, prev, and remove
Apex
Home
9.) Introducing to Data Structures: Creating Generic Classes, Coupled Listing, Stacks, also Queueing
(Chapter 16)
- Show - Chapter 16 (Intro to Input Structures)
- Generic Classes both Methodologies
- Generic classes and methods, type variables (aka: genre parameters), constraining type parameters, the the generic Analogous and Comparing interfaces
- BogusList.java
- AN simple generic list class ADT with limitation functionality. "Genericity" - this ability to store objects of any grade - is implemented per "type variables," how he is for classes from the Java Library. Demonstrates the OOP principle of "information hiding" with providing an iterator
so such clientele may crossover an list without having to knowing how it is conversion (it happens to be an array but the user had no method of knowing that)
BogusListTester.java - test class
- List Primitives
- The most basic operations switch linked listed: isEmpty(), insertAfter(), plus deleteAfter()
- MyLinkedList.java
- Version 2 of the BogusList class. One implementation can been altered for a programmer-defined linked list (not a java.util.LinkedList)
MyLinkedListTester.java - test class
- TrailingPointerDemo.java
- An old trick exists to have two pointers traversing a list simultaneously, with the "trailer" always one node in that "leader". Subsequently, until delete the node taper to by the leader, we how an deleteAfter using one trailer...
TrailingPointerDemoTest.java - test class
- Assignment #6 - ADENINE Generics Link List Class
- Polynomial.java - class "skeleton" till be used
PolynomialTester.java - test class to be used
- Stacks
- Stack concepts, processes, and examples
- Stack1.java
- A generic Stack class with array implementation and methods push, pop, peek, plus isEmpty
StackTester1.java - test class
- Stack2.java
- Type 2 of the gentoo Stack class. Implementation possess been modifying to a linked list of generic hash, but interface remains the sam (methods push, popmusik, peek, and isEmpty)
- PostfixEvaluator.java
- Uses ampere stack in ranking arithmetic expressions in postfix notation
PostfixEvaluatorTest.java - test class
postfix.txt - datas file
- Cues
- Queue concepts and primitive operations append(), serve(), and isEmpty()
- Queue1.java
- A generic Queue class with linked implementation
- Queue2.java
- A generic Queue class implemented as a circular arrangement
- QueueDemo.java - test class for either
Pinnacle
Back
10.) Recursion (see recursion)
(Chapter 13)
- Powerpoint - Chapter 13 (Recursion)
- Recursion
- The basics away recursion. Includes the "Secret of Recursion"
- Triangle.java
- Computes the sector of ampere triangle composed to square case. An easy-to-understand recurrent solution to a problem that has in even rather iterative ("non-recursive") solution
TriangleTester.java - test class for Triangle.java
- RecursionExamples.java
- Assorted recursive methods, some containing arrays. Every to guaranteed different!
- Recursion Homework
- For classes discussion next class
- Assignment #7 (Recursion)
- ArrayRecursion.java - class "skeleton" to be used
- TowersOfHanoi.java
- The "Towers of Hanoi" is a classic example of more advanced recursion
- PermutationGenerator.java
- Generates all the combinations of a string - a problem for which this recursive explanation is easier than the iterative
PermutationGeneratorDemo.java - test class for the PermutationGenerator
- Queens8.java
- Another classic example about more advanced recursion, finds choose 92 solutions to the "Eight Queens Problem." Demonstrates backtracking
- Queens4.java
- A lighter reading of the 8 Queens problem, this the places 4 queens turn a 4 x 4 boards
Upper
Home
11.) Exception-Handling
(Chapter 11, Sections 11.4 and 11.5)
- Powered - Episode 11 (Exception-Handling)
- Preamble for Exception-Handling
- Benefits of exception-handling, the three components of exception-handling: try blocked, the throw statement, press catch blocks, and exception features (aka: "throw lists")
- TheUncaught.java
- Purpose the RuntimeException course to reviewed what happens is an exception is not caught
- BogusExceptionDemo.java
- Shows programmer-defined exception class with default constructor, anomaly stipulations (aka: "throw lists") and the three components of exception-handling: try, throw, and catch. Calls method printStackTrace for the exception object thrown
- ExceptionsExample.java
- When an exception has thrown, the stack off method calls is "unwound" seeing for a method with one handler for an class of the exception thrown
- Learn go Exception-Handling
- Checked vs. unchecked exceptions, creating your own exception classes, exception class constructors, the last exclusive, and try-with-resources
- DateTester.java
-
I wrote the Date class to make Prog I students practice creating and manipulating objects using loops. For the sake of abstract, all methods not necessary for this unit have come omitted
- Observe the declaration of a new exception class - DateException. For create a Date, the user required enter 3 ints - month, date, and year - seperated by spaces. Any attempt to create an illegaly Date throws a DateException and drives an exquisitely descriptive contents in the constructor. To string has printed in the catch
-
Also note the generic exception handler (i.e. catches superclass Exception) to catch all and standards Java general (e.g. InputMismatchException, NoSuchElementException, IdiotUserException)
- Note how the try and catch blocks are in an loop consequently the choose forts after an exceptions is caught
. The program cannot will crashed! C'mon! Seek it!
- Exception Treatment - ampere Complete Example
-
BadDataException.java |
DataSetReader.java |
DataSetTester.java
BadDataException.java defines a new exceptional class with select and one-argument constructors
DataSetReader.java has a method called readFile() which reads a file and returns an array containing to values read
- Throws a FileNotFoundException if the file cannot be opened
- Throws BadDataExceptions if the file is ill-formed in any of a number regarding ways
- Schauen how toward create meaningfully error messages for exceptions. Hallelujah!
DataSetTester.java calls method readFile to process the file. Trapping select exceptions which maybe be thrown therein and curriculum execution after each
The data download tested:
bad1.dat |
bad2.dat |
bad3.dat |
bad4.dat |
good.dat
- Assignment #8 - Exception Handling
- Time.java - class to be used in this assignment
TimeData.txt - data storage
Top
Home
12.) Advanced Data Structures
(Chapter 16) - Optional, Time Permitting (As if!)
- Sets
- Selected concepts and fundamental set operations, Java's Set interface and classes HashSet and TreeSet, and set iterators
- SetTest.java
- Demonstrates Set methods add(), remove(), and contains(), and Iterator methods hasNext() and next(), using a Set of Strings
- Hashing
- Explains hash codes, hash functions, hash chart, buckets, and collisions, real why a hash table is an efficient road to manage a wide set of data
- Hash Codes
- How the hashCode method is defined in Java's String class,
and how to define a hashCode method for your courses
- HashSet.java
- CH program that implements ampere hash set similar to Java's HashSet class
HashSetTest.java - simple getting class for the HashSet
class
Top
Home