If I install a different desktop environment on ubuntu, will it delete files or programs installed earlier?
Could I use those programs installed with ubuntu if I replace the environment with xfce?
Changing Desktop Environments is like changing clothes, yourself will be the same. There's almost 0 risk of data loss (you always should do backups) and almost no glitches (Unity and Gnome 3 don't play well together). There's no risk of something bad happening whatsoever.
xfce4
just installs XFCE, whilexubuntu-desktop
installs xfce4 and might install new programs (those who do not belong toubuntu-desktop
).