import java.io.*; /** Lists all .java files in a directory * passed as a command-line argument */ public class Lister{ public static void main(String[] args){ File f=new File(args[0]); //f refers to the specified directory String[] list = f.list(new FilenameFilter() { //argument of type anonymous class that //implements java.io.FilenameFilter interface public boolean accept(File f, String s){ //method of anonymous class return s.endsWith(``.java''); } }); for(int i=0;i<list.length;i++){ System.out.println(list[i]); } } } /******** sample compilation & run ******* # javac l1Anon3.java # java l1Anon2 . l1Anon2.java l1Anon3.java l1Anon4.java l1Anon5.java l1ClCons1.java l1ClDecl1.java l1ClStat1.java l1ClStat2.java l1ClStat3.java l1ClThis1.java l1Except1.java l1Except2.java l1Except3.java l1Except5.java l1Inherit1.java l1Inherit10.java l1Inherit11.java l1Inherit12.java l1Inherit2.java l1Inherit3.java l1Inherit4.java l1Inherit5.java l1Inherit6.java l1Inherit7.java l1Inherit8.java l1Inherit9.java l1Interf1.java l1Interf2.java l1Interf3.java l1Local1.java l1Local2.java l1Local3.java l1Memb1.java l1Memb2.java l1Memb3.java l1Nest2.java l1Nest3.java # ******************************************/