Standard Interfaces

I have been using Java for some time, and I keep hearing about interfaces like Cloneable , Iterable and other X- able s.

I was wondering if there is a list of all of these and, more importantly, which ones do you regularly use every day?

For example, I read that Cloneable is considered poorly written and not widely used.

+7
java interface
source share
8 answers

In the API docs:

 AccessibleStreamable AdapterActivatorOperations Callable Cloneable Closeable Comparable Compilable Destroyable Externalizable Flushable Formattable Invocable ItemSelectable Iterable JMXAddressable Joinable Pageable Printable Readable Referenceable Refreshable Runnable Scrollable Serializable StateEditable Streamable Transferable TypeVariable TypeVariable VM_TRUNCATABLE 

I use Cloneable, Comparable, Iterable, Runnable and, of course, Throwable :-)

+6
source share

Here is a list of all * capable classes and interfaces in java. There are only a few that are really widely used: I would add Comparable and Runnable to your list.

 $ jar tf $JAVA_HOME/jre/lib/rt.jar | grep [az]able\.class | grep -v ^com | grep -v ^sun | sort java/awt/Adjustable.class java/awt/Container$WakingRunnable.class java/awt/datatransfer/Transferable.class java/awt/Dialog$WakingRunnable.class java/awt/ItemSelectable.class java/awt/print/Pageable.class java/awt/print/Printable.class java/awt/ScrollPaneAdjustable.class java/io/Closeable.class java/io/Externalizable.class java/io/Flushable.class java/io/Serializable.class java/lang/Appendable.class java/lang/Cloneable.class java/lang/Comparable.class java/lang/Iterable.class java/lang/ProcessEnvironment$Variable.class java/lang/Readable.class java/lang/reflect/TypeVariable.class java/lang/Runnable.class java/lang/Throwable.class java/rmi/activation/Activatable.class java/util/Collections$SelfComparable.class java/util/concurrent/Callable.class java/util/concurrent/Executors$PrivilegedCallable.class java/util/Formattable.class java/util/Hashtable.class java/util/Observable.class javax/accessibility/AccessibleStreamable.class javax/lang/model/type/TypeVariable.class javax/management/remote/JMXAddressable.class javax/naming/Referenceable.class javax/script/Compilable.class javax/script/Invocable.class javax/security/auth/Destroyable.class javax/security/auth/Refreshable.class javax/sql/rowset/Joinable.class javax/swing/JSlider$1SmartHashtable.class javax/swing/JTable$ThreadSafePrintable.class javax/swing/plaf/basic/BasicFileChooserUI$FileTransferHandler$FileTransferable.class javax/swing/plaf/basic/BasicTextUI$TextTransferHandler$TextTransferable.class javax/swing/plaf/basic/BasicTransferable.class javax/swing/RepaintManager$DisplayChangedRunnable.class javax/swing/Scrollable.class javax/swing/SwingWorker$DoSubmitAccumulativeRunnable.class javax/swing/TablePrintable.class javax/swing/text/DefaultStyledDocument$ChangeUpdateRunnable.class javax/swing/TransferHandler$PropertyTransferable.class javax/swing/undo/StateEditable.class org/omg/CORBA/portable/Streamable.class 
+3
source share

The interfaces that you are most likely to implement are:
java.lang.Comparable
java.lang.Runnable
java.io.Serializable

Interfaces that you most likely call but do not implement yourself:
java.lang.Appendable (StringBuffer / StringBuilder / Writers)
java.lang.CharSequence (String / StringBuffer / StringBuilder)
java.lang.Iterable (Collections, explicitly or using for Blah blah : List<Blah> )
java.lang.Readable (Readers)
java.io.Closeable (Streams)
java.io.Flushable (Streams)
java.util.Collection (Collections)
java.util.Deque (Collections)
java.util.List (Collections)
java.util.Map (Collections)
java.util.Set (Collections)

Interfaces that are likely to explode in your face:
java.lang.Cloneable

Edit: Oops, Throwable is not an interface.

It is usually better to write Copy Constructor instead of using the clone() method.

+3
source share

You're right. Cloneable and partially answer your question, I would never use it. For more information, read this interview with Joshua Bloch.

+1
source share

Here is a list of all the interfaces in the javaadocs Java libraries - follow the tree link, then find the "Interface Hierarchy" section.

+1
source share

Runnable is the one I use the most.

0
source share

Comparable is the one that I use all the time. There is a list: http://java.sun.com/j2se/1.5.0/docs/api/ , but it is HUGE. (To go to the interface tree, you need to scroll about 2/3 of the way down the page.

0
source share

There are many interfaces, as well as many classes, enumerations, and exceptions. If you just look at the interfaces in isolation, you will not see the whole picture. Some interfaces are nouns made in adjectives (-able), others are not, and separation is what is reasonable in English than any technical difference.

It is probably best to research in the area you are trying to solve, and not to study which interfaces are available in the JRE - most of them will not make much sense until you have a specific problematic scenario, and look at them in context with your employees .

As soon as you start, start with the interfaces in the java.lang , then java.io , java.util and maybe java.util.concurrent , this will give you good grounding and then look at specific areas of the application.

Good luck

0
source share

All Articles