You are on page 1of 6

Java II

Lecture 1
http://www.fas.harvard.edu/~cscie10
CSCie10@Fas.Harvard.Edu
Most took Java 1 in the fall
objectives of course:
exponential growth in number of transistors that fit on a chip
Moore's law - every 18 months processing power doubles.
Software has resisted the improvement that has happened in hardware.
Henry ford first came up with standardized parts
recursion:
factorial
base case when n = 0
n * (n-1)
slight penalty with overhead of calling classes
inheritance --> Mammal Class
^ ^
| - extends |
dog (sub class) (cat)
encapsulation
data / properties and behavior (methods) (things it can do)
Message passing between objects
Polymorphism - Have Java determine at runtime which objects needs to be ran
each element in mammal array sent speak, and at runtime it determines how it spe
aks
define classes in a way that you don't have to worry about lower level details
EXCEPTION handling
,--Division
Run Timeby zero, Array out of bounds, file availabilty
be able to recover from exceptions.
TRY - CATCH block -- try this code, if you catch one of these exceptions, d
o this.
Starting with Unit 5, Unit 6 will work with GUIs
-- design and implementation of GUIS
--- watching for events that take place by user actions
Unit 7
Data Structure --- huge impact on performance.
Array List --> Array management auto magically
Linked Lists - single / double
Unit 8
Assembly Language --> Human readable version of machine language
computer architecture --> lower level view of the machine
What computers are doing all day long.
Stack Frame.--> Methods calling methods, or methods calling themselves.
Assembly is dependent on processor in machine.
MIPS processor => use simulator
-----
Prerequisites: Alegbra, CS50,
You will be busy!!!
6 Problem sets, mostly programming --> due dates strictly enforced.
BEFORE Monday 3pm
term project --> GUI
Mid Term & Final Exams (open book)
Proctorial System. !!!
TF's
Christopher Morris --> Head TA - full authority to make exceptions
--- Wednesday section
David Havermehl
David Hughes
Brandon Tineo
Review: this Wednesday
Regular Sections NEXT Week!!
Monday 10:30pm EST, (ONLINE)
Thursday 7:15pm EST (ONLINE)
TEXT --> get Building Java Programs 4th Ed
--> MIPS Assembly Language Program
--> Core Java --9th
--> Computer Science An OverView
--> Java Language Ref
--> On To Java --- Free online (using older version)
--> Swing - A beginners guide
--> Linux Command Line
MidTerm 15%
Problem Sets 50%
Final 25%
Term Project 10%
TA Appraisal priceless
53 church street lab 9a to mid night
Harvard Cooperative Society
Science Center - 24 / 7
=====================================
Intro to Computer Science using Java, II
Bill Gates --> vs GM joke
Java --- 1991 James Gosling / Patrick Naughton (code named Green)
no consumer ever found
further developed, named Oak, already in use
Java from coffee shop
Declarative / Imperative .... Example = C, very close to machine language
LISP --> 1950's First functional language ... everything is function
used for AI
1968 objective oriented ... 1968, popular with small talk,
most popular C++
Free account with Cloud9
CS50.io
Cloud 9 does not allow Swing.
www.fas.harvard.edu
unicode.org --- full unicode char sets
"\u 03B2 "
Java is less error prone than C++, intellectual roots in small talk
Features of Java
* Simple
* Pointers ..... Dereferencing etc. don't have to worry about pointer issues
* Multi Threaded --> each thread is separate program.
* Recycles memory automatically
In C, have to free up. Java handles.
Pauses -- might be garbage collection
* Distributed and Secure --> Applets in broswers cant read files on local drive
* Robust ---> programs are less brittle, by explicity watching for Try Catch
* Byte Code --> run anywhere
What is OOP?
Encapsulation, Inheritance, Polymorphism
JavaC --> compile
Hello.Class --> byte code
Java Hello.Class
Operator Prededence:
= assignment right to left
[]
.
()
++ , -- increment / decrement
unary minus / plus
bitwise operators ---->
new --> object instantiation R to L
( type ) ... type case R to L
multipliction, division, remainder L to R
addtion, substraction, concatenation
left shit, right shift
< ,
==, !=
?: conditional operator ... ternary operator
lowest precedence / priority = assignment
control flow in Java
if (condition) { Java Statement}
if (condition) {Java stmt}
else { Java stmt}
Switch ( expression of certain types )
{
case value1: Java statements1;
case value 2 Java Statements2;
default: default java statements;
}
wrapper objects
int --> Integer objects
double -> Double
break --- get out of here, done
might flow through all java statements
problem set --> how many days in a month via switch statement
--------------------
Looping
for ( initialize; boolean exp, increment) {java statment}
while (java statement) {}
Do {java } while () --- execute at least once.
for each : for every value in the array, do xyz.
continue --- next iteration of loop
break get out of switch, or LOOP
return: return from a method
primitive data types. --> lower case
primitive vs Objects
single dim array example
strArr --> [ ],[],[],[],[]
strArr --> [Hello01 ],[Hello12],[],[],[Hello45]
can't directly change size of array at run time.
have to move arrays around
can't compare arrays for equality using == compares pointer address
Java.util.Arrays class
binary search index of a given value in a sorty array
copyOf
equals ( array1, array2)
fill (array, value)
toString(array)
Java API
Arrays get passed by Reference (they are objects)
two dimensional arrays are arrays of arrays
nested for loops to process the ith row, and jjth column
have to watch for edges, and negative indexes
for (int j = 0; j < MEDALS; j++)
{
total += counts[i][j];
}
object: an entity that contains data (variables inside the object) and bechavior
(methods inside the object).
You interact with the methods

Methods (behavior)
fields (state) attributes, breed, color, size, weight, name, isHungry
Class java.lang.STring .... see stringTest.java
a String object can not be altered
int length()
String trim()
boolean equalsIgnoreCase(String other)
int compareTo
Class named StringBuilder --- mutable
--converts strings to stringbuilder and back again

You might also like