The component you are describing is generally called a "solenoid" in the EE field. Be aware that the term "solenoid" has other meanings within the EE world as well. But here I am referring to the generally available component known by that name. 
A solenoid is a coil of wire wound on a tube. The tube generally has a circular cross-section. Inside that tube is an iron "plunger". The plunger is often spring loaded so it will have a preferred position in the tube. 
When voltage is applied to the coil, the plunger will rapidly move from its resting position to its activated position. The displacement between these two positions  is generally about 1/4 to 1 inch, but this is part of the design of the solenoid and can be made to vary according to certain geometric parameters inherent in the design of the solenoid. 
Solenoids are manufactured in a wide variety of sizes and shapes for a large range of applications. They are ubiquitous in our world. For example, your personal vehicle probably has a solenoid as part of its starter motor. This solenoid is used to move the pinion gear on the starter motor shaft into mesh with the ring gear on the engine's flywheel. It produces the "click" you hear when you turn your ignition key and just before the starter motor starts cranking. Or, when your battery is dead and all you hear is that click under the hood.
Another common example is a gong - such as a commercial door bell sounder. This has a resonant metal dome which makes the actual sound. Underneath the metal dome is a solenoid. When the door bell switch is pressed, a voltage is applied to the solenoid, the solenoid's plunger flies upward, and strikes the dome, making the sound. 
There's probably a solenoid activated valve in your refrigerator, gas furnace, or gas water heater. They are everywhere.
Go to www.mcmaster.com and search on "solenoid" and you will see a wide variety of stock units you can purchase to experiment with. I'm sure there are dozens of other internet sources. 
To launch a tennis ball you will need a pretty large solenoid. Such a large solenoid will require a considerable amount of electrical power. You will have to experiment to figure out what's practical for your application. But, I'd start with the biggest solenoid I could find. 
It's not out of the question that you can make your own solenoid. It's also possible to put a number of solenoids in series to increase the produced force.  That is, a common, extra long, plunger with multiple coils you would take from stock solenoids. Though the plunger has to be built in a special way to accomplish this advantage.
That should be enough to get you started.  Good Luck!