The Corps of Midshipmen attend the US Naval Academy at Annapolis. When selected, you can declare the Marine Option and if successful and you graduate, then you become a Marine Corps 2nd Lieutenant and then attend The Basic School (TBS) at Quantico, VA, where you attend six months schooling to learn how to become a basic Marine Second Lieutenant. After that school, you are assigned another school for whatever job it is you are going to do in the Marine Corps (Infantry, Artillery, Logistics, Naval Aviator, etc)
Getting an appointment to the Naval Academy is a very competitive process and you must be nominated generally by a Congressman from your state/hometown. Certain individuals get an automatic appointment (sons of Medal of Honor winners, etc.).
If you want to be a Marine Officer without going to the Naval Academy, there are other avenues (NROTC, Platoon Leader's Class (PLC), Bulldog) that includes an Officer Candidate School that you have to attend (10 weeks usually) before you get to go to TBS.
The Department of the Navy is composed of the United States Navy and the United States Marine Corps. Together they comprise the "Naval" component of the Department of the Defense. So saying the Marine Corps is under the Navy is not technically correct. Both the Navy and the Marine Corps are co-equal branches of service under this "Naval" component called the Department of the Navy.