Hofstra University
University College for Continuing Education

M3161-01 Introduction to Java Programming

instructor: Engin Yalt

home

Duke
Text Books:
Java: An Introduction to Problem Solving and Programming, Walter Savitch
Prentice Hall , Amazon 4th
Thinking in Java, 3rd Edition, Bruce Eckel
Free e-book 3rd Ed, Amazon 4th Ed
Head First Java, 2nd Edition, Kathy Sierra
O'Reilly, Amazon

The Java Tutorial, by Sun

Download Java 2 Platform Standard Edition 5.0
JDK 5.0 Update 8  Installation Instructions
API Specification: 1.4   1.5 (Java 5)
J2SE 5.0 New Features and Enhancements
Download the free code samples from these books:
Java Programmer's Reference by Grant Palmer source code
Java in a Nutshell, Third Edition by David Flanagan
Java Examples in a Nutshell by David Flanagan
Beginning Java 2, SDK 1.4 Edition by Ivor Horton

TextPad (an excellent text editor)
Eclipse (industry standard IDE)
Java Ranch (check out the Big Moose Saloon)
UML Tutorial


  Subject Thinking In Java Head First Java Class Work Home Work
Sep 13 Intro to Java, OOP, Install JDK 1,2 1,2 UML - Class Diagrams Set up JDK,
compile and run HelloWorld.java
Sep 20 Data Types, Methods,
Program Flow, Control Structures,
Object Life Cycle, Garbage Collection
3,4 3,4,5,6,9,10 Quiz 1 answers
Classwork
Grant Palmer:
ch 1.1-1.9, 2.4
HW 1
Project 1
Sep 27 Encapsulation, Access Modifiers,
Inheritance, Abstract Classes,
Overloading, Overriding
5,6 4,7 Quiz 2 answers
Martian.java
ClockTest.java
ShapeTest.java
Oct 4 Interfaces, Packages,
Generics, Polymorphism,
7,8 8,9 Quiz 3 answers
ConstructorTest.java
InterfaceTest.java
HW 3
Project 2
Oct 11 Exception Handling, Detecting Types,
Data Structures, Collections, Inner Classes
9, 10, 11 10, 11, 16 TestThrow.java
TestThrows.java
ExceptionTest.java
TestInstanceOf.java
Project 3
Project 4
Oct 18 I/O, Multi Threading 12,13 14 Quiz 4 answers
TestNotOptimized.java
TestT.java
TestT2.java
TestT3.java
TestT4.java
TestT5.java
TestPC.java
TestOptimized.java
  TestFR.java
TestFW.java
TestBIS.java
TestBOS.java
TestFIS.java
TestFOS.java
 
Oct 25 "instanceof" operator
Cloning
String, StringBuffer, StringBuilder
Singleton
Serialization
14 12,13,15
ShapeTest.java
CloneableTest.java
StringBufferTest.java
SingletonTest.java
  Serialization
- PersistentTime.java
- FlattenTime.java
- InflateTime.java
 
Nov 1 Applets (eg),
Swing,
Networking
JAR Apache ANT
JAVADOC
POJOs
   
GetURL.java
GetURLInfo.java
HttpMirror.java
HttpClient.java
Server.java
Client.java
  TicTacToe.html
TicTacToeServer.java
TicTacToeClient.java
 


Additional Books (free e-book to download):
The Java Language Specification by James Gosling, Bill Joy, Guy Steele, Gilad Bracha
The Java Virtual Machine Specification by Tim Lindholm, Frank Yellin

Related Articles
When is a Singleton not a Singleton?
JDJ - Don't Tell Me Cause It Hurts
The Pitfalls of Outsourcing Programmers
JDJ - What Is POJO Programming?
JDJ - Java Is Dead, Long Live Java!
Abstract Classes vs. Interfaces

JDJ - Digitial Edition
JDJMarch2006.pdf
JDJFeb2006.pdf
JDJJan2006.pdf
JDJDec2005.pdf
JDJNov2005.pdf
JDJOct2005.pdf


top
Home Work due March 1st
You can pass the inputs as arguments after the class name, separated by spaces: java MyClass arg1 arg2 arg3

Input - firstname lastname
Output - lastname, fistname

Input - 1 integer(n)
Output - print all numbers from 0 to n
Output - print all even numbers from 0 to n
Output - print all odd numbers from 0 to n
Output - determine whether the integer is even, odd or zero.

Input - 1 integer(n), 1 string("odd" or "even")
Output - if the string entered is "even", print all even numbers from 0 to n
Output - if the string entered is "odd", print all odd numbers from 0 to n

Input - 1 integer (ex:12345)
Output - digits seperated by a space (ex:1 2 3 4 5)

Input - n integers
Output - Min, Max, Sum and Product of those n integers
Output - Print the largest 2 numbers (input: 1,2,3,4,5 output: 4,5)

Input - n integers
Output - Number of integers entered
Output - Number of even integers
Output - Number of odd integers
Output - Number of integers that are zero

Input - none
Output
number	square	cube
0	0	0
1	1	1
2	4	8
3	9	27
4	16	64
5	25	125
6	36	206
7	49	343
8	64	512
9	81	729
10	100	1000

Input - none
Output - use for loops and only System.out.print("* "), System.out.print(" ") and System.out.println("")
* * * * * * * * * *
 * * * * * * * * * *
* * * * * * * * * *
 * * * * * * * * * *
* * * * * * * * * *
 * * * * * * * * * *
* * * * * * * * * *
 * * * * * * * * * *
* * * * * * * * * *
 * * * * * * * * * *

Input - none
Output - 2,4,8,16,32,64.... etc (create infinite loop, you will have to hit CTRL+c, to stop program)

Input - integer (ex: n=5)
Output - 2,4,8,16,32  (loop upto the nth power of 2)

Input - 3 positive integers (a,b,c)
Output - Determine if those values can be the sides of a right triangle (a2=b2+c2)
(You should not assume that the first integer is the hypotenuse. If b2=a2+c2 or c2=a2+b2 holds true, the program should evaluate this as a possible triangle)

Input - integer (n=500)
Output - Print out all the Pythagorean Triples, hypotenuse being no larger than the input n
ex: (3,4,5) (4,3,5) (5,3,4) (5,4,3) (5,12,13) (6,8,10)....... (300,400,500)
Output - modify the program to not print out duplicate entries such as (3,4,5), (4,3,5), (5,3,4), (5,4,3)
Output - modify the program to not print out "similar" triangles. (3,4,5) is similar to (6,8,10). (all sides multiplied by a coeficcient)

Input - 1 integer: n>0
Output - compute the factorial: n! = n(n-1)(n-2)...(2)(1)

Input - none
Output - compute the value of PI: PI=4-4/3+4/5-4/7+4/9-4/11+...  (3.14159...)
Output - compute the constant e: e=1+1/1!+1/2!+1/3!+1/4!+...    (2.71828...)

Input - 1 integer (x)
Output - compute the value of e^x using the formula e=1+x/1!+x^2/2!+x^3/3!+x^4/4!+...
Most of the homework assignment are taken from Java How to Program by Deitel & Deitel
top
Home Work 3

Step 1 - Create a UML Class Diagrams for each data set provided below. Note that this is just a partial list, assume your client only managed to provide that much requirement. You can add/remove any object as you wish. For this exercise you may or may not use the following: abstract class, final class, interface, composition... Use the 'is a', 'has a' test to identify whether inheritance or composition is required. Keep in mind that there are no right or wrong answers. Even if you can't combine every single element, at least try with subset of the following items. We'll go over it in class.
All you need is a pen and paper, but you can also use PowerPoint. Make sure "Drawing" toolbar is selected. Then you can use the "AutoShapes" to draw the classes and relationships. A rectangle can represent a class, a "connector" -such as an error- can represent the relationship (inheritance).

Step 2 - Write the Java Code, and compile for each.

TimeEcommerce
clock
wristWatch
wallWatch
computerWatch
tableWatch
grandfatherClock
hourglass
type [digital or analog]
watchStand
cradle
hanger
pendulum
wristband
hourHand
minuteHand
secondHand
digital display
hour
minute
second
resetTime()
addTime()
deductTime()
motion powered
battery powered
solar powered
changeBattery()
shake()
Customer
Shipping Address
Billing Address
Shopping Cart
Product
Order
Payment
Order History
regularCustomer
wineCustomer (21+ required)
creditCard
expirationDate
checkAge()
addItem()
removeItem()
changeQuantity()
checkOut()
submitOrder()
cancelOrder()

Exception Handling
Create a class called "BankAccount", that has the following field values: firstName, lastName, customerID, balance, dailyLimit. Create the necessary constructors. Implement the following methods: widrawMoney(), depositMoney(). Create 2 exceptions called "NotEnoughMoneyException", and "DailyLimitReachedException".
Ex: If there is $100 in the balance, and the customer wants to widraw $200, a NotEnoughMoneyExceptionWould be thrown. Also, the BankAcount class should keep a track of the total money widtdrawn in a given day, and if that limit is reached DailyLimitReachedException should be thrown.

instanceof
Modify ShapeTest.java. Add a new method "roll()" in the Circle class. In the main method, for loop, check to see if the temporary object (temp) is an instance of Circle using the instanceof operator. If "instanceof" operator returns true, call the "roll()" method.