Chapter 2 - Client-Server Systems Flashcards

1
Q

What is a database?

A
  • collection of data
  • links between entries
  • accessible from many perspectives
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

6 advantages of a database

A
  • Easy to share info
  • see relationships
  • avoid data duplication
  • easier to enforce data security
  • easier to enforce data integrity
  • transaction friendly
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

2 types of database

A

Relational

Object Oriented

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe Relational Database

A

Tables with mathematical relationships.
Rows=records
Columns=attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a foreign key?

A

A foreign key in this table is a primary key in that table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does Java need in order to connect to a DBMS?

A

A driver (eg JDBC)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Statements vs prepared statements

A

Prepared statements are

  • prepared long before execution
  • compiled at the DB, not at the client
  • safer from code injection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

3 Layers of basic multi tier system (MVC)

A
    • VIEW (the browsers/clients)
    • CONTROL (the server)
    • MODEL (DBMS/database)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of the CONTROLLER layer in a multi tier system?

A

Handles DB (SQL) transactions.

  • load balancing
  • concurrency control
  • security
  • logic & control
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What protocols are used between the VIEW and CONTOLLER layer in a multitier system?

A

http - used between browser clients and server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What protocols are used between the CONTROLLER and MODEL layers in a multitier system?

A

SQL (between server and DBMS)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

3 Advantages of Multitier Systems

A
  • scale ability
  • Reduce network congestion
  • Flexibility (eg languages)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

give 2 database models

A

Relational and Object-Oriented

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a candidate key in a DB table?

A

a collection of attributes (column values) which can uniquely identify a single record

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a primary key?

A

A candidate key made up of only one attribute… that attribute is the primary key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a foreign key?

A

when a record in one table refers to a primary key from another table, the primary key is called a foreign key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Give 6 advantages of databases

A
  • easy sharing of info btwn processes
  • can see relationships between data
  • avoids data duplication
  • easier to enforce security
  • easier to enforce integrity
  • transaction-friendly
18
Q

What are the 4 steps Java goes through to communicate with a DB?

A
  1. Load Driver
  2. Connect
  3. Create Statement object & execute
  4. Access results in ResultSet
19
Q

give the code to load a DB driver

A

String driver = “com.mysql.jdbc.Driver”;

Class.forName(driver);

20
Q

give 2 lines of code to make the connection with a DB

A

String url = “jdbc:mysql//server-name:port/context-root

Connection connection = DriverManager.getConnection(url, “user”, “pwrd”);

21
Q

Give a little code to go through a ResultSet:

A

ResultSet results = //execute statement here
while( results.next() ) {
String str = results.getString(“column-name);
Date bDay = results.getDate(1); // used row number

22
Q

Create, set and execute prepared statement to get 2 values.

A

PreparedStatement prep = connection.prepareStatement(“SELECT attribute1 FROM table WHERE strAttr=? AND dateAttr=?”);

prep. setString(1, “name”);
prep. setString(2, myBDay);

ResultSet rs = prep.executeQuery();

23
Q

Create, set and execute prepared statement to write a value.

A

PreparedStatement prep = connection.prepareStatement(“UPDATE table SET attribute=? WHERE primKeyAttribute=?”);

prep. setString(1, “name”);
prep. setInt(2, id);

ResultSet rs = prep.executeUpdate();

24
Q

What are the three tiers of a multi-tier architecture?

A

Client
domain / application Server
Database server

25
Q

3 advantages of multi-tier systems

A
  • scaleability
  • reduce network congestion
  • flexibility
26
Q

4 main actions of a server tier

A
  • read data sent by client (usually http)
  • process data
  • prepare results
  • send results back to client
27
Q

list 6 servlet methods

A
  • init
  • service
  • doGet
  • doPost
  • doPut
  • destroy
28
Q

describe the “service” method of a servlet

A

Called by server in a new thread on receipt of http request.
checks HTTP method type and calls doXxx, as required.
SHOULD NOT BE OVERRIDDEN

29
Q
create a GET form in a url with the following attributes:
firstname is John
lastname is Smith
server is localhost
context root is servlet/FormProcessor
port is 8080
A

http://localhost:8080/servlet/FormProcessor?firstname=John&lastname=Smith

30
Q

How can session information be achieved if the client does not allow the use of cookies?

A

Use URL rewriting

31
Q

what are the four scopes of session bean?

A
  • page
  • request
  • session
  • application
32
Q

what are the access limitations of a session bean with a scope of “page”

A

can be accessed from PageContext by that JSP only during the current request

33
Q

what are the access limitations of a session bean with a scope of “request”

A

Can be accessed from the ServletRequest object by any JSP or Servlet during the current request

34
Q

what are the access limitations of a session bean with a scope of “session”

A

Can be accessed from the HttpSession object for the rest of the client session

35
Q

what are the access limitations of a session bean with a scope of “application”

A

Can be accessed from ServletContext object by all JSP and Servlets

36
Q

What are the three states of an EJB?

A

@Stateful
@Stateless
@Singleton

37
Q

Give two types of EJB

A

session bean and

message-driven bean

38
Q

purpose of EJBs

A

To hold the business logic of a multi-tier application, as opposed to the website and client interfacing logic

39
Q

How are EJBs handled by the application server?

A

They are created in an EJB container, and the application server creates and deletes them as needed.
Note, there is only ever one instance of a Singleton bean

40
Q

Server Tier provides CGI.

What is CDI & what are its 3 main functions?

A

Common Gateway Interface, handles client requests and responses:

  • handle http requests and responses
  • manage sessions (eg URL encoding and cookies)
  • fetch & prepare results