How many ways we can create an object in java

There are four different ways to create objects in java:
1. Using new keyword:
This is the most common way to create an object in java. Almost 99% of objects are created in this way.
 Customer  customer = new  Customer();
2 Using Class.forName() :
If we know the name of the class & if it has a public default constructor we can create an object in this way.
Customer  customer = (Customer) Class.forName("com.srinu.Customer").newInstance();
3. Using clone() :
The clone() can be used to create a copy of an existing object.
Customer    customer = new Customer();
Customer    object = (Customer customer .clone();
4. Using object deserialization :
Object deserialization is nothing but creating an object from its serialized form.
ObjectInputStream inStream = new ObjectInputStream(anInputStream );

Customer    customer = (Customer) inStream.readObject();
Share:

No comments:

Post a Comment

Ordered List

Popular Posts

The Magazine

Facebook

Post Top Ad

LightBlog

Post Top Ad

Your Ad Spot

About Me

authorHello, my name is Jack Sparrow. I'm a 50 year old self-employed Pirate from the Caribbean.
Learn More →

Comment

Post Top Ad

Your Ad Spot

Hot

AD BANNER

Sponsor

AD BANNER

Recent Comments

Extra Ads

AD BANNER

Contact Form

Name

Email *

Message *

Translate

Sponsor

test

Home Top Ad

Responsive Ads Here

Flickr

Ad Banner
Responsive Ads Here

About Us

authorHello, my name is Jack Sparrow. I'm a 50 year old self-employed Pirate from the Caribbean.
Learn More →

Recent Posts

Unordered List

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
  • Vestibulum auctor dapibus neque.

Sample Text

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation test link ullamco laboris nisi ut aliquip ex ea commodo consequat.

Pages

Theme Support

Need our help to upload or customize this blogger template? Contact me with details about the theme customization you need.