There is (or at least was) a Navy Law Education Program, where Navy will send serving officers to Law School in exchange for committment to serve as a JAG after graduation. Like the USMC programs, this is very competitive -- it was only 2 a year back in my day. One of the pilots in my squadron, my predecessor as Squadron Legal Officer, got the program and Navy sent him to University of Chicago Law. I tried to follow a few years later, selected as an alternate, and when I didn't get it..left the Navy to attend law school on my own.
There is (or at least was ) a Law for the Junior Officer course --one of the NL courses back in my day. It was an interesting course, and good info for the junior officer to have. Most units have Legal Officer as a collateral duty, and that is a good job for a JO. You have a lot of interaction with the Skipper, albeit often under less than ideal circumstances.