Hi Aruna,

AFAIK, The compiler will replace all the class names with the fully
qualified name at all the places whether or not we use package.*. So after
compilation, there is no impact from this practice.

This is all about readability for me. Lets say I have 10 packages imported
a.b.c.*, a.b.d.* etc.... I have used a class "Z" in my code. now the reader
can't figure out from which package the Z class came from because all are *
imports.

So I think its better to use full class name than full package exports.

But in your example, I think there should be a scenario 3. java.io and
java.util are well known. so only classes came from java.util.zip are
mentioned.

Scenario 3

import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

WDYT?


On Thu, Jul 31, 2014 at 3:08 PM, Aruna Karunarathna <[email protected]> wrote:

> Hi all,
>
> For e.g I have a java file with following imports.
>
> Scenario 1
>
> import java.io.*;
> import java.util.*;
> import java.util.zip.*;
>
> Scenario 2
>
> import java.io.BufferedOutputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.OutputStream;
> import java.io.UnsupportedEncodingException;
> import java.util.ArrayList;
> import java.util.Dictionary;
> import java.util.Enumeration;
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.List;
> import java.util.Map;
> import java.util.zip.ZipEntry;
> import java.util.zip.ZipFile;
>
> In scenario 1 we have put * and match the imports in a bad way and in
> Scenario 2 you define the exact imports. I know that the Scenario 2 is the
> ideal.
> But in default Intellij IDEA, if we are importing more than 5 imports it
> automatically put the java.io.* (This can be changed by Settings > Code
> Style > Java > imports tab   Setting the "class count to use import with *"
> to some higher value)
>
> My questions are,
> What is the best way to optimize imports in above scenario?
> Do we have a best  practice for "class count to use import with *" in a
> java file in WSO2?
> Does the import order matter?
>
> Highly appreciate your thoughts on this.
>
> Regards,
> Aruna
>
> --
>
> * Aruna Sujith Karunarathna* | Software Engineer
> WSO2, Inc | lean. enterprise. middleware.
> #20, Palm Grove, Colombo 03, Sri Lanka
> Mobile: +94 71 9040362 | Work: +94 112145345
> Email: [email protected] | Web: www.wso2.com
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
K.D. Chamil Jeewantha
Associate Technical Lead
WSO2, Inc.;  http://wso2.com
Mobile: +94716813892
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to