Showing posts with label Basic CS knowledge. Show all posts
Showing posts with label Basic CS knowledge. Show all posts

Sunday, February 12, 2012

HTTP and more

HTTP:
connectionless and stationless
each request requires its own connection.
it has no memory of prior connections.

GET method. containing no body content, a GET request is comprised of only a method statement and various request header fields
GET /login.html HTTP/1.1
User-Agent ...
Even though a GET request does not send any information in the body of the message, data can still be pased as part of the GET statement itself
GET /login.html?username=dustin&...
GET method is normally used to request static data.
conditional GET: if a GET request includes and IF-Modified-Since
http servers tranditionally store GET parameters in system environment variables that can be accessed by CGI programs.

POST Method
is commonly used for passing user input to the server. all the info is stored in the body of the request rather than in the URL portion of the method statement.
advantages: info is not visible in the URL and there is no limit to the amount of information that can be passed.
POST /login.html http:/1.1
more header info

(in the body) username=dustin&...

basic authentication:
GET /salary.html HTTP/1.0
Authorization: Basic TATATATTTT (BASE64 encoding of the username and password)

MIME
Multipurpose Internet Mail Extensions

Saturday, February 11, 2012

Web Basics

URI:Uniform Resource Identifer
is a term referring to any specification that identifies an object on the internet. there are two types URIs--URL(Uniform Resource Locator) and Uniform Resource Name.

URL is a specification for identifying an object, such as a file, newsgroup,CGI program by indicating its exact location on the internet.
URN is a method for referencing an object without declaring the full path to the object. rather by its location, a resource is referenced by its an alias. in case the resource is removed, all there are multiple copies on different servers in different parts of the world. when a request is made for a URN, the browser could locate the nearest copy of the resource and return it. URN is not supported by most software.

format
http://host[:port]/path/resource_name[#section][?query_string]
ftp://username:password@host[:port]/path
try{
url=new URL("http://yahoo.com/index.html")
}
catch(MalformedURLException e){
}

BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

String nextLine = in.readLine

this return html files

absolute URL
relative URL

URL encoding:
URLs are comprised of a string of printable characters within ASCII coded character set. Any unsafe or nonprintable characters within a URL must be encoded. URL encoding involves replacing those characters with % followed by two hexadecimal digits corresponding to the character's ASCII value.
%20 is space, but it is so common, it is encoded as a single plus +
then + itself is encoded as %2B

Java includes a class to help convert resource names and other references into URL safe strings
URLEncoder.encode(string)

Web browser: is a client application that requests, receives, and displays HTML tags
web server is also called httpserver, responds to requests from a web browser by returning html,images ..also responsible for enforcing security polices, logging , cach
simple web server implementation
ServerSocket serverConnect ServerSocket(port); listen on port
HttpServer server = new HttpServer(serverConnect.accept())

CGI: common Gateway Interface
is a standard interface between an HTTP server and an application.CGI enables the Web server to generate dynamic content rather than just return static HTML files.In addition, because CGI can accept and process information submitted by the user,it can provide two way interaction between the client and the web server.


Thursday, February 2, 2012

heap vs stack

http://www.maxi-pedia.com/what+is+heap+and+stack

very good article about heap and stack

What is stack?

The two sections other from the code segment in the memory are used for data. The stack is the section of memory that is allocated for automatic variables within functions.

Data is stored in stack using the Last In First Out (LIFO) method. This means that storage in the memory is allocated and deallocated at only one end of the memory called the top of the stack. Stack is a section of memory and its associated registers that is used for temporary storage of information in which the most recently stored item is the first to be retrieved.

What is heap?

On the other hand, heap is an area of memory used for dynamic memory allocation. Blocks of memory are allocated and freed in this case in an arbitrary order. The pattern of allocation and size of blocks is not known until run time. Heap is usually being used by a program for many different purposes.

The stack is much faster than the heap but also smaller and

Monday, January 30, 2012

What is Virtual Memory

http://computer.howstuffworks.com/question684.htm

Virtual memory is a common part of most operating systems on desktop computers. It has become so common because it provides a big benefit for users at a very low cost.

Most computers today have something like 64 or 128 megabytes of RAM (random-access memory) available for use by the CPU (central processing unit). Often, that amount of RAM is not enough to run all of the programs that most users expect to run at once. For example, if you load the Windows operating system, an e-mail program, a Web browser and word processor into RAM simultaneously, 64 megabytes is not enough to hold it all. If there were no such thing as virtual memory, your computer would have to say, "Sorry, you cannot load any more applications. Please close an application to load a new one." With virtual memory, the computer can look for areas of RAM that have not been used recently and copy them onto thehard disk. This frees up space in RAM to load the new application. Because it does this automatically, you don't even know it is happening, and it makes your computer feel like is has unlimited RAM space even though it has only 32 megabytes installed. Because hard-disk space is so much cheaper than RAM chips, virtual memory also provides a nice economic benefit.

The area of the hard disk that stores the RAM image is called a page file. It holds pages of RAM on the hard disk, and the operating system moves data back and forth between the page file and RAM. (On a Windows machine, page files have a .SWP extension.)

Of course, the read/write speed of a hard drive is much slower than RAM, and the technology of a hard drive is not geared toward accessing small pieces of data at a time. If your system has to rely too heavily on virtual memory, you will notice a significant performance drop. The key is to have enough RAM to handle everything you tend to work on simultaneously. Then, the only time you "feel" the slowness of virtual memory is in the slight pause that occurs when you change tasks. When you have enough RAM for your needs, virtual memory works beautifully. When you don't, the operating system has to constantly swap information back and forth between RAM and the hard disk. This is called thrashing, and it can make your computer feel incredibly slow.