Tuesday, May 8, 2012

What are the difference between String, StringBuffer, and StringBuilder?


  • The String class is immutable, however StringBuffer and StringBuilder classes are not immutable. There's no reason to use a StringBuffer or StringBuilder unless you're planing on changing the contents. 

The String class overrides the default equals() method, but StringBuffer and StringBuilder do not override the default equals() method in Object class. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true). For example


Difference between String and StringBuffer/StringBuilder in Java


Well, the most important difference between String and StringBuffer/StringBuilder in java is that String object is immutable whereas StringBuffer/StringBuilder objects are mutable.



Difference Between Interface and Abstract Class

Interface: Java Interfaces are equivalent to protocols. They basically represent an agreed-upon behavior to facilitate interaction between unrelated objects. For example, the buttons on a Remote Controller form the interface for outside world to interact with TV. How this interface is implemented by different vendors is not specified and you’re hardly aware of or bothered about how these buttons have been implemented to work internally. Interface is plainly a contract between the producer and the consumer. How the producer implements the exposed behavior is normally not cared by the consumer
.




DOWNLOAD

Difference bet Implements and Extends Difference bet Implements and Extends Difference bet Implements and Extends


Implements and Extends are two keywords that provide a mechanism to inherit attributes and behavior to a class in Java programming language, they are used for two different purposes. Implements keyword is used for a class to implement a certain interface, while Extends keyword is used for a subclass to extend from a super class. When a class implements an interface, that class needs to implement all the methods defined in the interface, but when a subclass extends a super class, it may or may not override the methods included in the parent class. Finally, another key difference between Implements and Extends is that, a class can implement multiple interfaces but it can only extend from one super class in Java. In general, usage of Implements (interfaces) is considered more favorable compared to the usage of Extends (inheritance), for several reasons like higher flexibility and the ability to minimize coupling. Therefore in practice, programming to an interface is preferred over extending from base classes.


Diffrence between Pass By Reference and Pass By Value


Pass By Reference :
In Pass by reference address of the variable is passed to a function. Whatever changes made to the formal parameter will affect to the actual parameters
- Same memory location is used for both variables.(Formal and Actual)-
- it is useful when you required to return more then 1 values

Pass By Value:
- In this method value of the variable is passed. Changes made to formal will not affect the actual parameters.
- Different memory locations will be created for both variables.
- Here there will be temporary variable created in the function stack which does not affect the original variable.

define class,package,inheritance,interface,object


What Is an Object?
What Is Inheritance?
What Is class?
What Is Interface?




Constructors - super


Every object contains the instance variables of its class. What isn't so obvious is that every object also has all the instance variables of all super classes (parent class, grandparent class, etc). These super class variables must be initialized before the class's instances variables.