JaiswalTraining

Get the online training        


Get Best Tutorial on all major programing language


Corejava Servlet Jsp  Php  Hibernate  Ajax Web Service   Ejb2.1 Ejb3.0 Struts Struts2  JPA Spring Ibatis   JSF    JSF2.0  CoreJavaDesignPattern    Jquery  Flex J2EE-Design-Patterns  Jboss7  Maven  Contact Me                                                                                                                                                                        
            IGNOU SMU PTU Project                                           Training                                                                                                                              
              

Contact Us  0091- 9210721663         jaiswaltraining@gmail.com




Corejava
Servlet
Jsp
Php
Hibernate
Ajax
Web Service
Ejb2.1
Ejb3.0
Struts  
Struts2
JPA
Spring
Ibatis
JSF
JSF2.0
CoreJavaDesignPattern
Jquery
Flex
J2EE-Design-Patterns
Jboss7
Maven







Java NIO

Overview

What is Java NIO?

  • Stands for New IO.
  • Started off as a JSR under Sun’s JCP (JSR51).
  • “APIs for scalable I/O, fast buffered binary and character I/O, regular expressions,
    Charest conversion, and an improved filesystem interface. ”
Why NIO?
  • NIO was created to allow Java programmers to implement high-speed I/O without
    having to write custom native code.
  •  NIO moves the most time-consuming I/O activities (namely, filling and draining buffers)
    back into the operating system, thus allowing for a great increase in speed.
Streams versus blocks
  • The most important distinction between the original I/O library (found in java.io.*) 
  • NIO has to do with how data is packaged and transmitted.
  •  I/O deals with data in streams, whereas NIO deals with data in blocks.
  • A stream-oriented I/O system deals with data one byte at a time. 
  • An input stream produces one byte of data, and an output stream consumes one byte of data. 
  • It is very easy to create filters for streamed data. 
  • It is also relatively simply to chain several filters together so that each one does its part in
    what amounts to a single, sophisticated processing mechanism.
  •  On the flip side, stream-oriented I/O is often rather slow.
  • A block-oriented I/O system deals with data in blocks. 
  • Each operation produces or consumes a block of data in one step. 
  • Processing data by the block can be much faster than processing it by the (streamed) byte.
    But block-oriented I/O lacks some of the elegance and simplicity of stream-oriented I/O.
Features
  • New Abstractions
    • Buffers
    • Channels
    • Selectors
  • New I/O Capabilities
    • Non-Blocking Sockets
    • Readiness Selection
    • File Locking
    • Memory Mapped Files
  • New Non-I/O Features
    • Regular Expressions
    • Pluggable Charset Transcoders


Advanatges
  • Efficiency – The Need For Speed
    • Byte/char-oriented pipelines are flexible but relatively inefficient
    • The OS provides high-performance I/O services - the JVM gets in the way
  • Scalability – Livin' Large
    • Big applications have big appetites, they consume large amounts of data
    • Traditional method of handling large numbers of I/O streams does not scale
    • Multiplexing can only be done effectively with OS support
  • Reliability – Less Code Written = Fewer Bugs
    • These I/O needs are generic and should be provided by the Java platform
    • Application programmers should write application code, not infrastructure
  • No Longer CPU Bound
    • Moving data has become the bottleneck, not bytecode execution speed
  • java.nio is not a replacement for java.io
    • NIO addresses different needs
    • java.nio does not re-implement java.io
  •  java.io is not going away
  •  NIO is not the right tool for every job

What Makes Up NIO?
  • Buffers
    • Data container objects
  • Channels
    • Transfer data between buffers and I/O services
  • Selectors
    • Provide status information about channels
  • Regular Expressions
    • Perform pattern matching against character sequences
  • Character Set Coding
    • Perform encoding/decoding of character sequences to/from byte streams