Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Lecture 15: I/O and Parsing
Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.
 2005 Pearson Education, Inc. All rights reserved Introduction.
USING ANDROID WITH THE INTERNET. Slide 2 Network Prerequisites The following must be included so as to allow the device to connect to the network The.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
CSCI 4550/8556 Computer Networks Comer, Chapter 3: Network Programming and Applications.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
16: Distributed Systems1 DISTRIBUTED SYSTEM STRUCTURES NETWORK OPERATING SYSTEMS The users are aware of the physical structure of the network. Each site.
Software design and development Marcus Hunt. Application and limits of procedural programming Procedural programming is a powerful language, typically.
Streams and File I/O Chapter 14. I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
JavaScript & jQuery the missing manual Chapter 11
CS378 - Mobile Computing Web - WebView and Web Services.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Networking Android Club Networking AsyncTask HttpUrlConnection JSON Parser.
CS378 - Mobile Computing Web - WebView and Web Services.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 Dr Alexiei Dingli XML Technologies XML Advanced.
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
1 Web Based Programming Section 8 James King 12 August 2003.
Data Persistence Nasrullah Niazi. Share Preferences The SharedPreferences class provides a general framework that allows you to save and retrieve persistent.
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
MAKANI ANDROID APPLICATION Prepared by: Asma’ Hamayel Alaa Shaheen.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
Android networking 1. Network programming with Android If your Android is connected to a WIFI, you can connect to servers using the usual Java API, like.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
1 Software. 2 What is software ► Software is the term that we use for all the programs and data on a computer system. ► Two types of software ► Program.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Recap of Part 1 Terminology Windows FormsAndroidMVP FormActivityView? ControlViewView? ?ServiceModel? Activities Views / ViewGroups Intents Services.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Review IS Overview: Data  Inside the application Collections  Outside the application Database XML  Getting/displaying Swing  Communicating.
1 Validation SAX-DOM. Objectives 2  Schema Validation Framework  XML Validation After Transformation  Workshops.
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
REEM ALMOTIRI Information Technology Department Majmaah University.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Small talk with the UI thread
Reactive Android Development
Lesson One – Creating a thread
Objectives You should be able to describe: Interactive Keyboard Input
SOFTWARE DESIGN AND ARCHITECTURE
WebView and Web Services
University of Central Florida COP 3330 Object Oriented Programming
Application with Cross-Platform GUI
I/O Basics.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Android Topics UI Thread and Limited processing resources
Android Topics Asynchronous Callsbacks
Android Developer Fundamentals V2
CS 240 – Advanced Programming Concepts
Applet Fundamentals Applet are small applications that are accessed on an Internet server, transported over the Internet, automatically installed and run.
XML Parsers.
Chapter 4: Threads.
Extensible Markup Language (XML)
Presentation transcript:

Networking Nasrullah

Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()), or from an in-memory byte array (ByteArrayInputStream).FileInputStreamgetInputStream() ByteArrayInputStream Use InputStreamReader to adapt a byte stream like this one into a character stream.InputStreamReader Most clients should wrap their input stream with BufferedInputStream. Callers that do only bulk reads may omit buffering. BufferedInputStream

InputStream::read reads a single byte and returns it as an int InputStreamReader::read reads a single char (respecting the encoding) and returns this as an int If you want to read binary data use InputStream If you want to read strings from a binary stream, use InputStreamReader. One of its constructors allows you to specify a character set.

Whole story of Streaming in java An inputStreamReader is a bridge from bytesStream to character stream ; it reads bytes and decodes them into characters.it usually is wrapped inside a BufferReader.

Web services We have to work on two types of web services A.REST B.SOAP The web services can response in one of the following way XML SOAP JSON

Parsing xml Android offers three types of XML parsers DOM Parser Pull Parser SAX Parser

Parsing with DOM parser

Web services tService.asmx?op=Define

What is mean by Parsing Parsing usually applies to text - the act of reading text and converting it into a more useful in- memory format, "understanding" what it means to some extent. So for example, an XML parser will take the sequence of characters (or bytes) and convert them into elements, attributes etc. In some cases (particularly compilers) there's a separation between lexical analysis and syntactic analysis, so the real "understanding" part of the parser works on a sequence of tokens (identifiers, operators etc) rather than on the raw characters.lexical analysis

Document Class The Document interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data. Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the Document interface also contains the factory methods needed to create these objects. The Node objects created have a ownerDocument attribute which associates them with the Document within whose context they were created.

DocumentBuilderFactory class Defines a factory API that enables applications to obtain a parser that produces DOM object trees from XML documents

Processes and Thread

Threads If you are familiar with the “Thread” term, it's easy to understand. Android applications have a main thread where all is processed. It's like having “OneTask” that does everything. If we had only this UI Thread to work with, you would not be able to do some things like, storing 10,000 data rows in the application at the same time you are using it. The application would stick, until the process “store 10,000 data rows” was finished. But, this is not the case! In Android you can have multiple threads running at the same time in one application. The UI Thread, allows you to move through the screen, while, for example, a background task is receiving data from a server and storing it in the database

Async Tasks As we are aware that any User interaction on any Android application should and must response with in 5 seconds, failure to which results in ANR Dialog. Yes "Application Not Responding" Dialog with 'Wait' and 'Force Close' inputs. Asynchronous operations can also be performed using Threads in accordance with Handler and messages to update UI about the action progress.

problem If you perform a long lasting operation, e.g. loading a file or accessing data from the Internet, the user interface of your Android Application will block until the corresonding code has finished.

Multithreading Multithreaded GUI (graphical user interface)- based programs remain responsive to users while performing other tasks, such as repaginating or printing a document. Threaded programs typically finish faster than their nonthreaded counterparts. This is especially true of threads running on a multiprocessor machine, where each thread has its own processor

Hints Do not call the methods onPreExecute, doInBackground and onPostEx ecute manually. This is automatically done by the system. You cannot call an AsyncTask inside another AsyncTask or Thread. The call of the method execute must be done in the UI Thread. The method onPostExecute is executed in the UI Thread (here you can call another AsyncTask!). The input parameters of the task can be an Object array, this way you can put whatever objects and types you want.

doInBackGround() public void makeLemonade(String[] args) {and public void makeLemonade(String... args) {the code inside the method would be the same, but when it was called, they would be called differently. The first would need to be called like this: makeLemonade(new String[]{"lemon1", "lemon2", "lemon3"});while the second one's method signature could have 0 to (an assumed)infinite number of arguments, but they would all need to be String arguments. All of the following calls would work: makeLemonade("lemon1"); makeLemonade("lemon4", "lemon7", "lemon11", "lemon12");

IntentService Class It is important to note that once your service has finished executing a task, it should be stopped as soon as possible so that it does not unnecessarily hold up valuable resources. That’s why you use the stopSelf() method to stop the service when a task has been completed. Unfortunately, a lot of developers often forgot to terminate the service when it is done performing its task. To easily create a service that runs a task asynchronously and terminates itself when it is done, you can use the IntentService class

IntentService class (continued--) IntentService class is a base class for service that handles asynchronously requests on demand it is started just like a normal service and it executes its tasks within a worker thread and terminates itself when task is completed