This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why do we use Constructors in Java ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Why do we use Constructors in Java ?" Watch "Why do we use Constructors in Java ?" New topic
Author

Why do we use Constructors in Java ?

Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
Why do we use Constructors in Java ? What is the purpose of it?


Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24054
    
  13

To construct objects? Their purpose seems pretty self-evident: when you create an object, there's obviously a need to initialize the data in that object to a particular known good state. That's what constructors are for.


[Jess in Action][AskingGoodQuestions]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

To ensure everything the object needs is initialized at construction time.

[Damn your quick typing Ernest!]


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Why do we use Constructors in Java ?
 
Similar Threads
Constructers
constructors for Enum types....
Diff btwn beans and ordinary object
constructors in jpa Entity Class
what is need of private constructors in java