File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt" Watch "Doubt" New topic
Author

Doubt

gangashri patil
Greenhorn

Joined: Sep 21, 2011
Posts: 3
what is difference between 1] List a=new List
2]ArrayList a=new ArrayList

which one is good to use?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14345
    
  22

Welcome to the Ranch.

java.util.List is an interface, so the first option is not going to work, because you can't instantiate an interface using new.

But probably you meant: List a = new ArrayList();

You're not the first one who asks this question, in fact, it is asked regularly on the forums here. It's the program to an interface, not an implementation principle.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt