Specialized Topics

Description

Mind Map on Specialized Topics, created by Bhavit Chhatralia on 27/05/2014.
Bhavit Chhatralia
Mind Map by Bhavit Chhatralia, updated more than 1 year ago
Bhavit Chhatralia
Created by Bhavit Chhatralia almost 10 years ago
97
0

Resource summary

Specialized Topics
  1. XML Parsing
    1. What is XML
      1. HTML-like language (XHTML is application of XML)
        1. Custom tags instead of predefined
          1. Strict grammar
            1. Standard format for data interchange
              1. <messages> <message index="1" epoch="1318236815692" from="paul.devrieze@gmail.com"> <h1>Welcome to Programming 2</h1> </message> </messages>
              2. Structure
                1. What in computer science is called a tree
                  1. what is a tree?
                  2. One root, has any number of children.
                    1. Every child has one parent.
                      1. Children can have any number of children
                        1. A child without children is called a leaf
                          1. The elements of a tree are called nodes
                          2. Parsing /chat/messages
                            1. parseMessages(XMLPullParser in,...)
                              1. On END_DOCUMENT return the stored list of messages
                                1. On START_TAG (assuming <messages>) call parseMessagesRoot(in,...). Store resulting List<Message> as local variable
                                2. Reading XML docs
                                  1. standardized parsers that do much of the heavy lifting
                                    1. DOM - Document Object Model (builds a tree for your in memory)
                                      1. parsing depends on recursion
                                      2. SAX - Simple API for XML (Invokes methods in handler during parsing, push based)
                                        1. STAX - STreaming API for XML (Ask for the next event, pull based)
                                          1. Fast + strightfoward
                                            1. parsing depends on recursion
                                              1. Android does not have standard STAX, but does have XMLPullParser (slightly different API, same principle)
                                          2. XMLPullParser approach
                                            1. Ask for next() node type (skips comments)
                                              1. Have a loop containing a Switch on the type. Handle START_TAG different from TEXT, END_TAG and END_DOCUMENT.
                                                1. Handling START_TAG by separate method that returns when it sees an END_TAG
                                                  1. Stop the loop on END_TAG or END_DOCUMENT (remember a return stops a loop as well
                                                2. Revision Control
                                                  1. Why
                                                    1. Collaboration
                                                      1. Keeping track of versions
                                                        1. Roll-backs
                                                          1. Managing multiple releases
                                                          2. Terminology
                                                            1. Repository – The database storing changes with when and by whom
                                                              1. Working copy – A directory with a checkout of the repository where the work happens
                                                                1. Checkout – The process of getting a particular version out of the repository
                                                                  1. Update – Getting the latest version into the working copy
                                                                    1. Commit – Send a set of changes to the repository
                                                                    2. VCS Operations
                                                                      1. Create
                                                                        1. A repository is a database. It contains more than just the files, it maintains a history.
                                                                          1. The database must be created before things can be added
                                                                            1. Version control databases are generally add-only. Old revisions (and the files) don't get deleted
                                                                            2. Checkout
                                                                              1. Load a revision (possibly the latest) from the repository into the checkout dir
                                                                                1. Private working copy means multiple people can do work without conflict
                                                                                2. Commit
                                                                                  1. Add a change from the working copy to the repository.
                                                                                    1. The comment matters, it allows you to find back things.
                                                                                      1. The repository can be configured to check code before commit, or to send out mails afterwards
                                                                                      2. Update
                                                                                        1. Get the last changes from the repository
                                                                                        2. Add
                                                                                          1. Signal in the working copy that the file should be added to the repository
                                                                                            1. Becomes part of the pending changeset
                                                                                            2. Ignore
                                                                                              1. Some files are auto generated
                                                                                                1. These files often change often.
                                                                                                  1. They can be recreated on demand
                                                                                                    1. Most revision control systems can be told to ignore patterns of file and directory names
                                                                                                      1. When ignored, files are not proposed for adding to the repository.
                                                                                                      2. Delete
                                                                                                        1. Delete file from future revisions
                                                                                                          1. Generally removes file from working copy immediately, from repository on commit
                                                                                                            1. File is not actually gone
                                                                                                          2. Subversion Trunk
                                                                                                          3. Threads
                                                                                                            1. Multiprocessing
                                                                                                              1. Multiple programmes can run concurrently on a computer
                                                                                                                1. Supported by multiple cpu's or by dividing up a CPU into timeslices
                                                                                                                  1. Each program / task has its own memory space, file descriptors etc
                                                                                                                  2. Inter Process Communication
                                                                                                                    1. To allow collaboration between programmes Inter Process Communication is needed
                                                                                                                      1. Using pipes (virtual files)
                                                                                                                        1. Using RPC middleware
                                                                                                                          1. Using regular files
                                                                                                                          2. Multithreading
                                                                                                                            1. Multiprocessing completely separates instances, multi threading shares most resources
                                                                                                                              1. Multi threading allows shared memory. Objects in one thread are present and shared with objects in another thread.
                                                                                                                                1. Java has native Thread support
                                                                                                                                2. Why use multithreading
                                                                                                                                  1. Do computation in background keeping UI responsive
                                                                                                                                    1. Handling (slow) I/O while keeping the processor occupied
                                                                                                                                      1. Programming model is more straightforward than asynchronous I/O
                                                                                                                                        1. Utilizing multiple CPU(s) and cores
                                                                                                                                        2. Issues with multithreading
                                                                                                                                          1. What happens on which thread?
                                                                                                                                            1. How to stop threads to step on each other's feet.
                                                                                                                                              1. Deadlocks (infinite waiting)
                                                                                                                                                1. Race conditions (inconsistent data)
                                                                                                                                              2. Thread synchronization
                                                                                                                                                1. Allows structured communication between threads
                                                                                                                                                  1. Java has synchronized keyword (for method, or block of code)
                                                                                                                                                    1. Hard to get right
                                                                                                                                                      1. Android and Java have utility classes to make this easier
                                                                                                                                                    2. Thread in Java
                                                                                                                                                      1. Thread class allows starting of a thread
                                                                                                                                                        1. The thread code is in a Runnable (Thread is a Runnable). End of the run() methods ends the thread
                                                                                                                                                        2. Communicating between threads
                                                                                                                                                          1. Shared memory (either synchronized or volatile variables)
                                                                                                                                                            1. Pipes – virtual files that allow passing of data
                                                                                                                                                              1. Message passing
                                                                                                                                                                1. Thread.sleep(), Object.wait(), Thread.interrupt() - Poke the thread for attention (timing not guaranteed)
                                                                                                                                                                2. Shared memory
                                                                                                                                                                  1. Multiple readers at the same time is fine
                                                                                                                                                                    1. Multiple (blind) writers can be fine
                                                                                                                                                                      1. Mixing read-only with write-only can be fine
                                                                                                                                                                        1. Most writing needs reading (adding 1 to a value)
                                                                                                                                                                          1. Unfortunately a modern programming language is a leaky abstraction in the face of multithreading (you want to know about hardware)
                                                                                                                                                                            1. Use synchronization.
                                                                                                                                                                              1. Synchronization needs an object to synchronize on.
                                                                                                                                                                                1. All readers and writers need to be synchronized to the same object
                                                                                                                                                                                  1. Immutable objects (only final attributes) such as Strings don't need synchronization.
                                                                                                                                                                                  2. Pipes / files
                                                                                                                                                                                    1. Allow passing of “arbitrary format” byte streams.
                                                                                                                                                                                      1. Very basic primitive (OS based)
                                                                                                                                                                                        1. Files are disk based and use OS based synchronization
                                                                                                                                                                                          1. Pipes are memory based but also OS based.
                                                                                                                                                                                          2. Message passing
                                                                                                                                                                                            1. Each thread has a message queue
                                                                                                                                                                                              1. Messages may have a return address
                                                                                                                                                                                                1. Threads have a message pump (event loop)
                                                                                                                                                                                                  1. Events are processed sequentially
                                                                                                                                                                                                    1. A special message can be used to stop loop
                                                                                                                                                                                                      1. Used for processing GUI events from the OS
                                                                                                                                                                                                    2. Databases
                                                                                                                                                                                                      1. Why databases?
                                                                                                                                                                                                        1. To store and retrieve data in a permanent fashion
                                                                                                                                                                                                          1. Databases abstract away the problem of data storage, caching etc.
                                                                                                                                                                                                            1. Databases ensure consistency
                                                                                                                                                                                                              1. Complex structures are hard to store another way efficiently
                                                                                                                                                                                                                1. Handles optimization and indexing
                                                                                                                                                                                                                2. What databases
                                                                                                                                                                                                                  1. Android: SQLiteDatabase (using sqlite)
                                                                                                                                                                                                                    1. Java: JDBC
                                                                                                                                                                                                                      1. Interface for connecting with many databases
                                                                                                                                                                                                                        1. Database independent
                                                                                                                                                                                                                          1. Extensible
                                                                                                                                                                                                                            1. Not really straightforward
                                                                                                                                                                                                                          2. How databases?
                                                                                                                                                                                                                            1. Connect to a database
                                                                                                                                                                                                                              1. Issue query / execute SQL statement
                                                                                                                                                                                                                                1. Retrieve results
                                                                                                                                                                                                                                  1. Close connection
                                                                                                                                                                                                                                  2. Connecting to a database
                                                                                                                                                                                                                                    1. You need to declare the database to use
                                                                                                                                                                                                                                      1. Embedded: Open file, initialise memory data structures
                                                                                                                                                                                                                                        1. External: Authenticate, allow server to prepare
                                                                                                                                                                                                                                          1. Connecting Android/SQLite
                                                                                                                                                                                                                                            1. SQLiteDatabase db; db=SQLiteDatabase.openDatabase ("database.db", null, OPEN_READONLY);
                                                                                                                                                                                                                                              1. Best way: extend SQLiteOpenHelper
                                                                                                                                                                                                                                              2. Connect JDBC
                                                                                                                                                                                                                                                1. final String database= "jdbc:mysql://localhost:3306/"+ "mydb"; Connection db; db = DriverManager .getConnection(database, "myuser", "secretpassword");
                                                                                                                                                                                                                                              3. Issue query / execute SQL statement
                                                                                                                                                                                                                                                1. Query types
                                                                                                                                                                                                                                                  1. Insert (Create)
                                                                                                                                                                                                                                                    1. Query (Read)
                                                                                                                                                                                                                                                      1. Update (Update)
                                                                                                                                                                                                                                                        1. Delete (Delete)
                                                                                                                                                                                                                                                        2. Frequent queries can be "prepared"
                                                                                                                                                                                                                                                          1. Returns a "Cursor" for reading results
                                                                                                                                                                                                                                                          2. Why a "cursor"
                                                                                                                                                                                                                                                            1. Databases can be big
                                                                                                                                                                                                                                                              1. Result sets can be really big
                                                                                                                                                                                                                                                                1. Not all results can be stored/transferred in memory
                                                                                                                                                                                                                                                                  1. User might want to process results sequentially
                                                                                                                                                                                                                                                                  2. Query Android/SQLite
                                                                                                                                                                                                                                                                    1. static final String SQL="SELECT * FROM messages WHERE index=?"; Cursor result; result = db.rawQuery(SQL, new String[]{ Long.toString(index)});
                                                                                                                                                                                                                                                                    2. Query JDBC
                                                                                                                                                                                                                                                                      1. static final String SQL="SELECT * FROM messages WHERE index=?"; PreparedStatement stmt = db.prepareStatement(SQL); stmt.setInt(0, index); ResultSet result; result = stmt.executeQuery();
                                                                                                                                                                                                                                                                      2. Retrieve results
                                                                                                                                                                                                                                                                        1. Row by Row
                                                                                                                                                                                                                                                                          1. Generic, so "ugly"
                                                                                                                                                                                                                                                                            1. Can tell you columns names
                                                                                                                                                                                                                                                                              1. If you use wildcards, retrieve (and cache) column indices
                                                                                                                                                                                                                                                                                1. Don't forget to close result when finished
                                                                                                                                                                                                                                                                                2. Close connection
                                                                                                                                                                                                                                                                                  1. Release resources belonging to connection
                                                                                                                                                                                                                                                                                    1. Must be called for each connection
                                                                                                                                                                                                                                                                                      1. Database resources are expensive, reuse them, but close them when not needed for long time db.close();
                                                                                                                                                                                                                                                                                      2. Issues with databases
                                                                                                                                                                                                                                                                                        1. Used often to store user data
                                                                                                                                                                                                                                                                                          1. SQL is a language
                                                                                                                                                                                                                                                                                            1. Do not use string concatenation for variable parts
                                                                                                                                                                                                                                                                                              1. This is slower, database doesn't know it's the same query
                                                                                                                                                                                                                                                                                                1. This can be insecure (if the data is not from the program)
                                                                                                                                                                                                                                                                                              2. Android Cursors
                                                                                                                                                                                                                                                                                                1. Like ArrayAdapter, there is a CursorAdapter
                                                                                                                                                                                                                                                                                                  1. CursorAdapter can use any Cursor
                                                                                                                                                                                                                                                                                                    1. SQLiteCursors are Cursors
                                                                                                                                                                                                                                                                                                  Show full summary Hide full summary

                                                                                                                                                                                                                                                                                                  Similar

                                                                                                                                                                                                                                                                                                  10 Basic English Questions - Quiz 1
                                                                                                                                                                                                                                                                                                  Leo JC
                                                                                                                                                                                                                                                                                                  General Knowledge Quiz
                                                                                                                                                                                                                                                                                                  PatrickNoonan
                                                                                                                                                                                                                                                                                                  Chemistry Quiz General -3
                                                                                                                                                                                                                                                                                                  lauren_johncock
                                                                                                                                                                                                                                                                                                  The Heart
                                                                                                                                                                                                                                                                                                  annalieharrison
                                                                                                                                                                                                                                                                                                  AS Biology- OCR- Module 1 Cells Specification Analysis and Notes
                                                                                                                                                                                                                                                                                                  Laura Perry
                                                                                                                                                                                                                                                                                                  Unit 1: Business Studies GCSE
                                                                                                                                                                                                                                                                                                  Libby Rose
                                                                                                                                                                                                                                                                                                  The Digestive system
                                                                                                                                                                                                                                                                                                  Elena Cade
                                                                                                                                                                                                                                                                                                  Biology B1
                                                                                                                                                                                                                                                                                                  Kelsey Phillips
                                                                                                                                                                                                                                                                                                  Electrolysis
                                                                                                                                                                                                                                                                                                  lisawinkler10
                                                                                                                                                                                                                                                                                                  2PR101 1. test - 2. část
                                                                                                                                                                                                                                                                                                  Nikola Truong
                                                                                                                                                                                                                                                                                                  2PR101 1.test - 3. část
                                                                                                                                                                                                                                                                                                  Nikola Truong