Quiz 3 Flashcards
JDBC
Java Data Base Connectivity. An API that consists of libraries of classes used to interact with a relational database from a java application
JDBC API allows you to access databases from just about any database vendor (T/F)
True
JDBC API lets you create a Connection object which allows you to log into the database (T/F)
True
JDBC API lets you create a Statement object to send queries/update statements to the database source (T/F)
True
JDBC API lets you create a PreparedStatement object that can be cached and executed only once (T/F)
False. It can be executed multiple times.
JDBC API lets you use a CallableStatement for executing stored procedures on the database (T/F)
True
JDBC API lets you process the results returned from the DB in a Collection object (T/F)
False. It is returned in a ResultSet object.
JDBC API lets you close the connection to the DB (T/F)
True
JDBC API looks after all of the translation work needed for your java app and the database to talk to each other (T/F)
True
What is needed to run a JDBC API?
A JDBC compatible database driver which must be loaded by your java application code in order to be used. Applications can load and use more than one driver depending on the back-end DB.
What are the steps to access a database via a Java app?
- Load JDBC driver
- Create Connection object and pass in DB URL, user and pass as args
- Create Statement/Prepared Statement object
- Execute the query/stored procedure
- Process the results
- Close ResultSet (if used)
- Close Statement object
- Close the Connection object
Types of DB Drivers
- JDBC to ODBC bridge (inefficient, unreliable)
- Native-API partly Java
- JDBC to Network protocol pure Java
- Native protocol pure Java (most efficient)
Model View Controller (MVC)
Design pattern that helps you break code into functional segments with clear boundaries as to what each segment does (compound design pattern)
MVC architecture
Design GUI using three separate code entities:
- Model - maintain the data to be displayed in GUI
- View - displayes data contained in model
- Controller - handles user inputs and updates model
If you have a view registered as a listener for the model then it can automatically update itself when the event fires (T/F)
True
Multiple views can be serviced by the same model (T/F)
True
TableModel
Interface that specifies 9 methods to manipulate data from a ResultSet:
- addTableModelListener
- getColumnClass
- getColumnCount
- getColumnName
- getRowCount
- getValueAt
- isCellEditable
- removeTableModelListener
- setValueAt
Process
- Can be thought as the entire program
- Every process has its own address space
- Process based multitasking means 2+ programs can be run concurrently
- Process based multitasking is controlled by the OS
Thread
- A small part of a process
- All threads in a process share the address space
- Thread based multitasking means a process can run 2+ threads concurrently
- Thread based multitasking is under the control of the JVM
Option 1 for creating threads in Java
Have the class being run as a thread implement the Runnable interface. Runnable represents a job that can execute concurrently with other jobs. Coder must only implement the run() method.
Option 2 for creating threads in Java
Extend the class from the Thread class, which also implements the Runnable interface, and override the Thread class run() method with your own code.
run() is automatically invoked by the JVM but should still be called explicitly (T/F)
False. Coder should not call run() explicitly, otherwise the code will run inside the current thread, no new thread will be used.
What does the start() method do?
Signals the JVM that a thread is ready and waiting to run, so it joins the queue of threads waiting to run.
Stop(), suspend() and resume() are unstable and should not be used (T/F)
True