Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Class or Interface

Declare variables as class or interface type?

Tutorial Details:

A common programming philosophy is to declare variables with a type that makes the least assumptions. This allows flexibility to make changes in the underlying type if this latter becomes necessary. For example, the most obvious way to declare x is

ArrayList x = new ArrayList();

Why change the underlying class?
The two List classes, ArrayList and LinkedList both implement the same List interface methods and can be manipulated by the methods in the Collections class, but the performance of different operations may be very different, eg, insertion in the middle of an LinkedList is more efficient, but accessing a random element is more efficient using a ArrayList. If it becomes necessary to change the underyling class for performance reasons, it is easy to do if variables are declared by their interfaces (List, Map, and Set for the Collections classes).


 

Rate Tutorial:
http://www.roseindia.net/java/java-tips/data/collections/classorinterface.shtml

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Class or Interface

View Tutorial:
Class or Interface

Related Tutorials:

Design networked applications in RMI using the Adapter design pattern
Design networked applications in RMI using the Adapter design pattern
 
Smarter Java development - JavaWorld August 1999
Smarter Java development - JavaWorld August 1999
 
Static class declarations
Static class declarations
 
Brewing entity Enterprise JavaBeans - JavaWorld September 2000
Brewing entity Enterprise JavaBeans - JavaWorld September 2000
 
Get smart with proxies and RMI - JavaWorld November 2000
Get smart with proxies and RMI - JavaWorld November 2000
 
Make an EJB from any Java class with Java Reflection - JavaWorld December 2000
Make an EJB from any Java class with Java Reflection - JavaWorld December 2000
 
Object mobility in the Jini environment - JavaWorld January 2001
Object mobility in the Jini environment - JavaWorld January 2001
 
A primordial interface? - JavaWorld March 2001
A primordial interface? - JavaWorld March 2001
 
Clean up your wire protocol with SOAP, Part 4 - JavaWorld July 2001
Clean up your wire protocol with SOAP, Part 4 - JavaWorld July 2001
 
Dynamically extend Java applications - JavaWorld August 2001
Dynamically extend Java applications - JavaWorld August 2001
 
Explore the Dynamic Proxy API
Explore the Dynamic Proxy API
 
Dynamically extend Java applications
Dynamically extend Java applications
 
Create your own type 3 JDBC driver, Part 1
Create your own type 3 JDBC driver, Part 1
 
Building Highly Scalable Servers with Java NIO
Building Highly Scalable Servers with Java NIO I/O Event Handling The I/O architecture of our router was strongly inspired by the Swing event-dispatch model. In Swing, events generated by the user interface are received by the JVM and stored in an even
 
Annotations in Tiger, Part 2: Custom annotations
Write your own annotations in Java 5 Part 1 of this series introduced annotations, the new metadata facility in J2SE 5.0, and focused on Tiger's basic built-in annotations. A more powerful related feature is support for writing your own annotations. In t
 
Smokescreen Introduction
Smokescreen is a Java obfuscator. Aside from being able to change symbolic names, it can also modify the bytecode instructions in methods thereby obfuscating control flow. This makes the resulting obfuscated classes much more difficult to decompile.
 
They just work
Writing CSV files: CSVPrinter This class makes it easy to output CSV. Given values, it will automatically determine if they need to be quoted and escape special characters. Comments can easily be written and correct line beginnings will be added.
 
Create intelligent Web spiders
Create intelligent Web spiders This article demonstrates how to create an intelligent Web spider based on standard Java network objects. The heart of this spider is a recursive routine that can perform depth-first Web searches based on keyword/phrase cri
 
Welcome to the Apache Struts Tutorial
This is the complete Struts Tutorial. Explains ActionForm Action Class Validation Framework.
 
Core Java Interview Questions!
Core Java Interview Questions! Core Java Interview Questions Question: What is transient variable? Answer: Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.