Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

When I wrote

import java.util.*;

at the beginning and 

 System.out.println(new Date());

in the main part, I am getting an output like this

Date@124bbbf

when I changed the import to import java.util.Date; it works perfectly. Can someone tell me the difference between the two import st

1 Answer

0 votes
by (13.1k points)

A java.util.*; can import all the APIs present in the folder but Java.util.Date would only import Date API. When you use Java.util.* and call date method, there might be some other method named date other than the date method we want and the compiler could end up using that wrong date method. So, it is better to use proper Java.util.Date to get the Date method that you want and also avoid using the same name for the methods.

Want to learn Java? Check out the Java course from Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 24, 2019 in Java by Nigam (4k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...