FileVisitor Interface Sample

In this sample file visitor interface you can list all the folders and their regarding files   import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.FileVisitor; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class MyFileVisitor implements FileVisitor<Path> { private Map<String, List<String>> data = new HashMap<>(); private Map<String, IOException>

Abstract Classes Compared to Interfaces

Abstract classes are similar to interfaces. You cannot instantiate them, and they may contain a mix of methods declared with or without an implementation. However, with abstract classes, you can declare fields that are not static and final, and define public, protected, and private concrete methods. With interfaces, all fields are automatically public, static, and

Binding of variables and methods at compile time and runtime

You can use reference variables of a base class to refer to an object of a derived class. With inheritance, the instance variables bind at compile time and the methods bind at runtime. Examine the following code: class Employee { String name = "Employee"; void printName() { System.out.println(name); } } class Programmer extends Employee { String name

Forms of Inheritance

Timothy Budd, in his book “Understanding Object-Oriented Programming with Java” (Addison-Wesley, 2000), makes the following distinction: The term subtype is used to describe the relationship between types that explicitly recognizes the principle of substitution. That is, a type B is considered to be a subtype of A if two conditions hold. The first is that

superclass/subclass compatibility

They must really love this topic on the Java Certification exam, because they ask it in several different questions. Make sure you have it down before taking that test. Here are possible assignments and a note about their compatibility: superclass = subclass ==> always valid, subclass = (subclass) superclass ==> valid at compile time, checked at run-time,