When the compiler sees "URLConnection" it recognises it as a type (because of its context in the code) but doesn't know where to find it. So the import statement tells it where to look. There is no difference in memory requirements between the two styles, but the 1st option is preferred because
There is less risk of collisions (eg Timer; there are two Timer classes available)
It is easier to review the code and see what imports have been used.
Import statements are a source-only mechanism. The compiler uses them to translate non-fully qualified class names like URLConnection to fully qualified class names like java.net.URLConnection. The generated byte code therefore no longer has any import statements.
You could compile your source file with the first way of specifying the imports, save the resulting class file, and then with the second way of specifying the imports. Compare the two class files and you will see that they are exactly the same.