It's a lot easier for us if you ask specific questions.
A library is a set of functions that are usually aimed at a single task. So the LiquidCrystal library is used to perform tasks on an LCD display, like positioning the cursor, clearing the display, writing text to the display, and so on. You should use a library virtually any time one exists for your task at hand. You can always write your own code, but why reinvent the wheel? Many general purpose libraries, like the LiquidCrystal library, are distributed with the Arduino IDE. However, there are probably hundreds of other specialized libraries written for the Arduino. Any time you have a specific task, like your distance sensor task, your first step to solving the task is spending some time with Google. I googled "Arduino distance sensor" and got over 344,000 hits. Surely one of those would be of help to you.
Finally, make sure you read the two posts at the top of this Forum by Nick Gammon. He has guidelines for posting here that will maximize the help you get here.