+ 1

Importing packages in java

if you import all the packages instead of the only the ones that your program requires are the only effects speed of execution and memory requirements?

29th Apr 2017, 10:03 AM
[A^dr3w]
[A^dr3w] - avatar
9 Respostas
+ 16
@[Andrew], When learning basics in Java, we use Scanner class of java.util package, so few people import the package like java.util.* , while few does like java.util.Scanner; I think there is a difference of execution time between both statement of importing all classes of util package, and importing a single Scanner class.
29th Apr 2017, 10:52 AM
Sachin Artani
Sachin Artani - avatar
+ 17
There is something called #include (Preprocessor) which is used to include the whole header file, despite including only those which we need in our program, To overcome this issue, for the purpose of improving execution speed, reducing response time etc, Java introduced "import" keyword, which then start to use to import only those packages or subpackages or classes which are needed in our program. So, it is obvious that if you import all the packages you know, the program will surely die because you are conflicting the rules of import.
29th Apr 2017, 10:34 AM
Sachin Artani
Sachin Artani - avatar
+ 16
@Very hard, I meant about the execution speeds between the two of cases I stated above.
29th Apr 2017, 10:54 AM
Sachin Artani
Sachin Artani - avatar
+ 16
@Very hard, Oh man!! 😂😂😂 I have never seen a guy doing that much precise work. And yeah, the difference will be in ms(miliseconds), if it is.
29th Apr 2017, 11:00 AM
Sachin Artani
Sachin Artani - avatar
+ 6
@Sachin Artani Ha ha if that. I think "nope" Unless if you use too much and so much class Or silly like I do (I use java.lang.System.out.print to just print "Hello world" -_- oh yeah not end yet.I'm crazy more I import java.lang.System -_-)
29th Apr 2017, 10:56 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 5
Difference is they import whole class of java.util
29th Apr 2017, 10:53 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 4
I think not much... Cus we can use another class without import it
29th Apr 2017, 10:47 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 2
You would think so. but java includes the import option with import java.util.*; So they must expect it to be used sometime.
29th Apr 2017, 10:46 AM
[A^dr3w]
[A^dr3w] - avatar
0
as many as you want
27th Sep 2019, 6:11 AM
Digvijaya Satpute
Digvijaya Satpute - avatar