Mike Judge, left, with actors Martin Starr, center, and Thomas Middleditch, is the creator of the HBO series “Silicon Valley.” (Jack Plunkett/Invision/AP)

Before he created “Beavis and Butt-Head” and “King of the Hill,” Mike Judge was a physics major working as an engineer in Silicon Valley, writing software for aircraft carriers for the F/A-18 fighter jet.

He took some mental notes on how weird it all was.

“It’s a lot of antisocial introverted people thrown together,” he says over the phone in his deep, halting voice — closer to Hank Hill than Butt-Head (both of whom he voiced in those series). “A lot of these guys would not fit in another workplace.”

But together, they make a humorous gang of nerds in hoodies, who spend their days writing code in hopes of becoming the newest startup millionaires — roles that they are even less suited to fill, even as they try on their Steve Jobs-style turtlenecks.

That’s the premise behind “Silicon Valley,” the new HBO comedy he has made with Alec Berg that premieres next Sunday.

“Silicon Valley” stars a group of mostly young comic actors led by Thomas Middleditch, T.J. Miller, Kumail Nanjiani, Martin Starr and Josh Brener, playing programmers who share a suburban house — an incubator — as they work on their various ideas in a town eager to gobble them up.

Almost immediately in the story, there’s a battle between two Silicon Valley giants and corporate seers over a compression app created by Middleditch’s character Richard.

“He totally doesn’t have the best social skills and he frets in his social position,” says Middleditch, who resembles a slacker version of Seth Meyers.

It’s tough for Richard to run a company or deal with people “while he’s still trying to work out the kinks to his own algorithms,” he says. “It’s like every episode, you feel you’re dealing with more and more money and more and more outcomes, and more and more at stake in the whole thing.”

“I thought about doing something in this area for a long time,” Judge says. But, suddenly, everybody had an idea about it. John Altschuler, a writer on “King of the Hill” who is an executive producer here, “had an idea about doing a show like ‘Dallas’ or ‘Falcon Crest’ but instead of oil or wine money, it would be about tech money,” Judge says.

Then HBO approached with an idea to do a series about video game players, Judge says. “And I didn’t know the gaming world at all. But I did know this world.”

Alec Berg, a former writer on “Seinfeld” and executive producer of “Curb Your Enthusiasm,” had some familiarity as well. “My dad was a Harvard biophysicist, and my brother was an electric engineer who worked for Microsoft, worked for Vulcan, went to Stanford for computer science,” he says over the phone interview, “so it was very much in my life.”

But there was a reason there hadn’t been a series about the digital boom.

“We’ve been joking that we’re doing a series about something that’s inherently unfilmable,” Berg says. While it’s understandable to have police, fire and emergency room TV shows, where “every 10 minutes a story comes running through your door,” he says, “watching guys type is not super exciting. So we’re consequently having to figure out ways to make what these guys do interesting and presentational, visual.”

Judge had heard it before.

“When I did ‘Office Space,’ ” he says, referring to the 1998 cult comedy film, “there was some concern back then about: How are you going to make a movie about people who sit in desks? But I think because there’s not obvious action stuff there, it’s kind of a challenge that ends up yielding really interesting character stuff. I think that ended up happening with this, too. “

Besides that, some of industry’s giants, from Facebook’s Mark Zuckerberg to Google creators Sergey Brin and Larry Page, have become more widely known as personalities.

In fact, some of their stories migrated to “Silicon Valley.”

“We heard a story about Sergey and Larry at Google, when they first started, they got their first seed check for $100,000 made out to Google Inc., but they didn’t own the name Google Inc., so they couldn’t cash the check until they solved that issue,” Berg says. “That became a story.”

“The big thing with Mike is satire — pulling in from what’s real and changing as little as possible, just to reflect at how ridiculous most of real life is,” says Middleditch, who has worked with Judge previously by lending his voice to Stewart in the last iteration of “Beavis and Butt-Head.”

As such, “it was impossible to clear names for the show because any nonsense arrangement of letters they came up with had already been taken,” Middleditch says.

So in a land of Google and Yahoo, they came up with Hooli as a giant tech company run by a megalomaniac played by Matt Ross, familiar from his role in HBO’s “Big Love.”

Other times, they’d invent something bizarre only to find out that someone else had actually come up with it. In the show’s pilot, Brener’s character, Big Head, invented an app that indicates the proximity of erect nipples. Six months later, when the producers attended the big TechCrunch Disrupt gathering in San Francisco, where the final two episodes of the season take place, there was news about negative reaction to an actual app presented there regarding staring at women’s breasts.

If the reaction to that misguided Australian app pointed out the rampant misogyny in Silicon Valley, some may also point to the show, where the only female characters in the opening episodes are a stripper and an executive assistant.

But, unfortunately, that’s the way it is there, says Berg, who reports seeing only a handful of women at the big tech event. So as an issue, he says, “that is something to play with.” But he adds, “it doesn’t authorize us to cast no women.”

“We make jokes about it,” Judge says. “But we do have female characters coming up in the show.”

For now, the cast resembles the kind of nerd gangs that populate the burgeoning industry, and the two are happy with the group of actors they got to portray them, who largely came up from improv comedy groups.

“They all seemed like they could play believable engineer types,” says Judge, who rewrote the series to fit them all in.

“One thing that’s a little tricky when you’re casting nerds,” he says, “you get all these guys who have been in a million of these commercials where it’s FedEx or something, when there’s a guy sitting at a desk. There’s this real fine line between somebody who is kind of cartoony nerdy and somebody who you believe can play intelligent and be funny at same time. And I think we have a pretty amazing cast that’s able to do that.”

And maybe they’re not acting that much. “Between takes of the show, they’re actually, literally playing Magic: The Gathering,” a trading card game, Berg says.

Catlin is a freelance writer.

Silicon Valley

(30 minutes) premieres next Sunday at 10 p.m. on HBO.