The Military Law of the United States is collected in the Uniform Code of Military Justice and has Jurisidicition over all military service members including reserves, the Coast Guard in times of peace (when it is not part of the Department of Defense but instead DHS) and National Oceanic and Atmospheric Administration (NOAA) and Public Health Service Corp (PHS) but only personnel attached to a military unit or when the organizations are militarized under an Executive Order by the President. Members of the National Guard are subject when operating under Federalization and otherwise are subject to State Uniform Codes of Military Justice.
In the military both the prosecutor counsel, the defense counsel, and the Judge are referred work in the Judge Advocate General (JAG) office. An accused military personnel retains all the Rights of the Accused outlined in the U.S. Constitution (Amendments 4-8 ). Any trial is reffered to as a Court Martial and the Jury varies between one of three types of Court Martial: Summary Court Martial, Special Court Martial, and General Court Martial
Summary is akin to magistrate judgement (commonly used traffic court in traffic court in the U.S.) though doesn't have any real equivalent and is not available to officers and enlisted must consent. Generally the charges are very minor as are the punishments and are considered to be a type of Article 15 proceedings (more on that in a bit). The accused is not entiteld to defense council (the Air Force provides one as matter of policy and other services provide one on case by case basis).
Special is akin to federal misdemeanor court and can have a sentence of no more than one year in jail time. The accused is entitled to a jury which is composed of at least 3 military officers unless the accused is enlisted, in which case one third of the jury must be enlisted rank.
General Court Martial is for serious offenses and would be akin to a felony criminal trial. The accused is entitled to a jury which is composed of at least 5 military officers unless the accused is enlisted, in which case one third of the jury must be enlisted rank.
Finally, the UCMJ allows for Non-Judicial Punishment (NJP) which is punishment for minor infractions by a commanding officer of the accused who is not a JAG officer. The punishment metted out depends on both the rank of the accused and the rank of the trier of fact. Each service has different names for NJP. The Army and Air Force refer to the proceeding as Article 15 (after the article allowing for the practice in the UCMJ). The Navy and Cost Guard refer to it as "Captain's Mast" or "Admiral's Mast" or "Flag Mast" (the latter two are if convened by an Admiral only. The first is regardless of rank otherwise. Name comes from several naval traditions based around the main mast of a sailing ship.). The Marines refer to it as "Office Hours" and one who's conduct is the subject of Office Hours as having been "NJP'd" or more informally and recently "Ninja Punched". Appeals are made to the next step up in the chain of command who can uphold or lessen the punishment or deny the appeal but can not augment the initial punishment. The accused may also request a court martial however the benefit of an NJP is keeping the infraction from being entered in the accused's criminal record.
Although not stated as such, the episode of Star Trek: TNG "Reunion" sees Picard hold a Captain's Mast of sorts against Worf in the conclusion for his actions at the climax (Worf receives a letter of reprimand in his Service Record. In the real world, Worf got off pretty light considering his actions though in fictional universe, the more serious offense was considered a justified homicide under the circumstances.) and "Ensign Ro" sees another such judgement, in which the titular character is confined to quarters for the duration of the mission for leaving the ship without Picard's permission (a more realistic crime and outcome).