The traditional view is that Jupiter first formed a rocky core, several times the size of Earth, which then attracted a still larger outer envelope of gas. This process is known as “accretion.”
But there are problems with this model. The major problem is that if the large, gaseous planet did form by the gradual accretion of material, it would have taken a very long time to develop. Current estimates range between 10 million and 1 billion years. However, recent observations of distant stars suggest that planets have at most a few million years or less to gather up as much dust and gas as they can before the protoplanetary disk that feeds them disappears.