How does Ubuntu Load previously opened applications on startup? (I want to code and modify that functionality present in the system preferences manually )
Ubuntu doesn't "load previously opened applications on start-up" out-of-the-box.
Try this: open the terminal by pressing Ctrl+Alt+T log off and log on again: the terminal doesn't open automatically and if it does on your system, you have an application installed that does that for you. (but I wouldn't know which: check your system settings.
If your question is "How should I add applications to the autostart", then please edit your question to make this clearer and then you have two possibilities:
Using the GUI
Go to the dash, type
Startup Applications and any application you want opened at login.
Using the command line
Have a look here for the file locations of these commands. You can then add those programmatically.