Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using package name to create objects in Java

I was looking at someone's else code and they code it using package names.

String filename = "";

java.io.PrintWriter writer;

writer = new java.io.PrintWriter(new java.io.FileWriter(filename));

Is the syntax the equivalent had it not been coded with package name? Is there any use coding it with package names since Java allows it?

like image 824
Nicholas Avatar asked Feb 09 '13 23:02

Nicholas


1 Answers

You have to use the package names (or "fully-qualified names" - this refers to the package name and the class name together) if:

  1. You need to use two classes of the same name in the same source file.
  2. You didn't import the classes you're using for whichever reason. (Usually insanity.)
  3. You imported the classes but are still using the package names anyway because I don't know.
like image 135
millimoose Avatar answered Oct 14 '22 18:10

millimoose