Arduino as a real device to computer
As per my understanding, the mouse has a microcontroller and a TTL serial converter which is programmed a certain way that enable computer's default mouse driver to understand the instructions coming from the connected device.


No, the mouse's microcontroller is a USB device.


  Like arduino send serial instructions to a port say COM3 and the driver which is a java program reads those instructions and performs accordingly.


No, that is the application you are talking about. The driver is what you install in Windows to make COM3 appear (that is, in any version of Windows before windows 10. Every other operating system, and Windows 10, has the driver built in already).


  Now what I want is when arduino connects to a computer it gets detected as a Joystick or as a pendrive or something like that.


There is no support for that in the Arduino API.


  I go through different header files of mouse and keyboard which are present in arduino library but those are very complex and without proper documentation hard to understand.


Even with proper documentation and understanding of how USB works it's hard to understand.


  Can you tell me where I could find study materiel regarding the existing library? Arduino website provides documentations only on different methods not on how it works.
  
  Or if I think of building my own library then how I should start?


Don't. Trying to do what you want without an in-depth understanding of how USB works is nigh on impossible.  I understand how USB works and struggle with writing USB driver code for microcontrollers.

Instead invest in a device that already does what you want (such as a Teensy 3.x), or move away from Arduino and use a professional environment with professional tools and examples to work with.


  One more thing where I can find the information regarding the protocols that a conventional device like mouse, keyboard, pendrive, CD-ROM follows during communication (like the code or the algorithm that is burn into the microcontroller of the device) ?


From the USB Implementer's Forum Inc. 


http://www.usb.org/developers/docs/devclass_docs/



  Mouse or pendrive have a special type of microcontroller which are capable of direct communication to pc ? if so then is their any programmable microcontroller in market? 


Yes, and there are plenty. Any of the Arduino boards based around the ATMega32U4 (such as the Leonardo) are that kind of microcontroller. The "serial" interface chip on the Uno is that kind of microcontroller (it is capable of being reprogrammed so it looks like a completely different device, and if you google around you will find people that have done it).


  What is the difference between actual driver and my java program which reads COM port?


The driver is what makes the COM port. Your program is what uses the COM port.

[USB device]----&gt;[USB)- Driver -(COM3]&lt;-----[Your program]