Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Sunday, June 9, 2013

What are legacy classes and interfaces in Java?

Before Java 1.2 version there is no Collection framework in java, instead java consists of some classes and interfaces to hold the objects those are called Legacy Classes and Interface
Legacy Class :
  • Dictionary
  • HashTable
  • Properties
  • Stack
  • Vector
Legacy Interface :
  • Enumeration
Dictionary :
Dictionary is a abstract class, which holds the data as Key/value pair. It works as Map collection.

The abstract methods and its description that are available in Dictionary class are in below figure.


Dictionary Class






















HashTable :

  • HashTable is a part of java.util package and it is a concrete class which extends the Dictionary class.
  • In Java 1.2 version on ward HashTable class implemented the Map interface and it is as part of Collection Framework.
  • HashTable is synchronized.

Properties :

Properties class will hold the set of properties in Key/value pair. Properties class extends HashTable class . This class is thread-safe , multiple threads can share single Properties object without making externally Synchronization.

Stack :

Stack represents the Last-In-First-Out(LIFO). Stack class extends the Vector class.

Vector :

Vector class is a grow-able array and is similar to ArrayList class with two difference. 
Vector is a Synchronized.
Vector is used where programmer didn't have knowledge of what the size of the Array is.It means you can ignore the size of the Vector, even still Vector will work without any exceptions.


Enumeration :

A class that implements Enumeration interface will generate series of elements, one at a time.
  • This interface is used to enumerate elements of Vector, keys/values of HashTable and properties in the Properties class.
  • Enumeration operations are duplicated by the Iterator interface and some more operations like remove() etc are added. For new implementations should consider Iterator instead of Enumeration.

Saturday, June 1, 2013

What is serialization?

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent database or streamed across a communication media. The byte stream can be serialized and converted into original object.

What is the difference between web server and app server?

A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.

What are difference between final finally and finalize?

final :final keyword is used along the variables in java. If you make variable as final, then it value can't be alerted.
If method is final, then that method can't be overridden.
If a class is final, then that class can't be extended.

finally : finally is used in the Exception handling using try , catch and finally blocks.
finally block has some special features like, finally block will be executed all the time even if the exception is occurred in the method.
finally block is mainly used to close/kill the resources opened in the try or any part of the method body.
finally block wont be called if JVM got killed wanted by using System.exist();

finalize() : finalize() method is called Garbage collection thread to collect the un-referenced java objects and 

What is a transient variable in Java?

A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can mark that field transient or static.

What are different types of access modifiers?

Access specifiers are keywords that determine the type of access to the member a class.
Public      
Protected
Private
Default

What is String Pooling?
Below prints true,
String str1="st"+"r";
String str2="s"+"tr";
System.out.println(str1==str2);
 When compiler optimizes your string literals, it sees that both str1 and str2 have same value and thus you need only one string object.
Name 'string pool' comes from the idea that all already defined string are stored in some 'pool' and before creating new String object compiler checks if such string is already defined.As result, both str1 and str2 point to the same object and some little memory saved.

Why String id Immutable?

The mail reason behind the String is immutable is
a) Security - As most of the parameters requried in our dialy life programming such as database connection url, port number, host name, file name supplied to the I/O operation in creating of files, userid and passwords all the above will be declared by String object because, as String is final and cannt be changed in middle of code excution.
b) String Pooling - Name 'string pool' comes from the idea that all already defined string are stored in some 'pool' and before creating new String object compiler checks if such string is already defined
c) Faster - As String variables cannot be manuplated, its hashcode will be one, so it can be retrieved fast every time

Friday, August 6, 2010

Encapsulation:
Means putting the data and the function that operates on that data in a single unit(information hiding) .Encapsulation prevents clients from seeing its inside view, where the behavior of the abstraction is implemented.
Encapsulation is the mechanism that binds together code and the data it manipulates,and keeps both safe from outside interference and misuse.in java encapsulation is achieved by making use of access modifiers( keeping variables as private and providing public getters and setters.

Eg:-
automatic transmission of an automobile.
It encapsulates lots of information about the engine, such acceleration, the pitch of the surface , and the position of the shift
lever. Being a user,we have only one method of affecting this complex encapsulation: moving the gear-shift lever.

Inheritance:
Inheritance is the process by which one object acquires the properties of another object.

Eg:-Vehicle->motorized->4wheeled.

Polymorphism:
Polymorphism (from the Greek, meaning “many forms”) is a feature that allows one interface to be used for a general class of actions.

Eg. Car's steering ->one interface many implementations(power or rack and pinion)

Abstraction:
Means hiding the internal details and just exposing the functionality.

Eg:-When we change the gear of a car, we know the gears will be changed without knowing how they are functioning internally.
Abstraction focuses on the outside view of an object (i.e. the interface).Kindle Wireless Reading Device, Free 3G, 6" Display, White - 2nd Generation

Followers

Is this helps u

Subscribe to RSS Feed