A JAG is a Judge Advocate General, the senior officer assigned to command the legal services organization one of the branches of the United States military. In common usage, however, the term refers to any military lawyer serving in such an organization. JAGs, in the United States and other countries, that maintain legal establishments within their military, usually are trained in the legal profession before joining the military. Upon earning their lawyer's credentials, they then apply to become lawyers in the military, and if accepted, they're given basic military training, as well as training in military law. Upon completion of the training, they're commissioned as officers.
In the US, Army, Air Force, and Navy JAGs are members of the Judge Advocate General's Corps of their respective branch of service; the Marines and Coast Guard have JAGs, but no special unit for them. Marine Corps and Coast Guard JAG officers are considered line officers. That is, they can be assigned to any officer's position within their service appropriate to their rank. The fact is, though, that JAG officers in all branches generally serve full time in their legal capacity, acting as legal counsel to the commander of the unit to which they're attached, providing legal service and advice to the other officers and enlisted men in the command, and keeping the units officers abreast of legislative issues as appropriate.
While JAGs provide a wide range of legal services to their units, including providing legal advice and services in combat conditions, probably the most visible and well-known of their functions is to serve as trial counsel and defense counsel in courts-martial, which are military trials of enlisted and commissioned personnel accused of violating the Uniform Code of Military Justice (UCMJ). The trial counsel is assigned to represent the US Government and prosecutes the case. The defense attorney is assigned to provide the defendant with the best possible defense. Defendants in courts-martial sometimes elect to hire a civilian attorney with military experience. In such cases, the assigned JAG officer will assist the civilian attorney.
In addition to their assignments as trial counsel and defense counsel, a senior JAG will be assigned to sit as judge both in general courts-martial, which have jurisdiction over serious cases where the maximum punishment exceeds a year's confinement and could include execution, and special courts-martial, which are convened for less serious cases, where the maximum confinement possible is 12 months. A third type of court-martial, called a summary court martial, is held with a single hearing officer, usually a JAG who acts both as trial counsel and defense counsel. A summary court-martial is convened for relatively minor offenses by enlisted personnel, and cannot impose a confinement punishment of more than 30 days.