UNC-CH COMP 210
Learning Java Programming
These items are video links explaining code that downloadable.
Down load the code, follow along with the videos in your IDE
-
VID: compiling then executing (command line)
This video shows the basics of Java program structure... source files, classes, public static
void main, compiling, running the compiled code, etc.
-
VID: Static Methods in a Class
This video shows the use of the keyword "static" on methods in a class
-
VID: Static Fields in a Class
This video shows the use of the keyword "static" on fields (data) in a class
It also serves as a pattern or suggestion for your assignment A1
-
VID: Arrays and String
This video shows the use of arrays and strings (reference types) in Java.
It also includes an implementation of bubblesort on an array, and a
suggestion for 2 altered versions of bubblesort you can write to exercise
your growing understand of Java coding.
Power Point information on Stack, Heap, Classes, Objects
Encapsulation
-
VID: Encapsulation (private fields and methods)
This video illustrates
one the 4 main "pillars" of OO programming: Encapsulation.
Encapsulation is making class fields private, and class methods private,
as appropriate to make objects of the class properly protect
the data in the object, making that data not visible and not
manipulable directly by code outside the methods of the class.
We say that objects of some class "encapsulate" their data
by making it only accessible by asking the objects to run their
public methods.
We will be implementing our data structures in 210 with classes that
exhibit proper encapsulation.
Abstraction
Download code for Interfaces (zip file)
Download code for Interface explanation using A2 (zip file)
Download code for using HashMap in Java (zip file)
HashMap is in the Java Collections library, and for Assignment 5 and 6
you may use data structures from the collections (such as HashMap, Queue,
Stack, PriorityQueue, etc.)
BTW, you should be able to take these example Java programs,
and user TreeMap instead of HashMap, since both are Maps.
However, for large data, TreeMap is not as efficient.
Download code for using Stack, Queue, Deque, PriorityQueue in Java (zip file)
Stack, Queue, Deque, and PriorityQueue are all in the Java Collections
library, and for Assignment 5 and 6 you may use data structures from
the collections. Here are examples of how to do this.
Note that PriorityQueue Ex 3 and 4 show how to define
a comparator function when you need a Priority Queue where the items
in the Queue are not basic Java types (like String and int) where we
have a built in "<" ordering function.
A comparator function will take two items of the types in the Queue and
return a value telling is the first item is less_than, greater_than,
or equal_to the second item.
In Ex4 we created something similar to what you need for Dijkstra's
algorithm (A6). The PriorityQueue contains pairs (int,String) where
the String is the name of a node, and the int is the priority (the distance
we currently know for the path from start to the node named in the pair).
Once we get a pair out of the PriorityQueue we take the name component,
hash it and get the actual object with that node name.
Pillars of OO Programming
- Encapsulation
- Abstraction
- Inheritance (in COMP 301)
- Polymorphism (in COMP 301)