A federal judge ruled yesterday that Fairfax County had discriminated against blacks and women in hiring and promotion and ordered a halt to the use of job exams that he found have adversely affected blacks. A court hearing will be held to determine whether some employees are entitled to receive compensation because of past discrimination.

The decision by U.S. District Judge Albert V. Bryan Jr. in Alexandria was promptly hailed as a clear victory by Justice Department attorneys, who argued that the county systematically discriminated against women and minorities in hiring and promotion.

The U.S. government's suit was vigorously contested by Fairfax County; county board Chairman John F. Herrity had sent letters to both President Reagan and Attorney General William French Smith urging them to drop the matter on the basis of compaign pledges to end harassment of local officials. County officials declined to comment yesterday until they could study the 22-page decision more fully.

It was the second time Bryan had ruled in the discrimination suit against the county. In April 1979 he largely rejected the Justice Department's case, but the 4th U.S. Circuit Court of Appeals ordered the retrial on grounds that the judge failed to give proper consideration to some of the evidence presented against the county.

In his latest ruling, Bryan did not make a blanket finding of discrimination. He ruled specifically that Justice extablished "a pattern and practice of disparate treatment of blacks" in professional, technical and protective service job categories and of women in paraprofessional and service maintenance categories. He wrote that "despite its shortcomings, the date presented "by [Justice] remains the more persuasive as between it and that now proffered by the county."

Justice Department attorney Katherine P. Ransel said of the decision: "We're obviously very pleased." Justice attorney Allen Wayne said, "The ball was basically in the county's court to rebut our . . . case, but the judge decided in the same way that we proposed."

The county has been ordered to replace written examinations for such positions as police officer, deputy sheriff and various clerical positions. Judge Bryan also ordered the county to alter its selection "so as to eliminate adverse impact on blacks or women."

Although Bryan cited the county's "intensified" affirmative action program as something that was being pursued in good faith, he nonetheless ordered a monitoring procedure requiring the county to keep a wide array of records relating to recruitment, selection and promotion of employes.

The county has also been ordered by Bryan to file semiannual reports on written and performance tests, appointments to all vacancies, applicants to job vacancies and work force statistics.

The judge also ordered what attorneys refer to as a "stage two" hearing in three months "to determine the relief to which individual victims of the pattern or practice of discrimination found by the court may be entitled."

Throughout three days of laborious testimony that ended March 23, attorney Jack Gould, who represented the county, produced a statistical argument that attacked the heart of the government's mathematical case, stating that Justice was reduced to using "broad brush strokes" and "unrefined data" to prove discrimination.

Bryan disagreed, saying that "the court rejects the county's objections to the data used and the method of its use by the government. . ."