Tuesday, March 24, 2015

10 difference between Java and JavaScript for Programmers

Programmers, developers and internet users  have always been confused between Java and JavaScript.  Many people still thinks that JavaScript is part of Java platform, which is not true. In truth, JavaScript has nothing to do with Java, only common thing between them is word "Java", much like in Car and Carpet, or Grape and Grapefruit. JavaScript is a client side scripting language for HTML, developed by Netscape, Inc, while Java is a programming language, developed by Sun Microsystems. James Gosling is Inventor of Java, popularly known as father of Java. While in today's world calling JavaScript just a client side scripting language would not be good, as its now been used in servers also using node.js and people are doing object oriented development in JavaScript, but that was what it was originally developed. There are several difference between Java and JavaScript, from how they are written, compiled and executed. Even capability of Java and JavaScript vary significantly. Java is full feature Object oriented programming language, used in almost everywhere, starting from programming credit card to server side coding. Android uses Java as programming language for creating Android apps, Swing is a Java API used to create desktop applications and Java EE is a Java platform for developing web and enterprise applications. On the other hand JavaScript is primarily used to bring interactivity into web pages, though there are other alternatives like Flash, JavaScript is the most popular one and regaining lots of ground lost earlier with introduction of powerful and easy to use libraries like jQuery and jQuery UI. You can use JavaScript to validate user input, create animation and cool effects in HTML page and can do lot of interactive stuff e.g. reacting on button click, mouse movement, image click etc. In this article, I will share some key differences between Java and JavaScript, mostly from a programmers perspective.


Difference between Java vs JavaScript

Here is my list of key differences between JavaScript and Java as programming languages. I have worked both on them, mainly used Java for all Server Side development, Android and JavaScript for writing client side scripts to do validation, interactivity, animation and ajax calls.
Difference between Java and JavaScript

1) Execution Environment

First difference between Java and JavaScript is that Java is compiled + interpreted language, Java code is fist compiled into class files containing byte code and than executed by JVM, on the other hand JavaScript code is directly executed by browser. One more difference which comes form this fact is that, Java is run inside JVM and needs JDK or JRE for running, on there other hand JavaScript runs inside browser and almost every modern browser supports JavaScript.



2) Static vs Dynamic Typed language

Another key difference between JavaScript and Java is that, JavaScript is a dynamic typed language, while Java is a statically typed language. Which means, variables are declared with type at compile time, and can only accept values permitted for that type, other hand variables are declared using vary keyword in JavaScript, and can accept different kinds of value e.g. Stringnumeric and boolean etc. When one variable or value is compared to other using == operator, JavaScript performs type coercion. Though it also provides === operator to perform strict equality check, which checks for type as well. See here for more differences between == and == operator in JavaScript.



3) Support of Closures

JavaScript supports closures, in form of anonymous function. In simple words, you can pass a function as an argument to another function. Java doesn't treat method as first class citizen and only way to simulate closure is by using anonymous class. By the  way Java 8 has brought real closure support in Java in form of lambda expression and this has made things much easier. It's very easy to write expressive code without much clutter in Java 8.



4) OOP

Java is an Object Oriented Programming language, and though JavaScript also supports class and object, it's more like an object oriented  scripting language. It's much easier to structure code of large enterprise application in Java then JavaScript. Java provides packages to group related class together, provides much better deployment control using JAR, WAR and EAR as well.



5) Right Once Run Anywhere

Java uses byte code to achieve platform independence, JavaScript directly runs on browser, but code written in JavaScript is subject to browser compatibility issue i.e. certain code which work in Mozilla Firefox, may not work in Internet Explorer 7 or 8. This is because of browse based implementation of JavaScript. This was really bad until jQuery comes. Its a JavaScript library which helps to free web developers from this browser compatibility issues. This is why I prefer to write code using jQuery rather than using plain old JavaScript code, even if its as simple as calling getElementById() or getElementByName() methods to retrieve DOM elements.



7) Block vs Function based Scoping

Java mainly uses block based scoping i.e. a variable goes out of scope as soon as control comes out of the block, unless until its not a instance or class variable. On the other hand JavaScript mainly uses function based scoping, a variable is accessible in the function they are declared. If you have a global variable and local variable with same name, local will take precedence in JavaScript.



8) Constructors

Java has concept of constructors, which has some special properties e.g. constructor chaining and ensuring that super class constructor runs before sub class, on the other hand JavaScript constructors are just another function. There is no special rules for constructors in JavaScript e.g. they cannot have return type or their name must be same as class.



9) NullPointerException

JavaScript is much more forgiving than Java, you don't have NullPointerException in JavaScript, your variable can accept different kinds of data because of JavaScript is dynamically typed language.



10) Applicability

Last but not the least, JavaScript has it's own space, sitting cozy along with HTML and CSS in Web development, while Java is everywhere. Though both has good number of open source libraries to kick start development, but jQuery has certainly brings JavaScript on fore front.


That's all on difference between Java and JavaScript language. As I said, they are totally different language, one is a general purpose programming language, while other is scripting language for HTML. Though you can do lot of fancy stuffs using JavaScript, you still don't have features like multithreading, as compared to Java. By the way JavaScript was originally named as Livescrpit, may be due to the fact that it makes your HTML pages live, and programming world would certainly be free of this confusion, had Netscape hadn't renamed LiveScript as JavaScript.

Read more: http://javarevisited.blogspot.com/2015/03/10-difference-between-java-and-javascript-programming.html#ixzz3VK4AAW1e

Sunday, March 1, 2015

Nested Loops


We have seen the advantages of using various methods of iteration, or looping.
Now let's take a look at what happens when we combine looping procedures. 
     The placing of one loop inside the body of another loop is called nesting.  When you "nest" two loops, the outer loop takes control of the number of complete repetitions of the inner loop.  While all types of loops may be nested, the most commonly nested loops arefor loops.

nested loops
    
Let's look at an example of nested loops at work.
We have all seen web page counters that resemble the one shown below ( well, OK, maybe not quite this spastic!!).  Your car's odometer works in a similar manner.
This counter (if it worked properly) and your car's odometer are little more than seven or eight nested for loops, each going from 0 to 9.  The far-right number iterates the fastest, visibly moving from 0 to 9 as you drive your car or increasing by one as people visit a web site.  A for loop which imitates the movement of the far-right number is shown below:
for(num1 = 0; num1 <= 9; num1++)
{
      cout << num1 << endl;
}
     The far-right number, however, is not the only number that is moving.  All of the other numbers are moving also, but at a much slower pace.  For every 10 numbers that move in the column on the right, the adjacent column is incremented by one.  The two nested loops shown below may be used to imitate the movement of the two far-right numbers of a web counter or an odometer:
The number of digits in the web page counter or the odometer determine the number of nested loops needed to imitate the process.
     
When working with nested loops, the outer loop changes only after the inner loop is completely finished (or is interrupted.).
Let's take a look at a trace of two nested loops.  In order to keep the trace manageable, the number of iterations have been shortened.
for(num2 = 0; num2 <= 3;  num2++)
{
      for(num1 = 0; num1 <= 2; num1++)
      {
            cout<< num2<< "   " << num1<< endl;
      }
}
       
MemoryScreen
int num2 int num1
00
1
2
3  end loop
10
1
2
3  end loop
20
1
2
3  end loop
30
1
2
3  end loop
4  end loop
    Remember, in the memory, for loops will register a value one beyond (or the step beyond) the requested ending value in order to disengage the loop.
0   0
0   1
0   2
1   0
1   1
1   2
2   0
2   1
2   2
3   0
3   1
3   2

Rectangle Example:

Write a code fragment that prints a length by height rectangle of *'s. For example, if length is 20 and height is 10, it should print:


********************
********************
********************
********************
********************
********************
********************
********************
********************
********************

Triangle Example:

Write a code fragment that prints a length by length right triangle of *'s. For example, if length is 8, it should print:


*
**
***
****
*****
******
*******
********

Diamond Example:

Write a code fragment that prints a diamond of *'s that is n wide at its widest. For example, if n is 10, it should print:


*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * *
* * * * * * * *
* * * * * *
* * *
* * * * * * * * * * *
*

Solutions

Rectangle Example: Write a code fragment that prints a length by height rectangle of *'s.










Triangle Example: Write a code fragment that prints a length by length right triangle of *'s.





Diamond Example: Write a code fragment that prints a diamond of *'s that is n wide at its widest.






System.out.println();
}

// print the lower pyramid
for (int row = n - 1; row > 0; row--) {

System.out.print(" ");
 for (int numStars = 0; numStars < row; numStars++)


Sunday, December 7, 2014

sliitexamz.blogspot.com is worth $ 84 - Worth Of Web Calculator

sliitexamz.blogspot.com is worth $ 84 - Worth Of Web Calculator


1. ඔබ පාරෙ ගමන් කරන විට, තනි පොලිස් නිලධාරියෙක්ට ඔබව නැවැත්වීමට තහනම්. එසේ නැවැත්වීමට උත්සාහ ගතහොත්, නොනවත්වා යාමට ඔබට හැකිය. 

2. තනි පොලිස් නිලධාරියෙකුහට ඔබේ රියදුරු බලපත්‍රය රඳවා ගැනීමට නොහැකිය. 

3. ඔබ වාහනයක ගමන් කරන විටකදී, ඔබේ ජාතික හැඳුනුම් පත හැර වෙනත් ලියකියවිලි ඉල්ලා සිටීමට අයිතිය ඇත්තේ රථ වාහන පාලක පොලිස් නිලධාරියෙකුට (Traffic Police) පමණි.

4. තනි රථ වාහන පාලක පොලිස් නිලධාරියෙකුට (Traffic Police) ඔබට දඩ ගැසීමට හෝ චෝදනා කිරීමට නොහැකිය. ඔහුට අනිවාර්යෙන්ම සාක්ෂිකරුවෙකු අවශ්‍ය වේ. සාක්ෂිකරු පොලිස් නිලධාරියෙකුම විය යුතුයි. (එබැවින් සැමවිටම පාරේ රථ වාහන පාලක පොලිස් නිලධාරින් දෙන්නෙක් එකට සිටියි)

5. පොලිස් නිලධාරියෙකු ඔබට බීමතින් රිය පැදවූ බවට චෝදනා කලහොත්, බැලූන් පරීක්ෂාව (Balloon Test) කිරීමට ඉල්ලා සිටිය හැක. ඒ අවස්ථාවේදී ඔවුන් සතුව බැලූන් නොමැති නම්, ඔබට යාමට අවසර ඇත.

6. මහ මග ගමන් ගන්නා වාහනයක් නැවැත්වීමට අවසර ඇත්තේ රථ වාහන පාලක පොලිස් නිලධාරියෙකුට (Traffic Police) පමණයි.(ඒ බැවින් හමුදා මුරපොල (check point) වල එක පොලිස් නිලධාරියෙක් හෝ සිටිය යුතුය.)

7. පොලිස් නිලධාරියෙකුට ලිඛිත උසාවි නියෝගයක් නොමැතිව ඔබේ නිවසට හෝ රැකියා ස්ථානයට ඇතුළු විය නොහැක. ලිඛිත නියෝගය ඉල්ලා සිටීමට ඔබට සියලු අයිතිය ඇත. ඔවුන් බලෙන් ඇතුලු වීමට සැරසෙයිනම් එයට විරුද්ධ වීමට ඔබට අයිතිය ඇත.

8. ඔබ සිදුකල වැරැද්දේ ස්වභාවයත්, දණ්ඩ නීති සංග්‍රහය අනුව අදාල නීති උල්ලංගනය කිරීමත් පිලිබඳව කියන තුරු රථ වාහන පාලක පොලිස් නිලධාරියෙකුට (Traffic Police) ට ඔබේ රියදුරු බලපත්‍රය ලබාගත නොහැකිය. එසේ සඳහන් කිරීමට අපොහොසත් වන්නේ නම් ඔබට යාමට අවසර ඇත.

9.රථ වාහන පාලක පොලිස් නිලධාරියෙකු (Traffic Police) ඔබේ බලපත්‍රය බලෙන් ලබාගෙන, එය නැවත ලබා ගැනීමට පොලිස් ස්ථානයට එන ලෙස පැවසූ විටක, එලෙස නොගොස් පොලිස් අධිකාරියතුමන්ට හෝ ප්ප්‍රදේශිකයට අදාල නියෝජ්‍ය පොලිස්පතිතුමන්ට පැමිණිලි කිරීමට ඔබට අයිතිය පවතී. එවිට අදාල නිලධාරියාව, දුරාචාරය සහ නොහික්මුණු හැසිරීම යන වරද මත පදනම්ව සේවයෙන් පහ කරවීමට වුවද හැකියාව පවතී.

10. කාන්තාවකගෙන්,පොලිස් නිලධාරියෙකු නම, ලිපිනය, හැඳුනුම් පත, දුරකථන අංකය ඉල්ලා සිටී නම් ඒ ඉල්ලීම ඉටු නොකිරීමට අයිතිය ඇත (ඔහු ඔබට හිරිහැර කිරීමේ අරමුණින් සිටින බව ඔබට හැඟේ නම් පමණක්). ඔහුට ඔබව (කාන්තාව) අත් අඩංගුවට ගැනීමට නොහැක. ඔබට පොලිස් නිලධාරිනියකගේ සහය ඉල්ලා සිටීමට අයිතිය ඇත.

11.පොලිස් නිලධාරියෙකු කාන්තාවක් පරීක්ෂා කිරීමට බව පැවසූ විටක, එය පොලිස් නිලධාරිණියක ලවා කරවා ගැනීමට ඔබට (කාන්තාව) අයිතිය ඇත. පොලිස් කාන්තාවක් නොමැති නම්, ඔබට එය ප්‍රතික්ෂේප කිරීමට අයිතිය ඇත.

12. ඔබට අධික වේගයෙන් වාහනය පැදවීමේ වරදට දඩ ගැසීමට හෝ නඩු දැමීමට සැරසෙයි නම් ඊට ප්‍රථම වාහනයේ වේගය මනින ලද මීටරයේ වේගය සටහන් වී ඇති අයුරු තමාට පෙන්වන ලෙස ඉල්ලා සිටීමට අයිතිය ඇත. (බොහොමයක් පොලිසිවල පවතින වේග මීටර අක්‍රිය අතර ඔවුන් හුදෙක් මීටරය දිගුකර අනුමානයෙන් වරදකරුවන් අසුකරගනී)

13. ඔබ කිසියම් කරුණක් මත අත් අඩංගුවට පත්ව සිටිනම් පොලිසියට ප්‍රකාශ ඉදිරිපත් කිරීමට ප්‍රථම නීතිඥයෙකුගේ උපදෙස් ලබාගැනීමට ඔබට අයිතියක් පවතී. එනිසා එවැනි අවස්ථාවල ඔබට නීතිඥයෙකු ඉල්ලා සිටීය හැකිය.

ඔබට නීතිමය කරුණක් ගැන තවදුරටත් තොරතුරු ලබාගැනීමට අවශ්‍ය නම් නීති ආධාර කොමිෂන් සභාව ,අංක 1295,මහාධිකරණ සංකීර්ණය,අළුත්කඩේ,කොළඔ 12. යන ලිපිනයට ලිවීමෙන් හෝ 0094-11-2433618, 0094-11-5335329, 0094-11-5335281, 0094-011-2395894 යන අංක වලට ඇමතීමෙන් තොරතුරු ලබාගත හැකිය.

--share කිරීම වැදගත්--

උපුටාගැනීමකි..

Monday, November 24, 2014




 ..ඔයාලගේ computer වල සමහර වෙලාවට,සමහර game ,software open කරද්දී පල්ලෙහා පින්තුරේ තියෙනවා වගේ eror message එකක් එනවා නේද බලන්නකෝ ටිකක් රූපේ දිහා  . .



ඉතින් මන් දැන් කියන්න හදන්නේ මේක හදාගන්න විදිහ ගැන  .. මුලින්ම මේ path එකට යන්නකෝ  ..
My Computer > Write click > Advanced System Setting > 





දැන් ඔකේ මුලින්ම තියෙන්නේ Perfomance කියලා  .. එකේ තියන setting කියන එක click කරන්න  ..




දැන් පල්ලෙහා විදිහේ dailog එකක් ආවනේ  . . ඔකේ තුන්වන එකට යන්න  . .(Data Execution prevention)




ඊළගට පල්ලෙහා රූපේ විදිහට කරන්න  . .




Add click කරට පස්සේ පල්ලෙහා තියන විදිහේ එකක් එනවනේ  . .එකෙන් ඔයාලගේ වැඩ කරන්නේ නැති install කරපු software එක හොයාගෙන එක select කරලා ok කරන්න. . .


දැන් අනිත් application එකත් ok කරලා සේරගෙන්ම අයින් වෙලා ඔයාල ඔතනට දුන්න  open කරන්න බැරි software එක open කරලා බලන්නකෝ  .

Sunday, October 12, 2014

ARP and RARP-- The Address Resolution Protocols

ARP and RARP-- The Address Resolution Protocols

ARP  --Address Resolution Protocol

What is it for:  Arp translates IP numbers into hardware addresses.
How ARP works:  Send a packet from the querrying host with an Ethernet  broadcast address asking the target host with the given IP address to respond.  All hosts on the physical network receive this packet, and the one with the given IP number responds.  Then the original querring host knows the physical address of the target host.   Does not use IP; uses's physical frames.
Common ARP improvements:  Keep a cache of recently received translations.  Remember that these addresses are quite small, and the space needed to store them is also small. Store both the physical and IP addresses of all ARP broadcasting hosts.  Then every host who receives a broadcast ARP request can know the address translation of the sender.  This is especially imporant for the receiver of the broadcast.
How to Write ARP Software:    There are two parts.  The first part uses the cache to map IP -> physical addresses.  The second part fills the cache with mapping upon request from the first part.
Security:  Can you fool ARP software.  Yes, by poluting the network with your own answers.
Interesting question:  To send machine A some data, you broadcast seeking machine A.  Would it not be easier just to broadcast the data.  That would for sure reduce the total number of packets sent, at the cost of changing many unicasts to broadcasts.  What if someone answers an ARP request for you, and lies about who they are?  Who answers an ARP for a machine

RARP -- Reverse Address Resolution Protocol

What is it for:  Diskless clients don't have a place to store there IP number.  Rarp translates machines addresses into IP numbers.
How RARP works:  The client broadcasts a RARP packet with an ethernet broadcast address, and it's own physical address in the data portion.  The server responds by telling the client it's IP address.  Note there is no name sent.  Also note there is no security.  Does not use IP; uses's physical frames.
Common RARP improvements:  Don't let an RARP client retry indefinitlly.  That just causes wasted broadcasts.  Have a backup RARP server or two, on random time delays.
Interesting Question:  When should the server broadcast the answer instead of target it?  What gets put in the rest of the packet (since there is a large minimum packet length?

BOOTP -- The Bootstrapping Protocol

What is it for:  Diskless clients don't have a place to store there IP number.  Bootp translates machines addresses into IP numbers.  Because it uses IP packets, application level programmers can write bootp servers.
How BOOTP works:  The client broadcasts a BOOTP packet with source and destination IP broadcast addresses (all 1's), and it's own physical address in the data portion.  The server responds by telling the client it's actual IP address, and some other info (see page 368).  Note that the server must also send to a broadcast address, since there is no IP-> physical address mapping in the server's ARP cache yet, and the client won't yet respond to ARP requests (since it does not yet recognize it's IP address).
The Boot file:  BOOTP sends a suggested file server and file name to the client.  The client can then use anbother protocol (TFTP?) to retrieve that file, and boot using the resulting image.
Vendor Specific Area:  Can contain anything, but often time of day, dns server name, printer IP address,  and such.
Advantages over RARP:   Carries more info in the reply.

DHCP -- The Dynamic Host Configuration Protocol

What is it for:  Allows hosts to dynamically get a unique  IP number on each bootup.  Allows more hosts than IP numbers, as long as the total number of hosts up at any one time does not exceed the number of IP addresses available.  Further, DHCP provides more info (like netmask) than bootp.  Finally, it can take the IP addres back when no longer needed. 

Saturday, August 30, 2014

Difference between TCP vs UDP Protocol

TCP and UDP are two transport layer protocols, which are extensively used in internet for transmitting data between one host to another. Good knowledge of how TCP and UDP works is essential for any programmer. That's why difference between TCP and UDP is one of the most popular programming interview question. I have seen this question many times on various Java interviews , especially for server side Java developer positions. Since FIX (Financial Information Exchange) protocol is also a TCP based protocol, several investment banks, hedge funds, and exchange solution provider looks for Java developer with good knowledge of TCP and UDP. Writing fix engines and server side components for high speed electronic trading platforms needs capable developers with solid understanding of fundamentals including data structure, algorithms and networking. By the way, use of TCP and UDP is not limited to one area, its at the heart of internet. The protocol which is core of internet, HTTP is based on TCP. One more reason, why Java developer should understand these two protocol in detail is that Java is extensively used to write multi-threaded, concurrent and scalable servers. Java also provides rich Socket programming API for both TCP and UDP based communication. In this article, we will learn key differences between TCP and UDP protocol, which is useful to every Java programmers. To start with, TCP stands for Transmission Control Protocol and UDP stands for User Datagram Protocol, and both are used extensively to build Internet applications.




Difference between TCP vs UDP Protocol

I love to compare two things on different points, this not only makes them easy to compare but also makes it easy to remember differences. When we compare TCP to UDP, we learn difference in how both TCP and UDP works, we learn which provides reliable and guaranteed delivery and which doesn't. Which protocol is fast and why, and most importantly when to choose TCP over UDP while building your own distributed application. In this article we will see difference between UDP and TCP in 9 points, e.g. connection set-up, reliability, ordering, speed, overhead, header size, congestion control, application, different protocols based upon TCP and UDP and how they transfer data. By learning these differences, you not only able to answer this interview question better but also understand some important details about two of the most important protocols of internet.


1) Connection oriented vs Connection less
TCP handshake process SYN, SYN-ACK and ACK
First and foremost difference between them is TCP is a connection oriented protocol, and UDP is connection less protocol. This means  a connection is established between client and server, before they can send data. Connection establishment process is also known as TCP hand shaking where control messages are interchanged between client and server. Attached image describe the process of TCP handshake, for example which control messages are exchanged between client and server. Client, which is initiator of TCP connection, sends SYN message to server, which is listening on a TCP port. Server receives and sends a SYN-ACK message, which is received by client again and responded using ACK. Once server receive this ACK message,  TCP connection is established and ready for data transmission. On the other hand, UDP is a connection less protocol, and point to point connection is not established before sending messages. That's the reason, UDP is more suitable for multicast distribution of message, one to many distribution of data in single transmission.


2) Reliability
TCP provides delivery guarantee, which means a message sent using TCP protocol is guaranteed to be delivered to client. If message is lost in transits then its recovered using resending, which is handled by TCP protocol itself. On the other hand, UDP is unreliable, it doesn't provide any delivery guarantee. A datagram package may be lost in transits. That's why UDP is not suitable for programs which requires guaranteed delivery.


3) Ordering
Apart from delivery guarantee, TCP also guarantees order of message. Message will be delivered to client in the same order, server has sent, though its possible they may reach out of order to the other end of the network. TCP protocol will do all sequencing and ordering for you. UDP doesn't provide any ordering or sequencing guarantee. Datagram packets may arrive in any order. That's why TCP is suitable for application which need delivery in sequenced manner, though there are UDP based protocol as well which provides ordering and reliability by using sequence number and redelivery e.g. TIBCO Rendezvous, which is actually a UDP based application.


4) Data Boundary
TCP does not preserve data boundary, UDP does. In Transmission control protocol, data is sent as a byte stream, and no distinguishing indications are transmitted to signal message (segment) boundaries. On UDP, Packets are sent individually and are checked for integrity only if they arrived. Packets have definite boundaries which are honoured upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent. Though TCP will also deliver complete message after assembling all bytes. Messages are stored on TCP buffers before sending to make optimum use of network bandwidth.


5) Speed
In one word, TCP is slow and UDP is fast. Since TCP does has to create connection, ensure guaranteed and ordered delivery, it does lot more than UDP. This cost TCP in terms of speed, that's why UDP is more suitable where speed is a concern, for example online video streaming, telecast or online multi player games.


6) Heavy weight vs Light weight
Because of the overhead mentioned above, Transmission control protocol is considered as heavy weight as compared to light weight UDP protocol. Simple mantra of UDP to deliver message without bearing any overhead of creating connection and guaranteeing delivery or order guarantee keeps it light weight. This is also reflected in their header sizes, which is used to carry meta data.


7) Header size
TCP has bigger header than UDP. Usual header size of a TCP packet is 20 bytes which is more than double of 8 bytes, header size of UDP datagram packet. TCP header contains Sequence Number, Ack number, Data offset, Reserved, Control bit, Window, Urgent Pointer, Options, Padding, Check Sum, Source port, and Destination port. While UDP header only contains Length, Source port, Destination port, and Check Sum. Here is how TCP and UDP header looks like :

TCP Header Format


UDP Header Format 



8) Congestion or Flow control
TCP does Flow Control. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control. On the other hand, UDP does not have an option for flow control.


9) Usage and application
Where does TCP and UDP are used in internet? After knowing key differences between TCP and UDP, we can easily conclude, which situation suits them. Since TCP provides delivery and sequencing guaranty, it is best suited for applications that require high reliability, and transmission time is relatively less critical. While UDP is more suitable for applications that need fast, efficient transmission, such as games. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients. In practice, TCP is used in finance domain e.g. FIX protocol is a TCP based protocol, UDP is used heavily in gaming and entertainment sites.


10) TCP and UDP based Protocols
One of the best example of TCP based higher end protocol is HTTP and HTTPS, which is every where on internet. In fact most of the common protocol you are familiar of e.g. Telnet, FTP and SMTP all are based over Transmission Control Protocol. UDP don't have any thing as popular as HTTP but UDP is used in protocol like DHCP (Dynamic Host Configuration Protocol) and DNS (Domain Name System). Some of the other protocol, which is based over User Datagram protocol is Simple Network Management Protocol (SNMP), TFTPBOOTP and NFS (early versions).


That's all about difference between TCP and UDP protocol. Always remember to mention that TCP is connection oriented, reliable, slow, provides guaranteed delivery and preservers order of messages, while UDP is connection less, unreliable, no ordering guarantee, but fast protocol. TCP overhead is also much higher than UDP, as it transmits more meta data per packet than UDP. It's worth mentioning that header size of Transmission control protocol is 20 bytes, compared to 8 bytes header of User Datagram protocol. Use TCP, if you can't afford to lose any message, while UDP is better for high speed data transmission, where loss of single packet is acceptable e.g. video streaming or online multi player games. While working in TCP/UDP based application on Linux, it's also good to remember basic networking commands e.g. telnet and netstat, they help tremendously to debug or troubleshoot any connection issue.

Read more: Click Here

OAuth authorization server