Advanced Java Programming Adam Gerber Ph D SCJP
Advanced Java Programming Adam Gerber, Ph. D, SCJP gerber@cs. uchicago. edu office: Ryerson CS Lab 4 th Floor office hrs: 3: 30 -5: 30 pm Wed
Android Portfolio: http: //www. flickr. com/photos/89831807@N 02/show/ Survey of the class Your name, hailing from, what you studied in undergrad, what you want to accomplish with this degree? (waive option)
Evaluations pro. Pres 10% pro. Data 10% pro. Service 10% Class participation 10% Midterm exam 15% pro. Web 20% (final project) Team Project 25%
Project Due Dates pro. Pres: due Tues July 15 at 11: 59 pm pro. Data: due Tues July 22 at 11: 59 pm pro. Service: due Tues July 29 at 11: 59 pm pro. Web: due Tues September 2 at 11: 59 pm
Team Projects Each team will be responsible for: 1/ creating a deck of slides describing the architecture of the technology Each team member will be responsible for: 1/ creating a lab using the course tools Maven/Git/Net. Beans and making their lab available on bitbucket as public repo. 2/ lecturing for 1/2 hour on that lab in weeks 7, 8, or 9. See course website for dates: http: //javaclass. cs. uchicago. edu/adv/
Piazza: https: //piazza. com/uchicago/summer 2014/mpcs 51 037/home Course website: http: //java-class. cs. uchicago. edu/adv/
Lecture 01 Agenda: 1/ intro 2/ bit. Bucket register 3/ setup dev environment JDK, maven, git, sourcetree, p 4 merge, net. Beans 8, glassfish 4/ intro to maven, netbeans, & git
Registering Bitbucket account Remote source-control: http: //java-class. cs. uchicago. edu/adv/
Set-up dev enviornment: ~/content/java_adv_install. txt
Java • Java is modeled after C++ • The majority of runtime errors in a C++ program are due to improper memory management (memory leaks). • Java is a memory-managed environment. In practice, that means you don’t have to worry about de-allocating memory when an object which was allocated on the heap falls out of scope. Garbage collected. • Since JEE and JSE 1. 5+, you may let the run-time environment manage both the allocation and deallocation of objects.
Java memory mgmt We are responsible for allocating memory on the heap using the new keyword. The JVM is responsible for de-allocating memory with the garbage collector. The finalize() method is the closest we can get to intercepting de-allocation. Date date = new Date("11/18/2007"); System. out. println(date. to. String()); //program exits The run-time environment (JEE container or JVM 1. 5+) is responsible for deallocating AND allocating memory on the heap. @Inject Date date; System. out. println(date. to. String()); //program exits
Java • Java is Write Once Run Anywhere (WORA). A java program can run on any platform that has a JVM. • A Java WAR file can run on any JEE compliant web -server, such as Tomcat, JBoss, Wirefly, Glassfish.
What Sun (now Oracle) says about Java • “…we designed Java as closely to C++ as possible in order to make the system more comprehensible. Java omits many rarely used, poorly understood, confusing features of C++ that, in our experience, bring more grief than benefit. ”
Architecture Neutral Java Code is compiled to. class files which are interpreted as bytecode by the JVM. (. NET does this too; only you’re trapped in an MS op system. ) JIT compilers like Hot. Spot are very fast – little difference between in performance between machine-binary and interpreted byte-code.
Implementation Independence • A java int is ALWAYS 32 bits; regardless of operating system. • A java long is ALWAYS 64 bits. • Etc. • The same is not true of C/C++.
No Pointers • There are no pointers in Java • Instead Java uses references; which for all intents and purposes, behave like pointers.
Version numbers in Java • Jdk 1. 5 == Java 5. 0 • Jdk 1. 6 == Java 6. 0 • Jdk 1. 7 == Java 7. 0
Wrapper Classes • Every primitive has a corresponding Wrapper class. • For example; double has Double, int has Integer, boolean has Boolean, char has Character, etc. • These wrapper classes can be very useful when storing values in collections which require you to use objects, and forbid the use of primitives.
The API Documentation of the Standard Java Library http: //docs. oracle. com/javase/7/docs/api/
Object heirarchies • You can also see the API online. Determine the version you using by typing> java –version http: //docs. oracle. com/javase/7/docs/api/ • Class hierarchies. • The Object class is the grand-daddy of ALL java classes. • Every class inherits methods from Object. • And from all its other ancestry. • Even if you create a class that extends no other classes, you still extend Object by default.
Class Object • A blueprint is to a house as a class is to an object • Class = Blueprint
Class Objects
Class Object • A blueprint is to a car as a class is to an object • Class = Blueprint
Class Objects
Spot the “class” here
Pass by value and reference
pass by value pass by reference Action: Tell my accountant how much I intend to spend on a new car. Action: Swipe debit card and enter pin at the Bently dealership. Change in bank account: no change. Change in bank account: -125 k.
If a tree falls in a forest and no one is around to hear it, does it make a sound?
Event-Source (Button) No Event-Listener listening Event (on. Click) No Catcher No Event Listener
Event-Source (Button) Event-Listener listening Event (on. Click) On. Click. Listener Any Object Catcher ready to catch
Wrong Event
Event source not registered
Event-Source (Button) Event-Listener listening Event (on. Click) On. Click. Listener On. Mouse. Listener Any Object Event (on. Mouse) Catcher ready to catch
Install Maven http: //maven. apache. org/download. cgi On Windows: verify M 2_HOME is created and PATH contains M 2_HOME On Mac/Linux: export M 2_HOME=/home/user/java/apache-maven-3. 0. 3 export PATH=/home/user/java/apache-maven 3. 0. 3/bin: ${PATH} mvn --version
cal Remote
Fork-and-Clone projects
GIT architecture
git config --global user. name "Your Name" git config --global user. email "your_email@whatever. com"
add/reset/commit: move files from working-dir to stage-dir(aka index) git add src/lec 01/glab/Digital. To. Binary. java move files from stage-dir(aka index) to working-dir git reset HEAD. git reset head src/lec 01/glab/Digital. To. Binary. java git commit -m “your commit message. ”
Amending: Every commit is associated with a sha-1 hash. That hash is derived from 1/ the file changes in that commit and 2/ the previous commit. You can not change any commit unless that commit is at the head. Since no other commits depend on the head, you may safely change the head. To change the head, use git commit --amend -m “your message” git commit --amend --no-edit
Reverting: You can roll back a commit (reverse it) by identifying it's sha 1 hash like so. git revert --no-edit 71 ac
Branching: To list the branches in a project: git branch -r git branch --all To create a branch: git checkout -b branch. Name c 39 b git checkout -b branch. Name To delete a branch: git branch -D branch. Name To checkout a branch: git checkout 7 afe git checkout master
Pushing to remotes: To see the remotes: git remote -v show To push to a remote: git push origin master: master git push origin master git push --all
Pulling from remotes: To see the remotes: git remote -v show To pull from a remote: git pull --all git pull origin eval
Net. Beans keymap
- Slides: 60