15 Coffee Nio, Socket, In Addition To Networking Interview Questions Answers

Networking as well as Socket Programming is i of the of import surface area of Java programming language, particularly for those programmers, who are working inwards customer server based applications. Knowledge of of import protocols e.g. TCP as well as UDP inwards particular is rattling important, particularly if you lot are inwards occupation organisation of writing high frequency trading application, which communicate via FIX Protocol or native central protocol. In this article, nosotros volition some of the frequently asked questions on networking as well as socket programming, mostly based roughly TCP IP protocol. This article is kinda calorie-free on NIO though, as it doesn't include questions from multiplexing, selectors, ByteBuffer and FileChannel but it does include classical questions similar difference betwixt IO as well as NIO. Main focus of this transportation service is to brand Java developer familiar amongst depression marker parts e.g. how TCP as well as UDP protocol works, socket options as well as writing multi-threaded servers inwards Java. Questions discussed hither is non actually tied upwards amongst Java programming language, as well as tin hold out used inwards whatsoever programming language, which allows programmers to write client-server applications. By the way, If you lot are going for interview on Investment banks for total Java developer role, you lot improve prepare good on Java NIO, Socket Programming, TCP, UDP as well as Networking along amongst other pop topics e.g. multi-threadingCollections API and Garbage Collection tuning. You tin also contribute whatsoever question, which is asked to you lot or related to socket programming as well as networking as well as tin hold out useful for Java interviews.



Java Networking as well as Socket Programming Questions Answers

Here is my listing of xv interview questions related to networking basics, cyberspace protocol as well as socket programming inwards Java. Though it doesn't comprise basic questions shape API e.g. Server, ServerSocket, but it focus on high marker concept of writing scalable server inwards Java using NIO selectors as well as how to implement that using threads, in that place limitations as well as issues etc. I volition in all likelihood add together few to a greater extent than questions based on some best practices spell writing socket based application inwards Java. If you lot know a adept query on this topic, experience gratis to suggest.



1) Difference betwixt TCP as well as UDP protocol?
There are many differences betwixt TCP (Transmission command Protocol) as well as UDP (User Datagram Protocol), but chief is TCP is connexion oriented, spell UDP is connexion less. This agency TCP provides guaranteed delivery of messages inwards the club they are sent, spell UDP doesn't supply whatsoever delivery guarantee. Because of this guarantee, TCP is slower than UDP, as it needs to perform to a greater extent than work. TCP is best suited for message, which you lot can't afford to loss, e.g. club as well as merchandise messages inwards electronic trading, wire transfer inwards banking as well as finance etc. UDP is to a greater extent than suited for media transmission, where loss of i packet, known as datagrams is affordable as well as doesn't acquit upon character of service. This reply is plenty for most of the interviews, but you lot demand to hold out to a greater extent than detailed when you lot are interviewing as Java developer for high frequency trading desk. Some of the points which many candidate forget to refer is nigh order and data boundary. In TCP, messages are guaranteed to hold out delivered inwards the same club as they are sent but information boundary is non preserved, which agency multiple messages tin hold out combined as well as sent together, or receiver may have i business office of the message inwards i packet as well as other business office of the message inwards side past times side packet. Though application volition have total message as well as inwards the same order. TCP protocol volition do assembling of message for you. On the other hand, UDP sends total message inwards a datagram packet, if clients receives the packet it is guaranteed that it volition larn the total message, but in that place is no guarantee that packet volition come upwards inwards same club they are sent. In short, you lot must refer next differences betwixt TCP as well as UDP protocol spell answering during interview :

  • TCP is guaranteed delivery, UDP is non guaranteed.
  • TCP guarantees club of messages, UDP doesn't.
  • Data boundary is non preserved inwards TCP, but UDP preserves it.
  • TCP is slower compared to UDP.

for to a greater extent than detailed answer, come across my transportation service 9 differences betwixt TCP as well as UDP protocol.


2) How does TCP handshake works?
Three messages are exchanged as business office of TCP head-shake e.g. Initiator sends SYN,  upon receiving this Listener sends SYN-ACK, as well as in conclusion initiator replied amongst ACK, at this betoken TCP connexion is moved to ESTABLISHED state. This procedure is easily understandable past times looking at next diagram.

 Networking as well as Socket Programming is i of the of import surface area of Java programming langua xv Java NIO, Socket, as well as Networking Interview Questions Answers








3) How do you lot implement reliable transmission inwards UDP protocol?
This is unremarkably follow-up of previous interview question. Though UDP doesn't supply delivery guarantee at protocol level, you lot tin innovate your ain logic to keep reliable messaging e.g. past times introducing sequence numbers as well as retransmission. If receiver divulge that it has missed a sequence number, it tin inquire for replay of that message from Server. TRDP protocol, which is used Tibco Rendezvous (a pop high speed messaging middle-ware) uses UDP for faster messaging as well as provides reliability guarantee past times using sequence number as well as retransmission.


4) What is Network Byte Order? How does 2 host communicate if they have got dissimilar byte-ordering?
There are 2 ways to shop 2 bytes inwards memory, piddling endian (least meaning byte at the starting address) as well as large endian (most meaning byte at the starting address). They are collectively known as host byte order. For example, an Intel processor stores the 32-bit integer as 4 consecutive bytes inwards retentiveness inwards the club 1-2-3-4, where 1 is the most meaning byte. IBM PowerPC processors would shop the integer inwards the byte club 4-3-2-1. Networking protocols such as TCP are based on a specific network byte order, which uses big-endian byte ordering. If 2 machines are communicating amongst each other as well as they have got dissimilar byte ordering, they are converted to network byte club earlier sending or afterward receiving. Therefore, a piddling endian micro-controller sending to a UDP/IP network must swap the club inwards which bytes appear inside multi byte values earlier the values are sent onto the network, as well as must swap the club inwards which bytes appear inwards multi byte values received from the network earlier the values are used. In short, you lot tin also say network byte club is criterion of storing byte during transmission, as well as it uses large endian byte ordering mechanism.


5) What is Nagle's algorithm?
If interviewer is testing your cognition of TCP/IP protocol than it's rattling rare for him non to inquire this question. Nagle's algorithm is way of improving performance of TCP/IP protocol as well as networks past times reducing number of TCP packets that needs to hold out sent over network. It plant past times buffering modest packets until buffer reaches Maximum Segment Size. Since modest packets, which contains alone 1 or 2 bytes of data, has to a greater extent than overhead inwards price of TCP header, which is of xl bytes. These modest packets tin also leads to congestion inwards ho-hum network. Nagle's algorithm tries to improve efficiency of TCP protocol past times buffering them, to transportation a larger packet. Also Nagle's algorithm has negative resultant on non modest writes, thence if you lot are writing large information on packets than it's improve to disable Nagle's algorithm. In general, Nagle's algorithm is a defense forcefulness against careless application, which sends lots of modest packets to network, but it volition non do goodness or have got a negative resultant on good written application, which properly takes assist of buffering.


6) What is TCP_NODELAY?
TCP_NODELAY is an pick to disable Nagle's algorithm, provided past times diverse TCP implementations. Since Nagle's algorithm performs badly amongst TCP delayed acknowledgement algorithm, it's improve to disable Nagle's when you lot are doing write-write-read operation. Where a read afterward 2 successive write on socket may larn delayed up-to 500 millisecond, until the bit write has reached the destination. If latency is to a greater extent than concern over bandwidth usage e.g. inwards a network based multi-player game, user wants to come across activeness from other thespian immediately, it's improve to bypass Nagle's delay past times using TCP_NODELAY flag.


7) What is multicasting or multicast transmission? Which Protocol is by as well as large used for multicast? TCP or UDP?
Multi-casting or multicast transmission is i to many distribution, where message is delivered to a grouping of subscribers simultaneously inwards a unmarried transmission from publisher. Copies of messages are automatically created inwards other network elements e.g. Routers, but alone when the topology of network requires it. Tibco Rendezvous supports multicast transmission. Multi-casting tin alone hold out implemented using UDP, because it sends total information as datagram package, which tin hold out replicated as well as delivered to other subscribers. Since TCP is a point-to-point protocol, it tin non deliver messages to multiple subscriber, until it has link betwixt each of them. Though, UDP is non reliable, as well as messages may hold out lost or delivered out of order. Reliable multicast protocols such as Pragmatic General Multicast (PGM) have got been developed to add together loss detection as well as retransmission on top of IP multicast. IP multicast is widely deployed inwards enterprises, commercial stock exchanges, as well as multimedia content delivery networks. Influenza A virus subtype H5N1 mutual corporation work of IP multicast is for IPTV applications


8) What is departure betwixt Topic as well as Queue inwards JMS?
Main departure betwixt Topic as well as Queue inwards Java Messaging Service comes when nosotros have got multiple consumers to consumer messages. If nosotros set-up multiple listener thread to eat messages from Queue, each messages volition hold out dispatched to alone i thread as well as non all thread. On the other mitt inwards representative of Topic each subscriber gets it's ain re-create of message.


9) What is departure betwixt IO as well as NIO?
Main departure betwixt NIO as well as IO is that NIO provides asynchronous, non blocking IO, which is critical to write faster as well as scalable networking systems. While most of utility from IO classes are blocking as well as slow. NIO convey payoff of asynchronous organisation calls inwards UNIX systems such as select() organisation telephone phone for network sockets. Using select(), an application tin monitor several resources at the same fourth dimension as well as tin also poll for network activity without blocking. The select() organisation telephone phone identifies if information is pending or not, thence read() or write() may hold out used knowing that they volition consummate immediately.


10) How do you lot write multi-threaded server inwards Java?
Influenza A virus subtype H5N1 multi-threaded server is the i which tin server multiple clients without blocking. Java provides fantabulous back upwards to developer such server. Prior to Java 1.4,  you tin write multi-threaded server using traditional socket IO as well as threads. This had severe limitation on scalability, because  it creates novel thread for each connexion as well as you lot tin alone do a fixed number of threads, depending upon machine's as well as platform's capability. Though this pattern tin hold out improved past times using thread pools as well as worker threads, it nonetheless a resources intensive design. After JDK 1.4 as well as NIO's introduction, writing scalable as well as multi-threaded server larn fleck easier. You tin easily do it inwards unmarried thread past times using Selector, which takes payoff of asynchronous as well as non-blocking IO model of Java NIO.


11) What is ephemeral port?
In TCP/IP connexion unremarkably contains 4 things, Server IP, Server port, Client IP as well as Client Port. Out of these four, three are good known inwards most of the time, what is non known is customer port, this is where ephemeral ports comes into picture. ephemeral ports are dynamic port assigned past times your machine's IP stack, from a specified range, known as ephemeral port range, when a customer connexion explicitly doesn't specify a port number. These are curt lived, temporary port, which tin hold out reused i time connexion is closed, but most of IP software, doesn't reuse ephemeral port, until whole attain is exhausted. Similar to TCP, UDP protocol also uses ephemeral port, spell sending datagram . In Linux ephemeral port attain is from 32768 to 61000, spell inwards windows default ephemeral port attain is 1025 to 5000. Similarly dissimilar operating organisation has dissimilar ephemeral port ranges


12) What is sliding window protocol?
Sliding window protocol is a technique for controlling transmitted information packets betwixt 2 network computers where reliable as well as sequential delivery of information packets is required, such as provided past times Transmission Control Protocol (TCP). In the sliding window technique, each packet includes a unique consecutive sequence number, which is used past times the receiving reckoner to house information inwards the right order. The objective of the sliding window technique is to work the sequence numbers to avoid duplicate information as well as to asking missing data


13) When do you lot larn "too many files open" error?
Just similar File connection, Socket Connection also needs file descriptors, Since every machine has express number of file descriptors, it's possible that they may ran out of file descriptors. When it happen, you lot volition come across "too many files open" error. You tin cheque how many file descriptor per procedure is allowed on UNIX based organisation past times executing ulimit -n command or exactly count entries on /proc//fd/


14) What is TIME_WAIT nation inwards TCP protocol? When does a socket connexion goes to TIME_WAIT state?
When i terminate of TCP Connection closes it past times making organisation call, it goes into TIME_WAIT state. Since TCP packets tin brand it inwards incorrect order, the port must non hold out shut straight off to allow belatedly packets to arrive. That's why that terminate of TCP connexion goes into TIME_WAIT state. For example, if customer closes a socket connexion than it volition expire to TIME_WAIT state, similarly if server closes connexion than you lot volition come across TIME_WAIT there. You tin cheque condition of your TCP as well as UDP sockets past times using these networking commands inwards UNIX.


15) What volition occur if you lot have got besides many socket connections inwards TIME_WAIT nation on Server?
When a socket connexion or port goes into TIME_WAIT state, it doesn't free file descriptor associated amongst it. File descriptor is alone released when TIME_WAIT nation is gone i.e. afterward some specified configured time. If besides many connections are inwards TIME_WAIT nation than your Server may ran out of file descriptors as well as commencement throwing "too many files open" error, as well as halt accepting novel connections.


That's all nigh inwards this listing of networking as well as socket programming interview questions as well as answers. Though I have got originally intended this listing for Java programmers it is as useful for whatsoever programmer. In fact, this is bare minimum cognition of sockets as well as protocols every programmer should have. I have got flora that C as well as C++ programmers are improve answering these questions than an average Java programmer. One argue of this may hold out because Java programmers has got thence many useful library e.g. Apache MINA, which does all the depression marker function for them. Anyway, cognition of fundamentals is rattling of import as well as everything else is exactly an excuse, but at same betoken I also recommend using tried as well as tested libraries similar Apache MINA for production code.


Further Reading
The Complete Java MasterClass
Java Network Programming, (4th Addition) past times Harold, Elliotte Rusty
TCP/IP as well as Networking Fundamentals for information technology Pros

0 Response to "15 Coffee Nio, Socket, In Addition To Networking Interview Questions Answers"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel