2/12/2015
Concepts: Java Servlets
- Use New Dynamic Web Project
- Create new servlets to
- Listener is designed to do setup (i.e. initializing the sessions)
- Session attributes act like hashMaps
- You can creat
2/3/2015
Concepts: Threading
start
vs.run
:start
will actually fork off a new quesiton butrun
will keep the run method of the child thread running on the main thread itself
*
1/29/2015
Concepts: Databases
- We'll be using MySQL Monitor to interact directly with MySQL
Key characteristics of a database:
- Persistent Storage
- Application Access (applications can acces the data)
- Transaction management (this is not supported by a file system): Database rolls back if either end of the transaction fails
- Efficient Searching (not necessarily supported by traditional file system)
To access the database you need:
- username
- password
- database server
- database name
Java Database Connectivity (JDBC): built-in java library that works with SQL database.
1/27/2015
Concepts: Anonymous Functions, Lambda Functions
- You can sort with an anonymous lamda function, you don't need to create the entire comparable class - just need to create that one function:
Collections.sort(ingredients, (x, y) -> (return(x.getGrams()-y.getGrams()));
Note that this anonymous function has the same context as the surrounding program in JRE 8 (JRE 9 apparently has the concept of closure)
1/22/2015
Concepts: Java Swing
java.awt
abstract window types
JFrame theFrame = new JFrame("Swing Example");
theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
(this way the entire application is still running even when you close a window)
- You can set the "look and feel" of an application
- Use ActionListeners to catch changes to buttons (like a JS callback)
1/8/2015
Concepts: Autoboxing, Templating, Generic Types, JUnit
- Remember you can't create collections of primitive types in Java, (i.e. you have to use Integer objects instead of ints)
- Autoboxing: We can autobox wrapper objects like Integers:
myIntList.add(5)
is equivalent tomyIntList.add(new Integer(5))
- Autounboxing:
int x = myIntList.get(0)
Though this list is made ofInteger
objects, Java will auto-unbox the int value for you- You do need to be explicit to unbox in this case:
a.get(0).intValue() == b.get(0).intValue()
- You do need to be explicit to unbox in this case:
Generic Types
- You can use generic type parameters to template objects in Java:
public class Pair<T> {
private T a;
private T b;
}
...
Pair<Integer> iPair = new Pair<Integer>(1,2);
- Beware! You cannot instantiate new generic types inside a class that uses a type parameter. This is because Java doesn't know what type it is at run-time (due to backwards-compability in the internal implementation of types because only the compiler knows about the type)
JUnit Testing Frameworks
- test stub - sample item returned that can be used to test a program (i.e. a single word returned by the hangman initialization function)
- test harnesses - stands in as a potential user of the program you're writing